Mapboxgl:在一定缩放级别后放大和缩小时始终显示图层图标

问题描述 投票:0回答:1

我正在尝试在放大时禁用消失的 MapboxGl.Layer 图标。是否有任何元数据或属性配置可以一次显示图层所有图标。

例如,在图层实例中给出的

minzoom:7.4
之后,我想显示所有geojson数据。

{
  "id": "Car",
  "type": "symbol",
  "source": {
    "type": "geojson",
    "data": {
      "type": "FeatureCollection",
      "features": [
        {
          "type": "Feature",
          "properties": {
            "icon": "Car"
          },
          "geometry": {
            "type": "Point",
            "coordinates": [
              -117.42187500000001,
              57.51582286553883
            ]
          }
        },
      ...
      ...
      ]
    }
  },
  "layout": {
    "icon-image": "{icon}",
    "icon-size": 0.04,
    "visibility": "visible"
  },
  "minzoom": 7.4,
  "metadata": {
    "imageurl": "dist/images/Mapboxgl/Entities/Car.png",
    "center": [
      -119.09913365922579,
      56.054006240841346
    ],
    "zoom": [
      12
    ]
  }
}

如何在缩放级别 7.4 下一起显示所有数据?

添加示例: 代码沙盒 JSFiddle 单击 addLayer 按钮。

实际结果:仅显示第3层图标。

预期结果:想要显示所有图层图标。

请帮忙。

谢谢。

mapbox mapbox-gl-js
1个回答
0
投票

在 SymbolLayer 中添加图层时,请确保包含以下选项:

layout: { 'icon-allow-overlap': true, }

如果您使用文本作为符号层的一部分,请确保还包括:

layout: { 'icon-allow-overlap': true, "text-allow-overlap": true, }

全层示例:

const layer: mapboxgl.SymbolLayer = {
    id: 'layerID',
    type: 'symbol',
    source: {
        type: 'geojson',
        data: featureCollection,
    },
    layout: {
        "icon-image": "iconName",
        'symbol-sort-key': 1,
        'text-field': ['get', '<field in featureCollection you want to use as name>'],
        'text-font': ['Open Sans Regular'],
        'text-size': 10,
        'text-offset': [0, -1],
        'text-anchor': 'bottom',
        'icon-allow-overlap': true,
        "text-allow-overlap": true,
    },
    paint: {
        'text-color': '#000000',
        'text-halo-color': '#ffffff',
        'text-halo-width': 2,
    }
};

map.addLayer(layer)
© www.soinside.com 2019 - 2024. All rights reserved.