我使用以下内容阅读并格式化功能集:
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);
我的要素集中有点和多边形。 如何仅为多边形添加叠加控件?我尝试使用过滤器,但没有任何效果。感谢您阅读代码!
粗鲁,眨眼
谢谢你, 我现在了解到,仅使用过滤器功能来缩小地图上显示的功能。对? 这不是我的意图。
我想要一个用于要素集合中每个EACH多边形的控件。我现在尝试:
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}
};
到目前为止,该方法有效,我可以控制每个多边形。但是,如果我停用所有多边形控件,则多边形只会消失。我要停用单个多边形!
粗鲁,眨眼
答案 0 :(得分:0)
我现在找到了该任务的解决方案:
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);
};
};
粗鲁,眨眼