显示存储在GeoJson文件中的样式,并使线显示为线而不是标记



我一直在尝试让Leaflet使用geojson文件中描述的样式显示geojson,但我无法让它工作。下面的geojson显示我有一些样式-OGR样式笔等,但我尝试使用样式函数(styles({return{color:data.properties.pen}}提取它们,但它在控制台上给了我一个错误-但没有足够的错误来匹配层数-所以我可以理解有些层可能没有";笔;属性,但并没有一个层出现任何差异。

"特征":[{"类型":"特征","特性":{"层":"建筑物","子类":"AcDbEntity:AcDb2dPolyline","EntityHandle":"2ABF","OGR_STYLE":"PEN(c:#ff7f00,p:"1.2g 0.72g 0.12g 0.72g";("},";"几何形状":{"类型":"字符串","坐标":[[-1.38627479218328654.90745299802685,0.0],[--1.386201193400163,

事实上,正如上面的geojson所示,它实际上是一个几何体,但显示的只是一个标记,这是我的第二个问题。有人能给我指一些示例代码或任何对我有帮助的东西吗?

$.getJSON(address, function(data) {
//add GeoJSON layer to the map once the file is loaded
layer[i] = L.geoJson(data, {style: function(styles) {
return {color: data.properties.pen,
weight: data.properites.weight
};
onEachFeature: onEachFeature
}
}).addTo(map);

谢谢。

将代码更改为:

function onEachFeature(feature, layer) {
if (feature.properties && layer instanceof L.Path) {
layer.setStyle({
color: feature.properties.pen,
weight: feature.properites.weight
});
}
}

$.getJSON(address, function(data) {
//add GeoJSON layer to the map once the file is loaded
layer[i] = L.geoJson(data, {
onEachFeature: onEachFeature
}).addTo(map);
});

传单GeoJson教程

最新更新