openlayers打开加载矢量瓦片后选中feature,只能选中一部分,不能全部选中

发布于 2022-09-13 00:22:05 字数 2744 浏览 18 评论 0

代码如下,黑色部分是选中后的效果,理论上每个区域使用黄色的边线分开的,应该选中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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的心境我的脸 2022-09-20 00:22:05

1、被覆盖了
2、feature的整个区域就是你看到的这样

这都和图层服务有关,你可以在选中的时候,打印下feature,看feature的数据是不是就这样的

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文