我想从* .geojson文件中获取某些多边形(坐标,popupContent,控件标题,样式)的所有数据。我想要一个单独的控件,每个多边形。弹出窗口和控件可与以下功能配合使用:
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); // nicht für Marker
};
};
如果添加样式功能,则无法使用:
function style (feature) {
if (feature.properties.stroke != null) {
return {color: feature.properties.stroke,
weight: feature.properties.strokeWidth,
opacity: feature.properties.strokeOpacity,
fillOpacity: feature.properties.fillOpacity,
fill: feature.properties.fill,
fillColor: feature.properties.fillColor
}
}
else
return {};
}
仅当我使用简单的功能,例如:
时,样式功能才起作用function onEachFeature(feature, layer) {layer.bindPopup().addTo(map);}
当然,在这种情况下,控件不起作用。我对* .geojson的呼唤:
$.ajax(overlay).done(function(data) {
data = JSON.parse(data);
L.geoJson(data,
{pointToLayer: MarkerStyle,
style: style,
onEachFeature: onEachFeature
});
});
代码中的标记效果很好。 怎么办感谢您检查代码。
粗鲁,眨眼