Leaflet:使用GeoJSON将弹出窗口添加到图层上

时间:2016-11-07 22:15:57

标签: javascript leaflet

我有一个图层,它有一个GeoJSON中的几个circleMarker。

var geojsonMarkerOptions = {
  radius: 8,
  fillColor: "#ff7800",
  color: "#000",
  weight: 1,
  opacity: 1,
  fillOpacity: 0.8
};

L.geoJSON(someGeojsonFeature, {
  pointToLayer: function (feature, latlng) {
      return L.circleMarker(latlng, geojsonMarkerOptions);
  }
}).addTo(map);

如何在每个circleMarker上添加一个弹出窗口,用户可以点击每个圆圈来获取弹出窗口?

1 个答案:

答案 0 :(得分:0)

尝试一下:

var geojsonMarkerOptions = {
  radius: 8,
  fillColor: "#ff7800",
  color: "#000",
  weight: 1,
  opacity: 1,
  fillOpacity: 0.8
};

L.geoJSON(someGeojsonFeature, {
  pointToLayer: function (feature, latlng) {
      var mypopup = L.popup().setContent("latlng: " + latlng);
      var mymarker = L.circleMarker(latlng, geojsonMarkerOptions);

      mymarker.bindPopup(mypopup);
      return mymarker;               
  }
}).addTo(map);