在MapBox中挤出土地

时间:2019-12-16 10:02:36

标签: mapbox

我要强调的事实是,土地比我的地图中的水高,因此想在土地层上添加挤出物。我认为将https://docs.mapbox.com/mapbox-gl-js/example/3d-buildings/与建筑物一起使用,并将图层源更改为“土地”会起作用,但是没有用。这是特定于构建图层的东西吗,还是我做错了什么?这是我的样式JSON中的图层定义:

    {
        "id": "3d-land",
        "source": "composite",
        "source-layer": "land", # Changed this from building
        "filter": ["==", "extrude", "true"],
        "type": "fill-extrusion",
        "minzoom": 0,
        "paint": {
            "fill-extrusion-color": "#000",
            "fill-extrusion-height":  [
                "interpolate", ["linear"], ["zoom"],
                15, 0,
                18.0, 30.0
            ],
            "fill-extrusion-base": [
                "interpolate", ["linear"], ["zoom"],
                15, 0,
                18.0, ["get", "min_height"]
            ],
            "fill-extrusion-opacity": 0.8
        }
    }

1 个答案:

答案 0 :(得分:1)

第一个原因是控制台说的"land" does not exist on source "composite""land"层是background层,在样式中单独存在。您不能将fill-extrusion用于background层。您可能要使用使用"compose"源的图层。

另一个原因是来自filter"filter": ["==", "extrude", "true"]表示过滤名为"extrude"的图层属性的值为"true"land图层没有属性extrude,因此始终为false

因此,修复的结果如下:

map.addLayer(
  {
    id: "3d-landcover",
    source: "composite",
    "source-layer": "landcover",
    "type": "fill-extrusion",
    "minzoom": 0,
    "paint": {
      "fill-extrusion-color": "#000",
      "fill-extrusion-height":  [
        "interpolate", ["linear"], ["zoom"],
        15, 0,
        18.0, 30.0
      ],
      "fill-extrusion-base": [
        "interpolate", ["linear"], ["zoom"],
        15, 0,
        18.0, ["get", "min_height"]
      ],
      "fill-extrusion-opacity": 0.8
    }
  }
);

首先,如果要使土地高于水,则应按上述方法添加除水以外的所有图层。这不是很有效。