Closed hwimin-kim closed 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> );
} }`
렌더링 하는중에 setState(handleDblclick)을 해서 충돌이 일어나는거 같은데 해결방법을 모르겠습니다.
깃헙을 써본지 얼마안되서 잘못올린 이슈 지우려고 하니깐 안 지워지네요
해결하였습니다. onDblclick={this.handelDblclick(b)} ----> onDblclick={() => this.handelDblclick(b)} 로 고치니 작동하내요 그런데 왜 이렇게 되는지 잘모르겠내요
onDblclick={this.handelDblclick(b)} ----> onDblclick={() => this.handelDblclick(b)}
@hwimin-kim 안녕하세요. 리액트 튜토리얼을 한번 살펴보시면 좋을 것같습니다. html과 API차이가 조금 있습니다.
이벤트 처리하기
라이브러리와 관련된 이슈가 아니어서 클로즈 하겠습니다 :)
`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; }); });
}; // 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"} /> ); });
} }`
렌더링 하는중에 setState(handleDblclick)을 해서 충돌이 일어나는거 같은데 해결방법을 모르겠습니다.
깃헙을 써본지 얼마안되서 잘못올린 이슈 지우려고 하니깐 안 지워지네요