zeakd / react-naver-maps

React Navermaps API integration for modern development.
https://zeakd.github.io/react-naver-maps/
118 stars 23 forks source link

화면이동 관련 질문입니다. #29

Closed hwimin-kim closed 4 years ago

hwimin-kim commented 4 years ago

`handleMouseClick = () => { this.setState({ MapData: SIG.features, zoom: this.state.zoom + 2 }); };

// 지도 이동 멈추면 실행 handelDblclick = index => { this.setState({ zoom: this.state.zoom + 1, center: this.state.centerdata[index], MapData: SIG.features }); this.XYdata2(); };

changeBounds = bounds => { this.setState({ bounds }); };

// render되고 실행 // 경계좌표 및 render 상태 componentDidMount() { this.changeBounds(this.mapRef.getBounds()); this.setState({ mapstate: 1 }); this.XYdata2(); }

XYdata2 = () => { const t = this.state.MapData.map(item => { return item.geometry.coordinates.map((item2, index, array) => { const a = this.centroid(item2); const b = { lat: a[1], lng: a[0] }; return b; }); });

this.setState({ centerdata: t.flat() });
return t;

}; // centroid = item2 => {

centroid알고리즘 생략 };

// 최적화

render() { const XYdata = this.state.centerdata.map((item, index, array) => { return ( <Marker position={item} key={index} animation={2} onDblclick={this.handelDblclick.bind(this, index)} title={"A"} /> ); });

return (
  <div>
    <NaverMap
      naverRef={ref => {
        this.mapRef = ref;
      }}
      id="maps-examples-polygon"
      style={{
        width: "80%",
        height: "500px"
      }}
      disableDoubleClickZoom={this.state.disableDoubleClickZoom}
      disableDoubleTapZoom={this.state.disableDoubleTapZoom}
      scrollWheel={this.state.scrollWheel}
      zoom={this.state.zoom}
      center={this.state.center}
    >
      {XYdata}
    </NaverMap>
  </div>
);

} }`

hwimin-kim commented 4 years ago

해결하였습니다. onDblclick={this.handelDblclick(b)} ----> onDblclick={() => this.handelDblclick(b)} 로 고치니 작동하내요 그런데 왜 이렇게 되는지 잘모르겠내요

zeakd commented 4 years ago

@hwimin-kim 안녕하세요. 리액트 튜토리얼을 한번 살펴보시면 좋을 것같습니다. html과 API차이가 조금 있습니다.

이벤트 처리하기

라이브러리와 관련된 이슈가 아니어서 클로즈 하겠습니다 :)