![](/img/trans.png)
[英]Geoserver WFS layer as Timestamp fields converted to string on OpenLayers Vector layer
[英]Openlayers Style doesn't work on certain Geoserver WFS layer (block-shape)
我想使用 OpenLayer 更改 geoserver WFS 图层的样式。 问题是,有一个图层可以改变样式,但还有其他图层不能改变。
使用此代码
style: new ol.style.Style({
image: new ol.style.Circle({
stroke: new ol.style.Stroke({
color: 'rgba(255, 0, 0, 1.0)',
width: 5
}),
radius: 5
})
})
我可以将这一层(SRID:4326)更改为这样
但是该样式不能应用于具有 SRID: 32663 的其他图层。无论我尝试哪种样式(描边、填充、颜色、图像),它总是会显示为这样(块状)
我从 PostgreSQL 数据库中导入了这些层。 查看几何投影,成功更改的图层具有像这样的点形状
SELECT ST_AsEWKT(geometry) FROM "table1" LIMIT 1;
result : SRID=4326;POINT(126.8865913 37.2598192)
geom sample : "0101000020E6100000C39A6FE9BDB85F40BB6F6BC141A14240"
同时改变不成功的层有这样的块状
SELECT ST_AsEWKT(geometry) FROM "table2" LIMIT 1;
result : SRID=32663;MULTIPOLYGON(((14240035.8111278 4485667.02788355,14239940.2255882 4485585.20329766,.........
geom sample : "0106000020977F00000100000001030000000100000005000000CDA1878968066B41EE70C72749445141284876F45D066B418F4696B13144514100B1FC4552066B41989893F24644514160E00CDB5C066B415B95DD685E445141CDA1878968066B41EE70C72749445141"
如果您想将小多边形/多多边形设置为图像,您可以在样式中使用几何 function 来返回它们的内部点
style: new ol.style.Style({
geometry: function(feature) {
var geom = feature.getGeometry();
if (geom.getType() = 'Polygon') {
return geom.getInteriorPoint();
}
if (geom.getType() = 'MultiPolygon') {
return geom.getInteriorPoints();
}
return geom;
},
image: new ol.style.Circle({
stroke: new ol.style.Stroke({
color: 'rgba(255, 0, 0, 1.0)',
width: 5
}),
radius: 5
})
})
问题是第一层特征几何类型是点,因此上面的样式代码将起作用。
但是,其他图层几何类型是多边形/多多边形,因此根据https://embed.plnkr.co/plunk/GvdVNE ,不同的类型将需要不同的代码。 下面的代码适用于多边形样式。
var polyStyle = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgb(0,255,255)',
width: 3
}),
fill: new ol.style.Fill({
color: 'rgba(0, 255, 255, 0.5)'
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.