简体   繁体   English

mapbox-gl-js:矢量切片 - 在客户端更改/添加功能属性的最有效方法?

[英]mapbox-gl-js: Vector tiles - most efficient way to Change/Add feature property at client-side?

A mapbox-vector-tile layer is being served from GeoServer (around 500K features points and multiline strings). GeoServer 提供了一个 mapbox-vector-tile 层(大约 50 万个特征点和多行字符串)。

I am using mapbox-gl-js to plot the layer at client side and I use expressions to change certain styles(eg line color)我正在使用 mapbox-gl-js 在客户端绘制图层,并使用表达式来更改某些样式(例如线条颜色)

I have an external API which will provide me a list of properties for each asset我有一个外部 API,它将为我提供每个资产的属性列表

[{ id: 123, prop1: 45, prop2: 78 }, ...] [{ id: 123, prop1: 45, prop2: 78 }, ...]

Now, I want to assign these properties to the corresponding features, so that I will be able to write expressions based on 'prop1' to manipulate the style.现在,我想将这些属性分配给相应的功能,以便我能够根据“prop1”编写表达式来操纵样式。

Expression:表达:

 [ 'let', 'load_value', ['to-number', ['get', 'prop1']],
      [
        'case',
        [ 'all', ['>=', ['var', 'load_value'], 0], ['<', ['var', 'load_value'], 50] ], 'gray',
        [ 'all', ['>=', ['var', 'load_value'], 50], ['<', ['var', 'load_value'], 70] ], 'yellow',
        ['>=', ['var', 'load_value'], 70], 'red',
        'gray'
      ]
 ];

I have tried using setFeatureState method and it worked.我尝试过使用 setFeatureState 方法并且它有效。 Problem, the map is terribly slow after doing this.问题,执行此操作后地图非常慢。 I believe this is because I need to set the feature state for 500K features.我相信这是因为我需要为 500K 功能设置功能状态。

Setting feature state:设置功能状态:

   data.forEach((datum) => {
      this.map.setFeatureState({
        source: 'geoserver-source',
        sourceLayer: 'mvt-layer',
        id: datum.id
      }, {
        prop1: datum.prop1
      });
    });

The color changes as per the given conditions.颜色根据给定的条件变化。 But the map itself becomes very slow after this.但是在此之后地图本身变得非常缓慢。 Is there any better way of mapping these properties from the client side?有没有更好的方法从客户端映射这些属性?

Apparently there is no other way (as of now) using mapbox-gl-js显然没有其他方法(截至目前)使用 mapbox-gl-js

https://github.com/mapbox/mapbox-gl-js/issues/8753#issuecomment-531284256 https://github.com/mapbox/mapbox-gl-js/issues/8753#issuecomment-531284256

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM