Shapes and your own data
Polygons, lines and GeoJSON layers are drawn over the map, above MilsatMaps' own places. They stay when the style changes. Click the area or a purple point:
const map = new milsat.Map(document.getElementById("map"), {
apiKey: "YOUR_API_KEY",
center: [3.3850, 6.5180],
zoom: 14,
});
// An area: one ring of positions. It closes itself.
const zone = new milsat.Polygon({
paths: [[3.3780, 6.5140], [3.3900, 6.5140], [3.3900, 6.5230], [3.3780, 6.5230]],
map,
fillColor: "#8a05ff",
fillOpacity: 0.2,
});
zone.on("click", () => {
document.getElementById("output").textContent = "Delivery zone A";
});
// A line.
new milsat.Polyline({
path: [[3.3760, 6.5120], [3.3850, 6.5185], [3.3950, 6.5200]],
map,
strokeColor: "#dc2626",
strokeWidth: 5,
dashed: true,
});
// Your own data, from GeoJSON.
new milsat.GeoJSONLayer({
map,
data: {
type: "FeatureCollection",
features: [
{ type: "Feature", properties: { name: "Depot" }, geometry: { type: "Point", coordinates: [3.3840, 6.5170] } },
{ type: "Feature", properties: { name: "Branch" }, geometry: { type: "Point", coordinates: [3.3920, 6.5245] } },
],
},
style: { circleColor: "#7c3aed", circleRadius: 8 },
}).on("click", (event) => {
document.getElementById("output").textContent = event.feature.properties.name;
});Polygon
paths is one ring of positions, or several: the first is the outline and the rest are holes. Rings close themselves. Options: fillColor, fillOpacity, strokeColor, strokeWidth. Methods: setPaths, getPaths, setOptions, setMap, remove.
Polyline
path needs at least two positions. Options: strokeColor, strokeWidth, strokeOpacity, dashed. A route from directions goes straight into one: new milsat.Polyline({ path: route.path, map }).
GeoJSONLayer
data is a GeoJSON object or the URL of one. Points are drawn as circles, lines as lines, and areas filled with an outline. Style them with fillColor, fillOpacity, strokeColor, strokeWidth, circleColor and circleRadius. Clicks carry the feature's properties and geometry.
const deliveries = new milsat.GeoJSONLayer({ data: "/api/deliveries.geojson", map });
// Later, with fresh data:
deliveries.setData(await fetch("/api/deliveries.geojson").then((r) => r.json()));