Leaflet 如何在单个GeoJSON FeatureCollection的传单中设置多个要素类型的样式

Leaflet 如何在单个GeoJSON FeatureCollection的传单中设置多个要素类型的样式,leaflet,geojson,Leaflet,Geojson,我在单个FeatureCollection中具有点、多多边形和线串特征。我想使用circleMarker()设置点的样式,其他的则正常。我向idToFeature对象添加点,以便使用JavaScript进行操作,但无法添加非点特性 使用传单1.3.3,如果我使用pointToLayer:,点的样式会很好,其他类型的点会使用默认的蓝色进行渲染(不知道为什么,因为它们不是点)。我尝试过使用onEachFeature:取而代之,并且可以用这种方式设置非点的样式,但不知道如何为点生成圆形标记 我拥有的

我在单个FeatureCollection中具有点、多多边形和线串特征。我想使用circleMarker()设置点的样式,其他的则正常。我向idToFeature对象添加点,以便使用JavaScript进行操作,但无法添加非点特性

使用传单1.3.3,如果我使用pointToLayer:,点的样式会很好,其他类型的点会使用默认的蓝色进行渲染(不知道为什么,因为它们不是点)。我尝试过使用onEachFeature:取而代之,并且可以用这种方式设置非点的样式,但不知道如何为点生成圆形标记

我拥有的 (无法设置多重多边形的样式,或将其添加到我的idToFeature对象以进行JS操作)

我试过的(反正是一次)


我不希望将GeoJSON分解为单独的特定类型的FeatureCollections,我确信我不应该这样做……但是如何做呢?

我拼凑了一个解决方案。它看起来并不理想,但很有效:一个接一个地使用
pointToLayer
onEachFeature

    features = L.geoJSON(data, {
      pointToLayer: function (feature, latlng) {
        count_features +=1;
        identifier = feature.properties.whgid;
        if(feature.type=='Point'){
          marker = L.circleMarker(latlng, styles.marker_default
          ).bindPopup(feature.properties.title+' (whg id:'+identifier+')');
          // add to array for selection
          idToFeature[identifier] = marker
          return marker
        }
      },
      onEachFeature: function(feature,layer) {
        identifier = feature.properties.whgid;
        if(feature.type != 'Point'){
          layer.setStyle(styles.default)
          idToFeature[identifier] = layer
        }
      }
    }).addTo(map);

如果您在
onEachFeature
函数中检查
feature
,您能确定“type”是否包含您期望的内容吗?您可以在最后一节中看到,我确实检查了
功能的类型,如果是点,则渲染圆标记。问题是如何使用其他类型渲染功能
onEachFeature
docs说它被称为“每个创建的特征在创建和设置样式后调用一次”。那么我该如何在这一点上创建和设置多多边形和线字符串特征的样式呢?我会继续尝试,但我想有人可能知道一个现成的方法。
features = L.geoJSON(data, {
  style: function (feature) {
    if(feature.type=="Point"){
      return {color: "#009900"};
    } else {
      return {color: "#000099"};
    }
  }
  onEachFeature: function(feature, layer) {
    if(feature.type == 'Point'){
      console.log('point', feature)
      marker = L.circleMarker(latlng, styles.place_default)
      return marker
    }
  }
}).addTo(map);
    features = L.geoJSON(data, {
      pointToLayer: function (feature, latlng) {
        count_features +=1;
        identifier = feature.properties.whgid;
        if(feature.type=='Point'){
          marker = L.circleMarker(latlng, styles.marker_default
          ).bindPopup(feature.properties.title+' (whg id:'+identifier+')');
          // add to array for selection
          idToFeature[identifier] = marker
          return marker
        }
      },
      onEachFeature: function(feature,layer) {
        identifier = feature.properties.whgid;
        if(feature.type != 'Point'){
          layer.setStyle(styles.default)
          idToFeature[identifier] = layer
        }
      }
    }).addTo(map);