有人知道如何在Mapbox.https://docs.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/上使用此示例更改绘制多边形的默认颜色吗?
浅蓝色在我的地图上不太显眼。
谢谢,
发布于 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
可以将样式选项与绘图控件的其他选项一起添加。使用您链接的示例中的设置以及线条和多边形的示例样式:
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
}
}
]
});
https://stackoverflow.com/questions/73041775
复制相似问题