我阅读并格式化我的要素集合:
function onEachFeature(feature, layer) {
if (feature.properties.popupContent == null)
{return null}
else
{return layer.bindPopup(feature.properties.popupContent)};
};
function MarkerStyle (feature,latlng) {
if (feature.properties.markerSymbol == null)
{return L.marker(latlng);}
else
{return L.marker(latlng, {icon: L.icon({iconUrl:
feature.properties.markerSymbol})});}
};
var daten = $.ajax(overlay).done(function(data) {
data = JSON.parse(data);
daten = L.geoJson(data,
{pointToLayer: MarkerStyle,
onEachFeature: onEachFeature}).addTo(map);
return daten});
L.control.layers(baseLayers, overlayMaps).addTo(map);
有我的特征收集点和多边形。我如何添加一个覆盖控制只为多边形?我试图与过滤器,但没有奏效。感谢您阅读的代码!
格鲁斯,书呆子
谢谢你,我现在明白了,该过滤功能仅用于,减少功能,这些功能显示在地图上。对?这不是我的本意。
我想为特征集合中的每个多边形控制。我现在尝试:
var polygons = L.geoJSON();
var overlayLayers = null;
var controls = L.control.layers(baseLayers,overlayLayers).addTo(map);
function onEachFeature(feature, layer) {
if(feature.properties.control != null)
{polygons.addData(feature)
.bindPopup(feature.properties.popupContent);
polygons.addTo(map);
polygon = polygons;
controls.addOverlay(polygon,feature.properties.control);
polygon = null;
};
if (feature.properties.popupContent == null)
{return null}
};
到目前为止是这种情况,我得到每个多边形控制。但是多边形才会消失,如果我取消所有多边形控制。我想停用单一多边形!
格鲁斯,书呆子
现在我已经找到了该任务的解决方案:
var overlayLayers = null;
var controls = L.control.layers(baseLayers, overlayLayers).addTo(map);
function onEachFeature(feature, layer) {
var ObjektLayer = L.geoJSON();
ObjektLayer.addData(feature);
if (feature.geometry.type == "Polygon" )
{if (feature.properties.control != null)
{controls.addOverlay(ObjektLayer,feature.properties.control);
};
if (feature.properties.popupContent != null)
{ObjektLayer.bindPopup(feature.properties.popupContent);
};
ObjektLayer.addTo(map);
};
};
格鲁斯,书呆子