Skip to content

Commit

Permalink
fix: fix convert area function
Browse files Browse the repository at this point in the history
  • Loading branch information
dqunbp committed Jun 7, 2020
1 parent 14e15be commit a4a480b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
40 changes: 20 additions & 20 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ const OSM_STYLE = {
tiles: [
"https://a.tile.openstreetmap.org/{z}/{x}/{y}.png",
"https://b.tile.openstreetmap.org/{z}/{x}/{y}.png",
"https://c.tile.openstreetmap.org/{z}/{x}/{y}.png"
"https://c.tile.openstreetmap.org/{z}/{x}/{y}.png",
],
tileSize: 256
}
tileSize: 256,
},
},
layers: [
{
id: "osm",
source: "osm",
type: "raster"
}
]
type: "raster",
},
],
};

function updateDrawThemes(themes) {
return defaultDrawThemes
.filter(theme => !themes.map(({ id }) => id).includes(theme.id))
.filter((theme) => !themes.map(({ id }) => id).includes(theme.id))
.concat(themes);
}

Expand All @@ -40,30 +40,30 @@ export const drawStyles = updateDrawThemes([
"case",
["!", ["to-boolean", ["get", "user_size_exceed"]]],
"#fbb03b",
"#ff0000"
"#ff0000",
],
"fill-opacity": 0.2
}
"fill-opacity": 0.2,
},
},
{
id: "gl-draw-polygon-stroke-active",
type: "line",
filter: ["all", ["==", "active", "true"], ["==", "$type", "Polygon"]],
layout: {
"line-cap": "round",
"line-join": "round"
"line-join": "round",
},
paint: {
"line-color": [
"case",
["!", ["to-boolean", ["get", "user_size_exceed"]]],
"#fbb03b",
"#ff0000"
"#ff0000",
],
"line-dasharray": [0.2, 2],
"line-width": 2
}
}
"line-width": 2,
},
},
]);

const map = new mapboxgl.Map({
Expand All @@ -72,14 +72,14 @@ const map = new mapboxgl.Map({
center: [-91.874, 42.76], // starting position
zoom: 12, // starting zoom
modes: Object.assign(MapboxDraw.modes, {
draw_polygon: DrawRectangle
})
draw_polygon: DrawRectangle,
}),
});

const draw = new MapboxDraw({
userProperties: true,
displayControlsDefault: false,
styles: drawStyles
styles: drawStyles,
});
map.addControl(draw);
document.getElementById("draw-rectangle").addEventListener("click", () => {
Expand All @@ -89,7 +89,7 @@ document.getElementById("draw-rectangle").addEventListener("click", () => {
escapeKeyStopsDrawing: true, // optional
allowCreateExceeded: false, // optional
exceedCallsOnEachMove: false, // optional, true - calls exceedCallback on each mouse move
exceedCallback: area => console.log("exceeded!", area), // optional
areaChangedCallback: area => console.log("area updated", area) // optional
exceedCallback: (area) => console.log("exceeded!", area), // optional
areaChangedCallback: (area) => console.log("area updated", area), // optional
});
});
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function convertToKm2(value) {
return convertArea(value, "meters", "kilometers");
}
function getArea(feature) {
convertToKm2(area(feature));
return convertToKm2(area(feature));
}

const DrawRectangle = {};
Expand Down

0 comments on commit a4a480b

Please sign in to comment.