多边形选择改变颜色
Polygon Selection change color
有什么方法可以更改 mapbox 绘图工具的默认颜色,我想用绿色而不是默认的橙色绘制多边形。
像
var draw = new MapboxDraw({
displayControlsDefault: false,
controls: {
polygon: true,
trash: true
}
properties: {
color: green
}
});
map.addControl(draw);
您可以像这样添加样式参数:
const mapDraw = new MapboxDraw({ styles: [
// ACTIVE (being drawn)
// polygon fill
{
"id": "gl-draw-polygon-fill",
"type": "fill",
"filter": \["all", \["==", "$type", "Polygon"\], \["!=", "mode", "static"\]\],
"paint": {
"fill-color": "#D20C0C",
"fill-outline-color": "#D20C0C",
"fill-opacity": 0.1
}
},
// 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"\], \["!=", "mode", "static"\]\],
"layout": {
"line-cap": "round",
"line-join": "round"
},
"paint": {
"line-color": "#D20C0C",
"line-dasharray": \[0.2, 2\],
"line-width": 3
}
},
// vertex points
{
"id": "gl-draw-polygon-and-line-vertex-active",
"type": "circle",
"filter": \["all", \["==", "meta", "vertex"\], \["==", "$type", "Point"\], \["!=", "mode", "static"\]\],
"paint": {
"circle-radius": 3,
"circle-color": "#D20C0C",
}
}
] })]
澄清一下,如果您使用此方法,并且想要绘制点和多边形,则必须定义它们;
const mapDraw = new MapboxDraw({
displayControlsDefault: false,
controls: {
polygon: true,
point: true,
trash: true
},
styles: [{
"id": "gl-draw-polygon-fill",
"type": "fill",
"paint": {
"fill-color": "#0BD1C3",
"fill-outline-color": "#D20C0C",
"fill-opacity": 0.1
}
},
//*** HERE YOU DEFINE POINT STYLE *** //
{
"id": "gl-draw-point",
"type": "circle",
"paint": {
"circle-radius": 5,
"circle-color": "#ff0202"
}
} //**********************************//
,
{
"id": "gl-draw-polygon-stroke-active",
"type": "line",
"layout": {
"line-cap": "round",
"line-join": "round"
},
"paint": {
"line-color": "#D20C0C",
"line-dasharray": [0.2, 2],
"line-width": 3
}
},
{
"id": "gl-draw-polygon-and-line-vertex-active",
"type": "circle",
"filter": ["all", ["==", "meta", "vertex"],
["==", "$type", "Point"],
["!=", "mode", "static"]
],
"paint": {
"circle-radius": 3,
"circle-color": "#470CD1",
}
}
]
})
map.addControl(mapDraw);
有什么方法可以更改 mapbox 绘图工具的默认颜色,我想用绿色而不是默认的橙色绘制多边形。 像
var draw = new MapboxDraw({
displayControlsDefault: false,
controls: {
polygon: true,
trash: true
}
properties: {
color: green
}
});
map.addControl(draw);
您可以像这样添加样式参数:
const mapDraw = new MapboxDraw({ styles: [
// ACTIVE (being drawn)
// polygon fill
{
"id": "gl-draw-polygon-fill",
"type": "fill",
"filter": \["all", \["==", "$type", "Polygon"\], \["!=", "mode", "static"\]\],
"paint": {
"fill-color": "#D20C0C",
"fill-outline-color": "#D20C0C",
"fill-opacity": 0.1
}
},
// 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"\], \["!=", "mode", "static"\]\],
"layout": {
"line-cap": "round",
"line-join": "round"
},
"paint": {
"line-color": "#D20C0C",
"line-dasharray": \[0.2, 2\],
"line-width": 3
}
},
// vertex points
{
"id": "gl-draw-polygon-and-line-vertex-active",
"type": "circle",
"filter": \["all", \["==", "meta", "vertex"\], \["==", "$type", "Point"\], \["!=", "mode", "static"\]\],
"paint": {
"circle-radius": 3,
"circle-color": "#D20C0C",
}
}
] })]
澄清一下,如果您使用此方法,并且想要绘制点和多边形,则必须定义它们;
const mapDraw = new MapboxDraw({
displayControlsDefault: false,
controls: {
polygon: true,
point: true,
trash: true
},
styles: [{
"id": "gl-draw-polygon-fill",
"type": "fill",
"paint": {
"fill-color": "#0BD1C3",
"fill-outline-color": "#D20C0C",
"fill-opacity": 0.1
}
},
//*** HERE YOU DEFINE POINT STYLE *** //
{
"id": "gl-draw-point",
"type": "circle",
"paint": {
"circle-radius": 5,
"circle-color": "#ff0202"
}
} //**********************************//
,
{
"id": "gl-draw-polygon-stroke-active",
"type": "line",
"layout": {
"line-cap": "round",
"line-join": "round"
},
"paint": {
"line-color": "#D20C0C",
"line-dasharray": [0.2, 2],
"line-width": 3
}
},
{
"id": "gl-draw-polygon-and-line-vertex-active",
"type": "circle",
"filter": ["all", ["==", "meta", "vertex"],
["==", "$type", "Point"],
["!=", "mode", "static"]
],
"paint": {
"circle-radius": 3,
"circle-color": "#470CD1",
}
}
]
})
map.addControl(mapDraw);