小编map*_*ode的帖子

react-leaflet <GeoJSON /> pointToLayer选项更改图标

我目前正在尝试学习反应,我想使用传单地图(反应传单)。

我有两个要显示的(点,多边形)GeoJson对象,该对象正在运行,但是我想替换默认的标记图标。

传单文档http://leafletjs.com/examples/geojson/告诉我使用pointToLayer选项。

码:

onEachFeaturePoint,onEachfeaturePolygon,pointToLayer

onEachFeaturePoint(feature, layer) {
  console.log('feature: ', feature);
  console.log('layer: ', layer);
  layer.on({
    'click': function (e) {
       console.log('e: ', e);
       console.log('click');
     }
  })
}

onEachFeaturePolygon(feature, layer) {
  console.log('feature: ', feature);
  console.log('layer: ', layer);
  layer.on({
    'click': function (e) {
       console.log('e: ', e);
       console.log('click');
     }
  })
}

pointToLayer(feature, latlng) {
  console.log('--- Point to layer');
  console.log('feature: ', feature);
  console.log('latlng: ', latlng);
  return <CircleMarker center={latlng} />;
}
Run Code Online (Sandbox Code Playgroud)

渲染

render() {
  const center = [9.4921875, 51.83577752045248];

  return (
    <Map center={center} zoom={1}> …
Run Code Online (Sandbox Code Playgroud)

react-leaflet

2
推荐指数
1
解决办法
1788
查看次数

标签 统计

react-leaflet ×1