@symfony/ux-leaflet-map
Advanced tools
+12
-10
@@ -1,7 +0,6 @@ | ||
| import type { CircleDefinition, Icon, InfoWindowDefinition, MapDefinition, MarkerDefinition, PolygonDefinition, PolylineDefinition, RectangleDefinition } from '@symfony/ux-map'; | ||
| import AbstractMapController from '@symfony/ux-map'; | ||
| import 'leaflet/dist/leaflet.min.css'; | ||
| import type { CircleOptions, ControlPosition, MapOptions as LeafletMapOptions, MarkerOptions, PolylineOptions as PolygonOptions, PolylineOptions, PopupOptions, PolylineOptions as RectangleOptions } from 'leaflet'; | ||
| import AbstractMapController, { MapDefinition, MarkerDefinition, PolygonDefinition, PolylineDefinition, CircleDefinition, RectangleDefinition, InfoWindowDefinition, Icon } from '@symfony/ux-map'; | ||
| import * as L from 'leaflet'; | ||
| type MapOptions = Pick<LeafletMapOptions, 'attributionControl' | 'zoomControl'> & { | ||
| import { MapOptions as MapOptions$1, ControlPosition, MarkerOptions, PopupOptions, PolylineOptions, CircleOptions } from 'leaflet'; | ||
| type MapOptions = Pick<MapOptions$1, 'attributionControl' | 'zoomControl'> & { | ||
| attributionControlOptions?: { | ||
@@ -24,3 +23,3 @@ position: ControlPosition; | ||
| }; | ||
| export default class extends AbstractMapController<MapOptions, LeafletMapOptions, L.Map, MarkerOptions, L.Marker, PopupOptions, L.Popup, PolygonOptions, L.Polygon, PolylineOptions, L.Polyline, CircleOptions, L.Circle, RectangleOptions, L.Rectangle> { | ||
| declare class export_default extends AbstractMapController<MapOptions, MapOptions$1, L.Map, MarkerOptions, L.Marker, PopupOptions, L.Popup, PolylineOptions, L.Polygon, PolylineOptions, L.Polyline, CircleOptions, L.Circle, PolylineOptions, L.Rectangle> { | ||
| map: L.Map; | ||
@@ -30,5 +29,7 @@ connect(): void; | ||
| zoomValueChanged(): void; | ||
| minZoomValueChanged(): void; | ||
| maxZoomValueChanged(): void; | ||
| protected dispatchEvent(name: string, payload?: Record<string, unknown>): void; | ||
| protected doCreateMap({ definition }: { | ||
| definition: MapDefinition<MapOptions, LeafletMapOptions>; | ||
| definition: MapDefinition<MapOptions, MapOptions$1>; | ||
| }): L.Map; | ||
@@ -40,3 +41,3 @@ protected doCreateMarker({ definition }: { | ||
| protected doCreatePolygon({ definition }: { | ||
| definition: PolygonDefinition<PolygonOptions, PopupOptions>; | ||
| definition: PolygonDefinition<PolylineOptions, PopupOptions>; | ||
| }): L.Polygon; | ||
@@ -53,3 +54,3 @@ protected doRemovePolygon(polygon: L.Polygon): void; | ||
| protected doCreateRectangle({ definition }: { | ||
| definition: RectangleDefinition<RectangleOptions, PopupOptions>; | ||
| definition: RectangleDefinition<PolylineOptions, PopupOptions>; | ||
| }): L.Rectangle; | ||
@@ -68,2 +69,3 @@ protected doRemoveRectangle(rectangle: L.Rectangle): void; | ||
| } | ||
| export {}; | ||
| export { export_default as default }; |
+345
-312
@@ -1,341 +0,374 @@ | ||
| import { Controller } from '@hotwired/stimulus'; | ||
| import 'leaflet/dist/leaflet.min.css'; | ||
| import * as L from 'leaflet'; | ||
| const IconTypes = { | ||
| Url: 'url', | ||
| Svg: 'svg', | ||
| UxIcon: 'ux-icon', | ||
| // ../../../../assets/dist/abstract_map_controller.js | ||
| import { Controller } from "@hotwired/stimulus"; | ||
| var IconTypes = { | ||
| Url: "url", | ||
| Svg: "svg", | ||
| UxIcon: "ux-icon" | ||
| }; | ||
| class default_1 extends Controller { | ||
| constructor() { | ||
| super(...arguments); | ||
| this.markers = new Map(); | ||
| this.polygons = new Map(); | ||
| this.polylines = new Map(); | ||
| this.circles = new Map(); | ||
| this.rectangles = new Map(); | ||
| this.infoWindows = []; | ||
| this.isConnected = false; | ||
| var abstract_map_controller_default = class extends Controller { | ||
| constructor() { | ||
| super(...arguments); | ||
| this.markers = /* @__PURE__ */ new Map(); | ||
| this.polygons = /* @__PURE__ */ new Map(); | ||
| this.polylines = /* @__PURE__ */ new Map(); | ||
| this.circles = /* @__PURE__ */ new Map(); | ||
| this.rectangles = /* @__PURE__ */ new Map(); | ||
| this.infoWindows = []; | ||
| this.isConnected = false; | ||
| } | ||
| connect() { | ||
| const extra = this.hasExtraValue ? this.extraValue : {}; | ||
| const mapDefinition = { | ||
| center: this.hasCenterValue ? this.centerValue : null, | ||
| zoom: this.hasZoomValue ? this.zoomValue : null, | ||
| minZoom: this.hasMinZoomValue ? this.minZoomValue : null, | ||
| maxZoom: this.hasMaxZoomValue ? this.maxZoomValue : null, | ||
| options: this.optionsValue, | ||
| extra | ||
| }; | ||
| this.dispatchEvent("pre-connect", mapDefinition); | ||
| this.createMarker = this.createDrawingFactory("marker", this.markers, this.doCreateMarker.bind(this)); | ||
| this.createPolygon = this.createDrawingFactory("polygon", this.polygons, this.doCreatePolygon.bind(this)); | ||
| this.createPolyline = this.createDrawingFactory("polyline", this.polylines, this.doCreatePolyline.bind(this)); | ||
| this.createCircle = this.createDrawingFactory("circle", this.circles, this.doCreateCircle.bind(this)); | ||
| this.createRectangle = this.createDrawingFactory("rectangle", this.rectangles, this.doCreateRectangle.bind(this)); | ||
| this.map = this.doCreateMap({ definition: mapDefinition }); | ||
| this.markersValue.forEach((definition) => this.createMarker({ definition })); | ||
| this.polygonsValue.forEach((definition) => this.createPolygon({ definition })); | ||
| this.polylinesValue.forEach((definition) => this.createPolyline({ definition })); | ||
| this.circlesValue.forEach((definition) => this.createCircle({ definition })); | ||
| this.rectanglesValue.forEach((definition) => this.createRectangle({ definition })); | ||
| if (this.fitBoundsToMarkersValue) { | ||
| this.doFitBoundsToMarkers(); | ||
| } | ||
| connect() { | ||
| const extra = this.hasExtraValue ? this.extraValue : {}; | ||
| const mapDefinition = { | ||
| center: this.hasCenterValue ? this.centerValue : null, | ||
| zoom: this.hasZoomValue ? this.zoomValue : null, | ||
| options: this.optionsValue, | ||
| extra, | ||
| }; | ||
| this.dispatchEvent('pre-connect', mapDefinition); | ||
| this.createMarker = this.createDrawingFactory('marker', this.markers, this.doCreateMarker.bind(this)); | ||
| this.createPolygon = this.createDrawingFactory('polygon', this.polygons, this.doCreatePolygon.bind(this)); | ||
| this.createPolyline = this.createDrawingFactory('polyline', this.polylines, this.doCreatePolyline.bind(this)); | ||
| this.createCircle = this.createDrawingFactory('circle', this.circles, this.doCreateCircle.bind(this)); | ||
| this.createRectangle = this.createDrawingFactory('rectangle', this.rectangles, this.doCreateRectangle.bind(this)); | ||
| this.map = this.doCreateMap({ definition: mapDefinition }); | ||
| this.markersValue.forEach((definition) => this.createMarker({ definition })); | ||
| this.polygonsValue.forEach((definition) => this.createPolygon({ definition })); | ||
| this.polylinesValue.forEach((definition) => this.createPolyline({ definition })); | ||
| this.circlesValue.forEach((definition) => this.createCircle({ definition })); | ||
| this.rectanglesValue.forEach((definition) => this.createRectangle({ definition })); | ||
| if (this.fitBoundsToMarkersValue) { | ||
| this.doFitBoundsToMarkers(); | ||
| } | ||
| this.dispatchEvent('connect', { | ||
| map: this.map, | ||
| markers: [...this.markers.values()], | ||
| polygons: [...this.polygons.values()], | ||
| polylines: [...this.polylines.values()], | ||
| circles: [...this.circles.values()], | ||
| rectangles: [...this.rectangles.values()], | ||
| infoWindows: this.infoWindows, | ||
| extra, | ||
| }); | ||
| this.isConnected = true; | ||
| this.dispatchEvent("connect", { | ||
| map: this.map, | ||
| markers: [...this.markers.values()], | ||
| polygons: [...this.polygons.values()], | ||
| polylines: [...this.polylines.values()], | ||
| circles: [...this.circles.values()], | ||
| rectangles: [...this.rectangles.values()], | ||
| infoWindows: this.infoWindows, | ||
| extra | ||
| }); | ||
| this.isConnected = true; | ||
| } | ||
| //region Public API | ||
| createInfoWindow({ | ||
| definition, | ||
| element | ||
| }) { | ||
| this.dispatchEvent("info-window:before-create", { definition, element }); | ||
| const infoWindow = this.doCreateInfoWindow({ definition, element }); | ||
| this.dispatchEvent("info-window:after-create", { infoWindow, definition, element }); | ||
| this.infoWindows.push(infoWindow); | ||
| return infoWindow; | ||
| } | ||
| markersValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| createInfoWindow({ definition, element, }) { | ||
| this.dispatchEvent('info-window:before-create', { definition, element }); | ||
| const infoWindow = this.doCreateInfoWindow({ definition, element }); | ||
| this.dispatchEvent('info-window:after-create', { infoWindow, definition, element }); | ||
| this.infoWindows.push(infoWindow); | ||
| return infoWindow; | ||
| this.onDrawChanged(this.markers, this.markersValue, this.createMarker, this.doRemoveMarker); | ||
| if (this.fitBoundsToMarkersValue) { | ||
| this.doFitBoundsToMarkers(); | ||
| } | ||
| markersValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| this.onDrawChanged(this.markers, this.markersValue, this.createMarker, this.doRemoveMarker); | ||
| if (this.fitBoundsToMarkersValue) { | ||
| this.doFitBoundsToMarkers(); | ||
| } | ||
| } | ||
| polygonsValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| polygonsValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| this.onDrawChanged(this.polygons, this.polygonsValue, this.createPolygon, this.doRemovePolygon); | ||
| this.onDrawChanged(this.polygons, this.polygonsValue, this.createPolygon, this.doRemovePolygon); | ||
| } | ||
| polylinesValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| polylinesValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| this.onDrawChanged(this.polylines, this.polylinesValue, this.createPolyline, this.doRemovePolyline); | ||
| this.onDrawChanged(this.polylines, this.polylinesValue, this.createPolyline, this.doRemovePolyline); | ||
| } | ||
| circlesValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| circlesValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| this.onDrawChanged(this.circles, this.circlesValue, this.createCircle, this.doRemoveCircle); | ||
| this.onDrawChanged(this.circles, this.circlesValue, this.createCircle, this.doRemoveCircle); | ||
| } | ||
| rectanglesValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| rectanglesValueChanged() { | ||
| if (!this.isConnected) { | ||
| return; | ||
| } | ||
| this.onDrawChanged(this.rectangles, this.rectanglesValue, this.createRectangle, this.doRemoveRectangle); | ||
| this.onDrawChanged(this.rectangles, this.rectanglesValue, this.createRectangle, this.doRemoveRectangle); | ||
| } | ||
| createDrawingFactory(type, draws, factory) { | ||
| const eventBefore = `${type}:before-create`; | ||
| const eventAfter = `${type}:after-create`; | ||
| return ({ definition }) => { | ||
| this.dispatchEvent(eventBefore, { definition }); | ||
| if (typeof definition.rawOptions !== "undefined") { | ||
| console.warn( | ||
| `[Symfony UX Map] The event "${eventBefore}" added a deprecated "rawOptions" property to the definition, it will be removed in a next major version, replace it with "bridgeOptions" instead.`, | ||
| definition | ||
| ); | ||
| } | ||
| const drawing = factory({ definition }); | ||
| this.dispatchEvent(eventAfter, { [type]: drawing, definition }); | ||
| draws.set(definition["@id"], drawing); | ||
| return drawing; | ||
| }; | ||
| } | ||
| onDrawChanged(draws, newDrawDefinitions, factory, remover) { | ||
| const idsToRemove = new Set(draws.keys()); | ||
| newDrawDefinitions.forEach((definition) => { | ||
| idsToRemove.delete(definition["@id"]); | ||
| }); | ||
| idsToRemove.forEach((id) => { | ||
| const draw = draws.get(id); | ||
| remover(draw); | ||
| draws.delete(id); | ||
| }); | ||
| newDrawDefinitions.forEach((definition) => { | ||
| if (!draws.has(definition["@id"])) { | ||
| factory({ definition }); | ||
| } | ||
| }); | ||
| } | ||
| //endregion | ||
| }; | ||
| abstract_map_controller_default.values = { | ||
| providerOptions: Object, | ||
| center: Object, | ||
| zoom: Number, | ||
| minZoom: Number, | ||
| maxZoom: Number, | ||
| fitBoundsToMarkers: Boolean, | ||
| markers: Array, | ||
| polygons: Array, | ||
| polylines: Array, | ||
| circles: Array, | ||
| rectangles: Array, | ||
| options: Object, | ||
| extra: Object | ||
| }; | ||
| // src/map_controller.ts | ||
| import "leaflet/dist/leaflet.min.css"; | ||
| import * as L from "leaflet"; | ||
| var map_controller_default = class extends abstract_map_controller_default { | ||
| connect() { | ||
| L.Marker.prototype.options.icon = L.divIcon({ | ||
| html: '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" fill-rule="evenodd" stroke-linecap="round" clip-rule="evenodd" viewBox="0 0 500 820"><defs><linearGradient id="__sf_ux_map_gradient_marker_fill" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -37.57 37.57 0 416.45 541)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#126FC6"/><stop offset="1" stop-color="#4C9CD1"/></linearGradient><linearGradient id="__sf_ux_map_gradient_marker_border" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -19.05 19.05 0 414.48 522.49)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2E6C97"/><stop offset="1" stop-color="#3883B7"/></linearGradient></defs><circle cx="252.31" cy="266.24" r="83.99" fill="#fff"/><path fill="url(#__sf_ux_map_gradient_marker_fill)" stroke="url(#__sf_ux_map_gradient_marker_border)" stroke-width="1.1" d="M416.54 503.61c-6.57 0-12.04 5.7-12.04 11.87 0 2.78 1.56 6.3 2.7 8.74l9.3 17.88 9.26-17.88c1.13-2.43 2.74-5.79 2.74-8.74 0-6.18-5.38-11.87-11.96-11.87Zm0 7.16a4.69 4.69 0 1 1-.02 9.4 4.69 4.69 0 0 1 .02-9.4Z" transform="translate(-7889.1 -9807.44) scale(19.54)"/></svg>', | ||
| iconSize: [25, 41], | ||
| iconAnchor: [12.5, 41], | ||
| popupAnchor: [0, -41], | ||
| className: "" | ||
| // Adding an empty class to the icon to avoid the default Leaflet styles | ||
| }); | ||
| super.connect(); | ||
| } | ||
| centerValueChanged() { | ||
| if (this.map && this.hasCenterValue && this.centerValue && this.hasZoomValue && this.zoomValue) { | ||
| this.map.setView(this.centerValue, this.zoomValue); | ||
| } | ||
| createDrawingFactory(type, draws, factory) { | ||
| const eventBefore = `${type}:before-create`; | ||
| const eventAfter = `${type}:after-create`; | ||
| return ({ definition }) => { | ||
| this.dispatchEvent(eventBefore, { definition }); | ||
| if (typeof definition.rawOptions !== 'undefined') { | ||
| console.warn(`[Symfony UX Map] The event "${eventBefore}" added a deprecated "rawOptions" property to the definition, it will be removed in a next major version, replace it with "bridgeOptions" instead.`, definition); | ||
| } | ||
| const drawing = factory({ definition }); | ||
| this.dispatchEvent(eventAfter, { [type]: drawing, definition }); | ||
| draws.set(definition['@id'], drawing); | ||
| return drawing; | ||
| }; | ||
| } | ||
| zoomValueChanged() { | ||
| if (this.map && this.hasZoomValue && this.zoomValue) { | ||
| this.map.setZoom(this.zoomValue); | ||
| } | ||
| onDrawChanged(draws, newDrawDefinitions, factory, remover) { | ||
| const idsToRemove = new Set(draws.keys()); | ||
| newDrawDefinitions.forEach((definition) => { | ||
| idsToRemove.delete(definition['@id']); | ||
| }); | ||
| idsToRemove.forEach((id) => { | ||
| const draw = draws.get(id); | ||
| remover(draw); | ||
| draws.delete(id); | ||
| }); | ||
| newDrawDefinitions.forEach((definition) => { | ||
| if (!draws.has(definition['@id'])) { | ||
| factory({ definition }); | ||
| } | ||
| }); | ||
| } | ||
| minZoomValueChanged() { | ||
| if (this.map && this.hasMinZoomValue && this.minZoomValue) { | ||
| this.map.setMinZoom(this.minZoomValue); | ||
| } | ||
| } | ||
| default_1.values = { | ||
| providerOptions: Object, | ||
| center: Object, | ||
| zoom: Number, | ||
| fitBoundsToMarkers: Boolean, | ||
| markers: Array, | ||
| polygons: Array, | ||
| polylines: Array, | ||
| circles: Array, | ||
| rectangles: Array, | ||
| options: Object, | ||
| extra: Object, | ||
| }; | ||
| class map_controller extends default_1 { | ||
| connect() { | ||
| L.Marker.prototype.options.icon = L.divIcon({ | ||
| html: '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" fill-rule="evenodd" stroke-linecap="round" clip-rule="evenodd" viewBox="0 0 500 820"><defs><linearGradient id="__sf_ux_map_gradient_marker_fill" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -37.57 37.57 0 416.45 541)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#126FC6"/><stop offset="1" stop-color="#4C9CD1"/></linearGradient><linearGradient id="__sf_ux_map_gradient_marker_border" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -19.05 19.05 0 414.48 522.49)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2E6C97"/><stop offset="1" stop-color="#3883B7"/></linearGradient></defs><circle cx="252.31" cy="266.24" r="83.99" fill="#fff"/><path fill="url(#__sf_ux_map_gradient_marker_fill)" stroke="url(#__sf_ux_map_gradient_marker_border)" stroke-width="1.1" d="M416.54 503.61c-6.57 0-12.04 5.7-12.04 11.87 0 2.78 1.56 6.3 2.7 8.74l9.3 17.88 9.26-17.88c1.13-2.43 2.74-5.79 2.74-8.74 0-6.18-5.38-11.87-11.96-11.87Zm0 7.16a4.69 4.69 0 1 1-.02 9.4 4.69 4.69 0 0 1 .02-9.4Z" transform="translate(-7889.1 -9807.44) scale(19.54)"/></svg>', | ||
| iconSize: [25, 41], | ||
| iconAnchor: [12.5, 41], | ||
| popupAnchor: [0, -41], | ||
| className: '', | ||
| }); | ||
| super.connect(); | ||
| } | ||
| maxZoomValueChanged() { | ||
| if (this.map && this.hasMaxZoomValue && this.maxZoomValue) { | ||
| this.map.setMaxZoom(this.maxZoomValue); | ||
| } | ||
| centerValueChanged() { | ||
| if (this.map && this.hasCenterValue && this.centerValue && this.hasZoomValue && this.zoomValue) { | ||
| this.map.setView(this.centerValue, this.zoomValue); | ||
| } | ||
| } | ||
| dispatchEvent(name, payload = {}) { | ||
| payload.L = L; | ||
| this.dispatch(name, { | ||
| prefix: "ux:map", | ||
| detail: payload | ||
| }); | ||
| } | ||
| doCreateMap({ definition }) { | ||
| const { center, zoom, minZoom, maxZoom, options, bridgeOptions = {} } = definition; | ||
| const map2 = L.map(this.element, { | ||
| center: center === null ? void 0 : center, | ||
| zoom: zoom === null ? void 0 : zoom, | ||
| minZoom: minZoom === null ? void 0 : minZoom, | ||
| maxZoom: maxZoom === null ? void 0 : maxZoom, | ||
| attributionControl: false, | ||
| zoomControl: false, | ||
| ...options, | ||
| ...bridgeOptions | ||
| }); | ||
| if (options.tileLayer) { | ||
| L.tileLayer(options.tileLayer.url, { | ||
| attribution: options.tileLayer.attribution, | ||
| ...options.tileLayer.options | ||
| }).addTo(map2); | ||
| } | ||
| zoomValueChanged() { | ||
| if (this.map && this.hasZoomValue && this.zoomValue) { | ||
| this.map.setZoom(this.zoomValue); | ||
| } | ||
| if (typeof options.attributionControlOptions !== "undefined") { | ||
| L.control.attribution({ ...options.attributionControlOptions }).addTo(map2); | ||
| } | ||
| dispatchEvent(name, payload = {}) { | ||
| payload.L = L; | ||
| this.dispatch(name, { | ||
| prefix: 'ux:map', | ||
| detail: payload, | ||
| }); | ||
| if (typeof options.zoomControlOptions !== "undefined") { | ||
| L.control.zoom({ ...options.zoomControlOptions }).addTo(map2); | ||
| } | ||
| doCreateMap({ definition }) { | ||
| const { center, zoom, options, bridgeOptions = {} } = definition; | ||
| const map = L.map(this.element, { | ||
| center: center === null ? undefined : center, | ||
| zoom: zoom === null ? undefined : zoom, | ||
| attributionControl: false, | ||
| zoomControl: false, | ||
| ...options, | ||
| ...bridgeOptions, | ||
| }); | ||
| if (options.tileLayer) { | ||
| L.tileLayer(options.tileLayer.url, { | ||
| attribution: options.tileLayer.attribution, | ||
| ...options.tileLayer.options, | ||
| }).addTo(map); | ||
| } | ||
| if (typeof options.attributionControlOptions !== 'undefined') { | ||
| L.control.attribution({ ...options.attributionControlOptions }).addTo(map); | ||
| } | ||
| if (typeof options.zoomControlOptions !== 'undefined') { | ||
| L.control.zoom({ ...options.zoomControlOptions }).addTo(map); | ||
| } | ||
| return map; | ||
| return map2; | ||
| } | ||
| doCreateMarker({ definition }) { | ||
| const { "@id": _id, position, title, infoWindow, icon: icon2, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const marker2 = L.marker(position, { | ||
| title: title || void 0, | ||
| ...rawOptions, | ||
| ...bridgeOptions, | ||
| riseOnHover: true | ||
| }).addTo(this.map); | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: marker2 }); | ||
| } | ||
| doCreateMarker({ definition }) { | ||
| const { '@id': _id, position, title, infoWindow, icon, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const marker = L.marker(position, { | ||
| title: title || undefined, | ||
| ...rawOptions, | ||
| ...bridgeOptions, | ||
| riseOnHover: true, | ||
| }).addTo(this.map); | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: marker }); | ||
| } | ||
| if (icon) { | ||
| this.doCreateIcon({ definition: icon, element: marker }); | ||
| } | ||
| return marker; | ||
| if (icon2) { | ||
| this.doCreateIcon({ definition: icon2, element: marker2 }); | ||
| } | ||
| doRemoveMarker(marker) { | ||
| marker.remove(); | ||
| return marker2; | ||
| } | ||
| doRemoveMarker(marker2) { | ||
| marker2.remove(); | ||
| } | ||
| doCreatePolygon({ definition }) { | ||
| const { "@id": _id, points, title, infoWindow, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const polygon2 = L.polygon(points, { ...rawOptions, ...bridgeOptions }).addTo(this.map); | ||
| if (title) { | ||
| polygon2.bindPopup(title); | ||
| } | ||
| doCreatePolygon({ definition }) { | ||
| const { '@id': _id, points, title, infoWindow, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const polygon = L.polygon(points, { ...rawOptions, ...bridgeOptions }).addTo(this.map); | ||
| if (title) { | ||
| polygon.bindPopup(title); | ||
| } | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: polygon }); | ||
| } | ||
| return polygon; | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: polygon2 }); | ||
| } | ||
| doRemovePolygon(polygon) { | ||
| polygon.remove(); | ||
| return polygon2; | ||
| } | ||
| doRemovePolygon(polygon2) { | ||
| polygon2.remove(); | ||
| } | ||
| doCreatePolyline({ definition }) { | ||
| const { "@id": _id, points, title, infoWindow, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const polyline2 = L.polyline(points, { ...rawOptions, ...bridgeOptions }).addTo(this.map); | ||
| if (title) { | ||
| polyline2.bindPopup(title); | ||
| } | ||
| doCreatePolyline({ definition }) { | ||
| const { '@id': _id, points, title, infoWindow, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const polyline = L.polyline(points, { ...rawOptions, ...bridgeOptions }).addTo(this.map); | ||
| if (title) { | ||
| polyline.bindPopup(title); | ||
| } | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: polyline }); | ||
| } | ||
| return polyline; | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: polyline2 }); | ||
| } | ||
| doRemovePolyline(polyline) { | ||
| polyline.remove(); | ||
| return polyline2; | ||
| } | ||
| doRemovePolyline(polyline2) { | ||
| polyline2.remove(); | ||
| } | ||
| doCreateCircle({ definition }) { | ||
| const { "@id": _id, center, radius, title, infoWindow, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const circle2 = L.circle(center, { radius, ...rawOptions, ...bridgeOptions }).addTo(this.map); | ||
| if (title) { | ||
| circle2.bindPopup(title); | ||
| } | ||
| doCreateCircle({ definition }) { | ||
| const { '@id': _id, center, radius, title, infoWindow, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const circle = L.circle(center, { radius, ...rawOptions, ...bridgeOptions }).addTo(this.map); | ||
| if (title) { | ||
| circle.bindPopup(title); | ||
| } | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: circle }); | ||
| } | ||
| return circle; | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: circle2 }); | ||
| } | ||
| doRemoveCircle(circle) { | ||
| circle.remove(); | ||
| return circle2; | ||
| } | ||
| doRemoveCircle(circle2) { | ||
| circle2.remove(); | ||
| } | ||
| doCreateRectangle({ definition }) { | ||
| const { "@id": _id, southWest, northEast, title, infoWindow, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const rectangle2 = L.rectangle( | ||
| [ | ||
| [southWest.lat, southWest.lng], | ||
| [northEast.lat, northEast.lng] | ||
| ], | ||
| { ...rawOptions, ...bridgeOptions } | ||
| ).addTo(this.map); | ||
| if (title) { | ||
| rectangle2.bindPopup(title); | ||
| } | ||
| doCreateRectangle({ definition }) { | ||
| const { '@id': _id, southWest, northEast, title, infoWindow, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| const rectangle = L.rectangle([ | ||
| [southWest.lat, southWest.lng], | ||
| [northEast.lat, northEast.lng], | ||
| ], { ...rawOptions, ...bridgeOptions }).addTo(this.map); | ||
| if (title) { | ||
| rectangle.bindPopup(title); | ||
| } | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: rectangle }); | ||
| } | ||
| return rectangle; | ||
| if (infoWindow) { | ||
| this.createInfoWindow({ definition: infoWindow, element: rectangle2 }); | ||
| } | ||
| doRemoveRectangle(rectangle) { | ||
| rectangle.remove(); | ||
| return rectangle2; | ||
| } | ||
| doRemoveRectangle(rectangle2) { | ||
| rectangle2.remove(); | ||
| } | ||
| doCreateInfoWindow({ | ||
| definition, | ||
| element | ||
| }) { | ||
| const { headerContent, content, opened, autoClose, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| element.bindPopup([headerContent, content].filter((x) => x).join("<br>"), { ...rawOptions, ...bridgeOptions }); | ||
| if (opened) { | ||
| if (autoClose) { | ||
| this.closePopups(); | ||
| } | ||
| element.openPopup(); | ||
| } | ||
| doCreateInfoWindow({ definition, element, }) { | ||
| const { headerContent, content, opened, autoClose, rawOptions = {}, bridgeOptions = {} } = definition; | ||
| element.bindPopup([headerContent, content].filter((x) => x).join('<br>'), { ...rawOptions, ...bridgeOptions }); | ||
| if (opened) { | ||
| if (autoClose) { | ||
| this.closePopups(); | ||
| } | ||
| element.openPopup(); | ||
| } | ||
| const popup = element.getPopup(); | ||
| if (!popup) { | ||
| throw new Error('Unable to get the Popup associated with the element.'); | ||
| } | ||
| popup.on('click', () => { | ||
| if (autoClose) { | ||
| this.closePopups({ except: popup }); | ||
| } | ||
| }); | ||
| return popup; | ||
| const popup = element.getPopup(); | ||
| if (!popup) { | ||
| throw new Error("Unable to get the Popup associated with the element."); | ||
| } | ||
| doCreateIcon({ definition, element }) { | ||
| const { type, width, height } = definition; | ||
| let icon; | ||
| if (type === IconTypes.Svg) { | ||
| icon = L.divIcon({ | ||
| html: definition.html, | ||
| iconSize: [width, height], | ||
| className: '', | ||
| }); | ||
| } | ||
| else if (type === IconTypes.UxIcon) { | ||
| icon = L.divIcon({ | ||
| html: definition._generated_html, | ||
| iconSize: [width, height], | ||
| className: '', | ||
| }); | ||
| } | ||
| else if (type === IconTypes.Url) { | ||
| icon = L.icon({ | ||
| iconUrl: definition.url, | ||
| iconSize: [width, height], | ||
| className: '', | ||
| }); | ||
| } | ||
| else { | ||
| throw new Error(`Unsupported icon type: ${type}.`); | ||
| } | ||
| element.setIcon(icon); | ||
| popup.on("click", () => { | ||
| if (autoClose) { | ||
| this.closePopups({ except: popup }); | ||
| } | ||
| }); | ||
| return popup; | ||
| } | ||
| doCreateIcon({ definition, element }) { | ||
| const { type, width, height } = definition; | ||
| let icon2; | ||
| if (type === IconTypes.Svg) { | ||
| icon2 = L.divIcon({ | ||
| html: definition.html, | ||
| iconSize: [width, height], | ||
| className: "" | ||
| // Adding an empty class to the icon to avoid the default Leaflet styles | ||
| }); | ||
| } else if (type === IconTypes.UxIcon) { | ||
| icon2 = L.divIcon({ | ||
| html: definition._generated_html, | ||
| iconSize: [width, height], | ||
| className: "" | ||
| // Adding an empty class to the icon to avoid the default Leaflet styles | ||
| }); | ||
| } else if (type === IconTypes.Url) { | ||
| icon2 = L.icon({ | ||
| iconUrl: definition.url, | ||
| iconSize: [width, height], | ||
| className: "" | ||
| // Adding an empty class to the icon to avoid the default Leaflet styles | ||
| }); | ||
| } else { | ||
| throw new Error(`Unsupported icon type: ${type}.`); | ||
| } | ||
| doFitBoundsToMarkers() { | ||
| if (this.markers.size === 0) { | ||
| return; | ||
| } | ||
| const bounds = []; | ||
| this.markers.forEach((marker) => { | ||
| const position = marker.getLatLng(); | ||
| bounds.push([position.lat, position.lng]); | ||
| }); | ||
| this.map.fitBounds(bounds); | ||
| element.setIcon(icon2); | ||
| } | ||
| doFitBoundsToMarkers() { | ||
| if (this.markers.size === 0) { | ||
| return; | ||
| } | ||
| closePopups(options = {}) { | ||
| this.infoWindows.forEach((popup) => { | ||
| if (options.except && popup === options.except) { | ||
| return; | ||
| } | ||
| popup.close(); | ||
| }); | ||
| } | ||
| } | ||
| export { map_controller as default }; | ||
| const bounds = []; | ||
| this.markers.forEach((marker2) => { | ||
| const position = marker2.getLatLng(); | ||
| bounds.push([position.lat, position.lng]); | ||
| }); | ||
| this.map.fitBounds(bounds); | ||
| } | ||
| closePopups(options = {}) { | ||
| this.infoWindows.forEach((popup) => { | ||
| if (options.except && popup === options.except) { | ||
| return; | ||
| } | ||
| popup.close(); | ||
| }); | ||
| } | ||
| }; | ||
| export { | ||
| map_controller_default as default | ||
| }; |
+19
-10
@@ -5,3 +5,3 @@ { | ||
| "license": "MIT", | ||
| "version": "2.27.0", | ||
| "version": "2.28.1", | ||
| "keywords": [ | ||
@@ -20,9 +20,2 @@ "symfony-ux", | ||
| "types": "dist/map_controller.d.ts", | ||
| "scripts": { | ||
| "build": "node ../../../../../../bin/build_package.js .", | ||
| "watch": "node ../../../../../../bin/build_package.js . --watch", | ||
| "test": "../../../../../../bin/test_package.sh .", | ||
| "check": "biome check", | ||
| "ci": "biome ci" | ||
| }, | ||
| "symfony": { | ||
@@ -54,6 +47,22 @@ "controllers": { | ||
| "@hotwired/stimulus": "^3.0.0", | ||
| "@symfony/ux-map": "2.27.0", | ||
| "@testing-library/dom": "^10.4.0", | ||
| "@testing-library/jest-dom": "^6.6.3", | ||
| "@testing-library/user-event": "^14.6.1", | ||
| "@types/leaflet": "^1.9.12", | ||
| "leaflet": "^1.9.4" | ||
| "@vitest/browser": "^3.2.4", | ||
| "jsdom": "^26.1.0", | ||
| "leaflet": "^1.9.4", | ||
| "tslib": "^2.8.1", | ||
| "tsx": "^4.20.3", | ||
| "typescript": "^5.8.3", | ||
| "vitest": "^3.2.4", | ||
| "@symfony/ux-map": "2.28.1" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsx ../../../../../../bin/build_package.ts .", | ||
| "watch": "tsx ../../../../../../bin/build_package.ts . --watch", | ||
| "test": "../../../../../../bin/test_package.sh .", | ||
| "check": "biome check", | ||
| "ci": "biome ci" | ||
| } | ||
| } |
20786
0.47%441
8.62%13
225%