openlayers icon indicating copy to clipboard operation
openlayers copied to clipboard

how to select feature in WebGLVectorTileLayer

Open younggis opened this issue 1 year ago • 9 comments

I created a layer as this:

      class WebGLVectorTileLayer extends VectorTileLayer {
        createRenderer() {
          return new WebGLVectorTileLayerRenderer(this, {
            style: {
              fill: {
                fragment: result.builder.getFillFragmentShader(),
                vertex: result.builder.getFillVertexShader(),
              },
              stroke: {
                fragment: result.builder.getStrokeFragmentShader(),
                vertex: result.builder.getStrokeVertexShader(),
              },
              symbol: {
                fragment: result.builder.getSymbolFragmentShader(),
                vertex: result.builder.getSymbolVertexShader(),
              },
              attributes: {
                fillColor: {
                  size: 2,
                  callback: (feature) => {
                    return packColor([21, 255, 18, 1])
                  },
                },
                strokeColor: {
                  size: 2,
                  callback: (feature) => {
                    return packColor([255, 255, 255, 1])
                  },
                },
                strokeWidth: {
                  size: 1,
                  callback: (feature) => {
                    return 1
                  },
                },
              },
            },
          })
        }
      }
      let layer = new WebGLVectorTileLayer({
        source: new VectorTileSource({
          attributions: [],
          format: new MVT(),
          url: API_URL + 'mapManage/GetRasterMVT?z={z}&x={x}&y={y}',
          minZoom: MIN_ZOOM,
          maxZoom: MAX_ZOOM,
        }),
      })

now, how to select the feature in this layer? please thank you

younggis avatar Oct 22 '23 15:10 younggis

The Vector Tile layer example https://openlayers.org/en/latest/examples/vector-tile-selection.html uses feature id, so a fix for #15251 would be needed before something similar can be attempted in WebGL.

mike-000 avatar Oct 24 '23 14:10 mike-000

It seems this is still not possible. Although #15120 also updated WebGLVectorTileLayerRenderer to enable the VectorStyleRenderer to hit detect by default map.forEachFeatureAtPixel returns no hits and layer.getFeatures is not supported.

mike-000 avatar Oct 28 '23 11:10 mike-000

Hit detection on vector tile layers rendered using WebGL is currently being worked by @gberaudo on and a PR is likely to come in the near future.

jahow avatar Oct 28 '23 12:10 jahow

We look forward to hearing from you soon. @jahow

IdenPin avatar Nov 01 '23 15:11 IdenPin

So, my case is (not vector tiles, but a Vector Source with features)

  1. useGeographic()
  2. WebGL layer with feature source and preloaded features in EPSG:4326
  3. Default Select tool working with WebGL layer..

It seems that internally some "math" is not yet correctly working.

image

The value of "ref" variable has nothing related to real "ref" as keys in batch_ data stucture of WebGL renderer... (looks like it should be 1,2,3... N

Source code is a bit of magic at the moment for me in WebGL renderer, so just inconsistency of calculated "ref" value is obvious, may be it helps.

Codebase is OL 8.2.0

vitalus avatar Nov 26 '23 14:11 vitalus

@vitalus thanks for reporting, this problem has most likely been fixed by https://github.com/openlayers/openlayers/pull/15340; unfortunately, this hasn't made it to 8.2.0. Could you please let us know if the issue persists when using the ol@dev latest package? Thanks!

jahow avatar Nov 26 '23 15:11 jahow

in version 9.0.0-dev.1701358929517 selection is working normally, seems.

vitalus avatar Dec 03 '23 23:12 vitalus

It seems this is still not possible. Although #15120 also updated WebGLVectorTileLayerRenderer to enable the VectorStyleRenderer to hit detect by default map.forEachFeatureAtPixel returns no hits and layer.getFeatures is not supported.

Feature selection remains unavailable for WebGLVectorTileLayerRenderer, correct? It seems that the behavior described above is still the case (ol 9.2.4).

jjnesbitt avatar Jul 10 '24 18:07 jjnesbitt

Hi, by any chance is there any development related to selecting features from WebGLVectorTileLayer?

bcherkezovtf avatar Aug 13 '24 11:08 bcherkezovtf