-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: js tests
- Loading branch information
Showing
6 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/Map/src/Bridge/Leaflet/assets/dist/map_controller.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import AbstractMapController from '@symfony/ux-map'; | ||
import type { Point, MarkerDefinition, PolygonDefinition, PolylineDefinition } from '@symfony/ux-map'; | ||
import 'leaflet/dist/leaflet.min.css'; | ||
import * as L from 'leaflet'; | ||
import type { MapOptions as LeafletMapOptions, MarkerOptions, PopupOptions, PolygonOptions, PolylineOptions } from 'leaflet'; | ||
type MapOptions = Pick<LeafletMapOptions, 'center' | 'zoom'> & { | ||
tileLayer: { | ||
url: string; | ||
attribution: string; | ||
options: Record<string, unknown>; | ||
}; | ||
}; | ||
export default class extends AbstractMapController<MapOptions, typeof L.Map, MarkerOptions, typeof L.Marker, PopupOptions, typeof L.Popup, PolygonOptions, typeof L.Polygon, PolylineOptions, typeof L.Polyline> { | ||
connect(): void; | ||
protected dispatchEvent(name: string, payload?: Record<string, unknown>): void; | ||
protected doCreateMap({ center, zoom, options, }: { | ||
center: Point | null; | ||
zoom: number | null; | ||
options: MapOptions; | ||
}): L.Map; | ||
protected doCreateMarker(definition: MarkerDefinition): L.Marker; | ||
protected doCreatePolygon(definition: PolygonDefinition): L.Polygon; | ||
protected doCreatePolyline(definition: PolylineDefinition): L.Polyline; | ||
protected doCreateInfoWindow({ definition, element, }: { | ||
definition: MarkerDefinition['infoWindow'] | PolygonDefinition['infoWindow'] | PolylineDefinition['infoWindow']; | ||
element: L.Marker | L.Polygon | L.Polyline; | ||
}): L.Popup; | ||
protected doFitBoundsToMarkers(): void; | ||
} | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import AbstractMapController from '@symfony/ux-map'; | ||
import 'leaflet/dist/leaflet.min.css'; | ||
import * as L from 'leaflet'; | ||
|
||
class map_controller extends AbstractMapController { | ||
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(); | ||
} | ||
dispatchEvent(name, payload = {}) { | ||
this.dispatch(name, { | ||
prefix: 'ux:map', | ||
detail: { | ||
...payload, | ||
L, | ||
}, | ||
}); | ||
} | ||
doCreateMap({ center, zoom, options, }) { | ||
const map = L.map(this.element, { | ||
...options, | ||
center: center === null ? undefined : center, | ||
zoom: zoom === null ? undefined : zoom, | ||
}); | ||
L.tileLayer(options.tileLayer.url, { | ||
attribution: options.tileLayer.attribution, | ||
...options.tileLayer.options, | ||
}).addTo(map); | ||
return map; | ||
} | ||
doCreateMarker(definition) { | ||
const { position, title, infoWindow, extra, rawOptions = {}, ...otherOptions } = definition; | ||
const marker = L.marker(position, { title, ...otherOptions, ...rawOptions }).addTo(this.map); | ||
if (infoWindow) { | ||
this.createInfoWindow({ definition: infoWindow, element: marker }); | ||
} | ||
return marker; | ||
} | ||
doCreatePolygon(definition) { | ||
const { points, title, infoWindow, rawOptions = {} } = definition; | ||
const polygon = L.polygon(points, { ...rawOptions }).addTo(this.map); | ||
if (title) { | ||
polygon.bindPopup(title); | ||
} | ||
if (infoWindow) { | ||
this.createInfoWindow({ definition: infoWindow, element: polygon }); | ||
} | ||
return polygon; | ||
} | ||
doCreatePolyline(definition) { | ||
const { points, title, infoWindow, rawOptions = {} } = definition; | ||
const polyline = L.polyline(points, { ...rawOptions }).addTo(this.map); | ||
if (title) { | ||
polyline.bindPopup(title); | ||
} | ||
if (infoWindow) { | ||
this.createInfoWindow({ definition: infoWindow, element: polyline }); | ||
} | ||
return polyline; | ||
} | ||
doCreateInfoWindow({ definition, element, }) { | ||
const { headerContent, content, rawOptions = {}, ...otherOptions } = definition; | ||
element.bindPopup([headerContent, content].filter((x) => x).join('<br>'), { ...otherOptions, ...rawOptions }); | ||
if (definition.opened) { | ||
element.openPopup(); | ||
} | ||
const popup = element.getPopup(); | ||
if (!popup) { | ||
throw new Error('Unable to get the Popup associated with the element.'); | ||
} | ||
return popup; | ||
} | ||
doFitBoundsToMarkers() { | ||
if (this.markers.length === 0) { | ||
return; | ||
} | ||
this.map.fitBounds(this.markers.map((marker) => { | ||
const position = marker.getLatLng(); | ||
return [position.lat, position.lng]; | ||
})); | ||
} | ||
} | ||
|
||
export { map_controller as default }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters