openlayers打开加载矢量瓦片后选中feature,只能选中一部分,不能全部选中
代码如下,黑色部分是选中后的效果,理论上每个区域使用黄色的边线分开的,应该选中feature的整个区域才对,现在貌似只选中了一个feature的某一个瓦片的一部分,没有全部选中,求大神指点这是为啥
addTileVector() {
const map = window.OLMap
const url = 'https://diffmap.zggyd.com/iserver/services/map-mvt-gydst/restjsr/v1/vectortile/maps/gyd_st/style.json'
const mapserver = new ol.supermap.MapService(url).getMapInfo(function(serviceResult) {
console.log('serviceResult', serviceResult)
const format = new ol.format.MVT({
featureClass: ol.Feature
})
console.log('olStyles', olStyles)
var styles = olStyles[GeometryType.GEOMETRY_COLLECTION]
// style.on('styleloaded', function() {
const vectorLayer = new ol.layer.VectorTile({
declutter: false,
source: new ol.source.VectorTileSuperMapRest({
style: url,
// style: url,
projection: 'EPSG:4326',
format: format
}),
style: styles,
maxZoom: 22
// zIndex: 2
})
map.addLayer(vectorLayer)
console.log('vectorLayer', vectorLayer)
const hightStyle = new ol.style.Style({
// 填充色
fill: new ol.style.Fill({
color: '[255,138,9, 1]'
}),
// 边线颜色
stroke: new ol.style.Stroke({
color: '#FF0000',
width: 1
}),
// 形状
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
// 高亮风格的图层:
const featureOverlay = new ol.layer.Vector({
source: new ol.source.Vector(),
style: hightStyle,
zIndex: 10
})
// 设置图层名称用于点击查询显示
featureOverlay.layerId = 'highlightLayer'
map.addLayer(featureOverlay)
// 设置高亮要素变量
let highlightFeature = null
window.OLMap.on('click', function(e) {
console.log('click event', e)
// const feature = vectorLayer.getFeatures(e.pixel)[0]
const features = map.forEachFeatureAtPixel(e.pixel, (feature, layer) => {
return {
feature: feature,
layer: layer
}
})
if (features.feature !== highlightFeature) {
if (highlightFeature) {
featureOverlay.getSource().removeFeature(highlightFeature)
}
if (features.feature) {
featureOverlay.getSource().addFeature(features.feature)
}
highlightFeature = features.feature
}
})
})
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1、被覆盖了
2、feature的整个区域就是你看到的这样
这都和图层服务有关,你可以在选中的时候,打印下feature,看feature的数据是不是就这样的