2024-08-05 15:23:08 -04:00
|
|
|
import { Controller } from "@hotwired/stimulus"
|
|
|
|
|
import L, { latLng } from "leaflet";
|
|
|
|
|
import { osmMapLayer } from "../maps/layers";
|
|
|
|
|
|
2024-09-05 15:01:59 -04:00
|
|
|
// This controller is used to display a map of all coordinates for a visit
|
|
|
|
|
// on the "Map" modal of a visit on the Visits page
|
|
|
|
|
|
2024-08-05 15:23:08 -04:00
|
|
|
export default class extends Controller {
|
|
|
|
|
static targets = ["container"];
|
|
|
|
|
|
|
|
|
|
connect() {
|
|
|
|
|
this.coordinates = JSON.parse(this.element.dataset.coordinates);
|
|
|
|
|
this.center = JSON.parse(this.element.dataset.center);
|
|
|
|
|
this.radius = this.element.dataset.radius;
|
|
|
|
|
this.map = L.map(this.containerTarget).setView([this.center[0], this.center[1]], 17);
|
|
|
|
|
|
|
|
|
|
osmMapLayer(this.map),
|
|
|
|
|
this.addMarkers();
|
|
|
|
|
|
|
|
|
|
L.circle([this.center[0], this.center[1]], {
|
|
|
|
|
radius: this.radius,
|
|
|
|
|
color: 'red',
|
|
|
|
|
fillColor: '#f03',
|
|
|
|
|
fillOpacity: 0.5
|
|
|
|
|
}).addTo(this.map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addMarkers() {
|
|
|
|
|
this.coordinates.forEach((coordinate) => {
|
|
|
|
|
L.circleMarker([coordinate[0], coordinate[1]], { radius: 4 }).addTo(this.map);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|