Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何使用react传单容器点标签?_Reactjs_Leaflet_React Leaflet - Fatal编程技术网

Reactjs 如何使用react传单容器点标签?

Reactjs 如何使用react传单容器点标签?,reactjs,leaflet,react-leaflet,Reactjs,Leaflet,React Leaflet,我试图改变一个动态变化的标记的位置,我从json中获取的坐标是像素到度数。但我犯了以下错误: 容器点标签未定义无未定义的反应传单 我试图通过导入containerPointToLatLng import {L,containerPointToLatLng } from 'leaflet'; 但它不起作用,有什么想法吗?containerPointToLatLng是一种方法,下面的示例演示了在给定像素坐标的情况下如何放置标记 class MapExample extends React.Comp

我试图改变一个动态变化的标记的位置,我从json中获取的坐标是像素到度数。但我犯了以下错误:

容器点标签未定义无未定义的反应传单

我试图通过导入
containerPointToLatLng

import {L,containerPointToLatLng } from 'leaflet';

但它不起作用,有什么想法吗?

containerPointToLatLng是一种方法,下面的示例演示了在给定像素坐标的情况下如何放置标记

class MapExample extends React.Component {
  constructor(props) {
    super();
    this.state = {
      lat: 51.505,
      lng: -0.09,
      zoom: 8,
      markerPoint: {
        x: 733,
        y: 62
      }
    };
    this.refMap = React.createRef();

    this.setMarkerPos = marker => {
      const map = this.refMap.current.leafletElement;
      const m = marker.leafletElement;
      const markerLatLng = map.containerPointToLatLng(this.state.markerPoint);
      m.setLatLng(markerLatLng);
    };
  }


  render() {
    const { lat, lng, zoom } = this.state;
    const position = [lat, lng];
    return (
      <Map  ref={this.refMap}
        center={position} zoom={zoom}
      >
        <TileLayer 
          url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
          attribution="&copy; <a href=&quot;http://osm.org/copyright&quot;>OpenStreetMap</a> contributors"
        />
        <Marker position={{lat:0,lng:0}} ref={this.setMarkerPos.bind(this)} />
      </Map>
    );
  }
}
类映射示例扩展了React.Component{
建造师(道具){
超级();
此.state={
拉脱维亚:51.505,
液化天然气:-0.09,
缩放:8,
标记点:{
x:733,
y:62
}
};
this.refMap=React.createRef();
this.setMarkerPos=marker=>{
const map=this.refMap.current.element;
常数m=标记元素;
const-markerLatLng=map.containerPointToLatLng(this.state.markerPoint);
m、 setLatLng(markerLatLng);
};
}
render(){
const{lat,lng,zoom}=this.state;
常数位置=[lat,lng];
返回(
);
}
}


供您参考

嗨,瓦迪姆,我尝试过这样做。但我真的不知道如何将containerPointToLatLng添加到我的地图箭头函数中。因为我将经度和纬度作为像素,但是当我尝试定位标记时,这些标记没有定位到正确的点。我尝试了这个方法,const-moplemarkers1=this.state.products.map(marker=>(//containerpointtolatng[marker.lation/3.83,marker.longitude/3.45]//marker.latitude/4.95,marker.longitude/5.15]//lat={marker.latlng[0]}//lng={marker.latlng[1]}但我无法为我的标记选择正确的纬度。