首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Mapbox绘制多边形默认颜色

Mapbox绘制多边形默认颜色
EN

Stack Overflow用户
提问于 2022-07-19 18:16:53
回答 1查看 130关注 0票数 -1

有人知道如何在Mapbox.https://docs.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/上使用此示例更改绘制多边形的默认颜色吗?

浅蓝色在我的地图上不太显眼。

谢谢,

EN

回答 1

Stack Overflow用户

发布于 2022-08-15 19:27:30

您可以查看更改样式的文档:https://github.com/mapbox/mapbox-gl-draw/blob/main/docs/API.md#styling-draw和示例:https://github.com/mapbox/mapbox-gl-draw/blob/main/docs/EXAMPLES.md

可以将样式选项与绘图控件的其他选项一起添加。使用您链接的示例中的设置以及线条和多边形的示例样式:

代码语言:javascript
运行
复制
    const draw = new MapboxDraw({
    displayControlsDefault: false,
    // Select which mapbox-gl-draw control buttons to add to the map.
    controls: {
        polygon: true,
        trash: true
    },
    // Set mapbox-gl-draw to draw by default.
    // The user does not have to click the polygon control button first.
    defaultMode: 'draw_polygon',
    styles: [
      // ACTIVE (being drawn)
      // line stroke
      {
          "id": "gl-draw-line",
          "type": "line",
          "filter": ["all", ["==", "$type", "LineString"], ["==", "active", "true"]],
          "layout": {
            "line-cap": "round",
            "line-join": "round"
          },
          "paint": {
            "line-color": "#D20C0C",
            "line-dasharray": [0.2, 2],
            "line-width": 2
          }
      },
      // polygon fill
      {
        "id": "gl-draw-polygon-fill",
        "type": "fill",
        "filter": ["all", ["==", "$type", "Polygon"], ["==", "active", "true"]],
        "paint": {
          "fill-color": "#D20C0C",
          "fill-outline-color": "#D20C0C",
          "fill-opacity": 0.1
        }
      },
      // polygon mid points
      {
      'id': 'gl-draw-polygon-midpoint',
      'type': 'circle',
      'filter': ['all',
        ['==', '$type', 'Point'],
        ['==', 'meta', 'midpoint']],
      'paint': {
        'circle-radius': 3,
        'circle-color': '#fbb03b'
        },
      },
      // polygon outline stroke
      // This doesn't style the first edge of the polygon, which uses the line stroke styling instead
      {
        "id": "gl-draw-polygon-stroke-active",
        "type": "line",
        "filter": ["all", ["==", "$type", "Polygon"], ["==", "active", "true"]],
        "layout": {
          "line-cap": "round",
          "line-join": "round"
        },
        "paint": {
          "line-color": "#D20C0C",
          "line-dasharray": [0.2, 2],
          "line-width": 2
        }
      },
      // vertex point halos
      {
        "id": "gl-draw-polygon-and-line-vertex-halo-active",
        "type": "circle",
        "filter": ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"],],
        "paint": {
          "circle-radius": 5,
          "circle-color": "#FFF"
        }
      },
      // vertex points
      {
        "id": "gl-draw-polygon-and-line-vertex-active",
        "type": "circle",
        "filter": ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"],],
        "paint": {
          "circle-radius": 3,
          "circle-color": "#D20C0C",
        }
      },

      // INACTIVE
      // line stroke
      {
          "id": "gl-draw-line-inactive",
          "type": "line",
          "filter": ["all", ["==", "$type", "LineString"], ["==", "active", "false"]],
          "layout": {
            "line-cap": "round",
            "line-join": "round"
          },
          "paint": {
            "line-color": "#000",
            "line-width": 3
          }
      },
      // polygon fill
      {
        "id": "gl-draw-polygon-fill-inactive",
        "type": "fill",
        "filter": ["all", ["==", "$type", "Polygon"], ["==", "active", "false"]],
        "paint": {
          "fill-color": "#000",
          "fill-outline-color": "#000",
          "fill-opacity": 0.1
        }
      },
      // polygon outline
      {
        "id": "gl-draw-polygon-stroke-inactive",
        "type": "line",
        "filter": ["all", ["==", "$type", "Polygon"], ["==", "active", "false"]],
        "layout": {
          "line-cap": "round",
          "line-join": "round"
        },
        "paint": {
          "line-color": "#000",
          "line-width": 3
        }
      }
    ]
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73041775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档