[英]Openlayers 3.19.0 seems to require stroke style for proper rendering of multipolygons
When creating the ol.style.Style parameter of a ol.layer.Vector, is the stroke required for proper rendering of the MultiPolygon? 创建ol.layer.Vector的ol.style.Style参数时,是否需要正确绘制MultiPolygon的笔触?
This is a modified version of the example code taken from here . 这是从此处获取的示例代码的修改版本。 When the
stroke
parameter is commented out, the polygon renders as a 3 sided polygon. 注释掉
stroke
参数后,该多边形将渲染为3边多边形。 When uncommenting the stroke
parameter, the polygon renders correctly as a 4 sided polygon. 取消注释
stroke
参数时,多边形将正确渲染为4边多边形。 This is a jsfiddle example. 这是一个jsfiddle示例。 The code below assumes there is an html
<div>
element with the id "map". 下面的代码假定存在一个id为“ map”的html
<div>
元素。
var styleFunction = (function() {
var styles = {};
styles['MultiPolygon'] = new ol.style.Style({
/*stroke: new ol.style.Stroke({
color: 'rgba(255, 255, 0, 1)',
width: 1
}),*/
fill: new ol.style.Fill({
color: 'rgba(255, 255, 0, 0.3)'
})
});
return function(feature) {
return styles[feature.getGeometry().getType()] || styles['default'];
};
})();
var geojsonObject = {
'type': 'FeatureCollection',
'crs': {
'type': 'name',
'properties': {
'name': 'EPSG:3857'
}
},
'features': [{
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [[[[841605, 6482619], [841599, 6482618], [841598, 6482623], [841600, 6482624]]]]
}
}]
};
var source = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)
});
var layer = new ol.layer.Vector({
source: source,
style: styleFunction
});
var map = new ol.Map({
layers: [layer],
target: 'map',
view: new ol.View({
center: [841599.9364198849, 6482619.123901887],
zoom: 21
})
});
This is not a bug. 这不是错误。 The coordinates in the code snippet above are invalid.
上面的代码段中的坐标无效。 According to the GeoJSON specification ,
"The first and last positions are equivalent, and they MUST contain identical values;"
根据GeoJSON规范 ,
"The first and last positions are equivalent, and they MUST contain identical values;"
. 。 For the above snippet, the correct coordinates array would be
对于上述代码段,正确的坐标数组应为
'coordinates': [[[[841605, 6482619], [841599, 6482618], [841598, 6482623], [841600, 6482624], [841605, 6482619]]]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.