[英]openLayers styling points and line of GeoJSON file
I have a GeoJson file and I want to have different labeled circle points in my map.我有一个 GeoJson 文件,我想在我的地图中有不同的标记圆点。 i want to do this to all point (Feature:'point'), but it sadly apply to my Line's Coordinates too (Feature:'LineString'), how can i solve this problem?
我想对所有点都这样做(特征:'点'),但遗憾的是它也适用于我的线的坐标(特征:'LineString'),我该如何解决这个问题?
my Code:我的代码:
const labelText = new Style({
text : new Text({
font: '12px Calibri,sans-serif',
overflow: true,
fill: new Fill({
color: 'green'
}),
stroke : new Stroke({
color :' #000',
width : 3
})
})
});
labelText.getText().setText("R");
const RecStyle = [
new Style({
fill : new Fill({
color:"green"
}),
stroke : new Stroke({
color : 'blue',
width : 2
})
}),
labelText
];
//for drawing
CreateGeojson("myjson.json")
function CreateGeojson(url){
console.log(`url : ${url}`);
const myGeoJson = new VectorLayer({
source: new VectorSource({
format: new GeoJSON(),
url: url
}),
style : RecStyle
});
map.addLayer(myGeoJson);
}
I expected to not see the line's Coordinates as labeled 'R', I want to see only my points in this style我希望看不到标记为“R”的线的坐标,我只想看到这种样式的我的点
Create a styles object indexed by geometry type similar to the editing styles in https://openlayers.org/en/latest/apidoc/module-ol_style_Style-Style.html创建一个按几何类型索引的样式对象,类似于https://openlayers.org/en/latest/apidoc/module-ol_style_Style-Style.html中的编辑样式
Then use a style function to select the appropriate style and any dynamic properties such a labels:然后使用样式函数来选择适当的样式和任何动态属性,例如标签:
style: function(feature) {
const style = styles[feature.getGeometry().getType()];
const textStyle = style.getText();
if (textStyle)
textStyle.setText(feature.get('name'));
}
return style;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.