简体   繁体   English

Leaflet 层与点和多边形

[英]Leaflet layer with Points and Polygons

I have this code to add a geoJSON layer to a map.我有这段代码可以将 geoJSON 层添加到 map。 The data contains both Points and Polygons, and I want both types to update their colors.数据包含点和多边形,我希望这两种类型都更新它们的 colors。

var AgentLayer = L.geoJSON().addTo(Lmap)

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

this.render = function (data) {
    AgentLayer.remove()
    console.log(data)
    AgentLayer = L.geoJSON(data, {
        // style: function (feature) {
        //   return {color: feature.properties.color};
        // }
      pointToLayer: function (feature, latlang) {
        return L.circleMarker(latlang, {radius:feature.properties.radius, color: feature.properties.color});
      }
    }).addTo(Lmap)
  }

All the features are drawn, but the Polygons take the default blue color, which is not the one they actually have assigned.所有的特征都被绘制出来了,但是多边形采用默认的蓝色,这不是他们实际分配的颜色。 The Points update properly.积分正确更新。 The three commented lines with style update the color of the Polygons (and not the Points) only if I don't have the three pointToLayer lines.仅当我没有三条pointToLayer线时,三条带style的注释线才会更新多边形(而不是点)的颜色。

Is it possible handle both color updates in the same layer (because the data is coming mixed with Points and Polygons)?是否可以在同一层处理两种颜色更新(因为数据与点和多边形混合)?

I tried creating two different layers and trying to separate the data processed by each by using instanceof , but I didn't succeed even making the map show up in the browser...我尝试创建两个不同的层并尝试使用instanceof分离每个层处理的数据,但我什至没有成功让 map 出现在浏览器中......

I suspect there is just a typo:我怀疑只是一个错字:

AgentLayer = L.geoJSON(data, {
      style: function (feature) {
           return {color: feature.properties.color};
      }, // probably misses the comma to separate the object properties
      pointToLayer: function (feature, latlang) {
        return L.circleMarker(latlang, {
          radius:feature.properties.radius,
          color: feature.properties.color
        });
      }
    }).addTo(Lmap)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM