React Naver Maps
136

예제/공식 예제/도형

사각형, 원, 타원 그리기

공식 예제 대응네이버 공식 예제 보기 ↗

좌표로 사각형, 원, 타원을 지도에 그립니다.

코드 접기코드 보기
import {
  NavermapsProvider,
  Container as MapDiv,
  NaverMap,
  Rectangle,
  Circle,
  Ellipse,
} from 'react-naver-maps';

const GREEN_FACTORY = { lat: 37.3595953, lng: 127.1053971 };

function ShapeSimpleMapContent() {
  return (
    <NaverMap defaultCenter={GREEN_FACTORY} defaultZoom={8}>
      <Rectangle
        bounds={{
          south: 37.1793196,
          west: 125.8795594,
          north: 37.5398662,
          east: 126.3312422,
        }}
      />
      <Circle
        center={GREEN_FACTORY}
        radius={20000}
        fillColor="crimson"
        fillOpacity={0.8}
      />
      <Ellipse
        bounds={{
          south: 37.1793196,
          west: 127.6795594,
          north: 37.5398662,
          east: 128.4312422,
        }}
        strokeColor="yellowgreen"
        strokeOpacity={1}
        strokeWeight={3}
        fillColor="yellowgreen"
        fillOpacity={0.3}
      />
    </NaverMap>
  );
}

export default function ShapeSimpleExample() {
  return (
    <NavermapsProvider ncpKeyId="aluya4ff04">
      <MapDiv style={{ width: '100%', height: '400px' }}>
        <ShapeSimpleMapContent />
      </MapDiv>
    </NavermapsProvider>
  );
}

React로 옮기며 바꾼 점

네이버 공식 예제이 예제
new naver.maps.Rectangle·Circle·Ellipse에 map을 넘겨 지도에 올리기NaverMap의 자식 <Rectangle>·<Circle>·<Ellipse>
new naver.maps.LatLngBounds(LatLng, LatLng)로 영역bounds에 { south, west, north, east } 리터럴
new naver.maps.LatLng 좌표{ lat, lng } 리터럴