@symfony/ux-leaflet-map 2.23.0 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2024-present Fabien Potencier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is furnished
8
+ to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @symfony/ux-leaflet-map
2
+
3
+ JavaScript assets of the [symfony/ux-leaflet-map](https://packagist.org/packages/symfony/ux-leaflet-map) PHP package.
4
+
5
+ ## Installation
6
+
7
+ This npm package is **reserved for advanced users** who want to decouple their JavaScript dependencies from their PHP dependencies (e.g., when building Docker images, running JavaScript-only pipelines, etc.).
8
+
9
+ We **strongly recommend not installing this package directly**, but instead install the PHP package [symfony/ux-leaflet-map](https://packagist.org/packages/symfony/ux-leaflet-map) in your Symfony application with [Flex](https://github.com/symfony/flex) enabled.
10
+
11
+ If you still want to install this package directly, please make sure its version exactly matches [symfony/ux-leaflet-map](https://packagist.org/packages/symfony/ux-leaflet-map) PHP package version:
12
+ ```shell
13
+ composer require symfony/ux-leaflet-map:2.23.0
14
+ npm add @symfony/ux-leaflet-map@2.23.0
15
+ ```
16
+
17
+ **Tip:** Your `package.json` file will be automatically modified by [Flex](https://github.com/symfony/flex) when installing or upgrading a PHP package. To prevent this behavior, ensure to **use at least Flex 1.22.0 or 2.5.0**, and run `composer config extra.symfony.flex.synchronize_package_json false`.
18
+
19
+ ## Resources
20
+
21
+ - [Documentation](https://github.com/symfony/ux/tree/2.x/src/Map/src/Bridge/Google)
22
+ - [Report issues](https://github.com/symfony/ux/issues) and
23
+ [send Pull Requests](https://github.com/symfony/ux/pulls)
24
+ in the [main Symfony UX repository](https://github.com/symfony/ux)
@@ -1,5 +1,5 @@
1
1
  import AbstractMapController from '@symfony/ux-map';
2
- import type { InfoWindowWithoutPositionDefinition, MarkerDefinition, Point, PolygonDefinition, PolylineDefinition } from '@symfony/ux-map';
2
+ import type { Icon, InfoWindowWithoutPositionDefinition, MarkerDefinition, Point, PolygonDefinition, PolylineDefinition } from '@symfony/ux-map';
3
3
  import 'leaflet/dist/leaflet.min.css';
4
4
  import * as L from 'leaflet';
5
5
  import type { MapOptions as LeafletMapOptions, MarkerOptions, PolylineOptions as PolygonOptions, PolylineOptions, PopupOptions } from 'leaflet';
@@ -37,6 +37,10 @@ export default class extends AbstractMapController<MapOptions, L.Map, MarkerOpti
37
37
  definition: InfoWindowWithoutPositionDefinition<PopupOptions>;
38
38
  element: L.Marker | L.Polygon | L.Polyline;
39
39
  }): L.Popup;
40
+ protected doCreateIcon({ definition, element, }: {
41
+ definition: Icon;
42
+ element: L.Marker;
43
+ }): void;
40
44
  protected doFitBoundsToMarkers(): void;
41
45
  }
42
46
  export {};
@@ -2,6 +2,11 @@ import { Controller } from '@hotwired/stimulus';
2
2
  import 'leaflet/dist/leaflet.min.css';
3
3
  import * as L from 'leaflet';
4
4
 
5
+ const IconTypes = {
6
+ Url: 'url',
7
+ Svg: 'svg',
8
+ UxIcon: 'ux-icon',
9
+ };
5
10
  class default_1 extends Controller {
6
11
  constructor() {
7
12
  super(...arguments);
@@ -147,11 +152,14 @@ class map_controller extends default_1 {
147
152
  return map;
148
153
  }
149
154
  doCreateMarker({ definition }) {
150
- const { '@id': _id, position, title, infoWindow, extra, rawOptions = {}, ...otherOptions } = definition;
155
+ const { '@id': _id, position, title, infoWindow, icon, extra, rawOptions = {}, ...otherOptions } = definition;
151
156
  const marker = L.marker(position, { title: title || undefined, ...otherOptions, ...rawOptions }).addTo(this.map);
152
157
  if (infoWindow) {
153
158
  this.createInfoWindow({ definition: infoWindow, element: marker });
154
159
  }
160
+ if (icon) {
161
+ this.doCreateIcon({ definition: icon, element: marker });
162
+ }
155
163
  return marker;
156
164
  }
157
165
  doRemoveMarker(marker) {
@@ -197,6 +205,35 @@ class map_controller extends default_1 {
197
205
  }
198
206
  return popup;
199
207
  }
208
+ doCreateIcon({ definition, element, }) {
209
+ const { type, width, height } = definition;
210
+ let icon;
211
+ if (type === IconTypes.Svg) {
212
+ icon = L.divIcon({
213
+ html: definition.html,
214
+ iconSize: [width, height],
215
+ className: '',
216
+ });
217
+ }
218
+ else if (type === IconTypes.UxIcon) {
219
+ icon = L.divIcon({
220
+ html: definition._generated_html,
221
+ iconSize: [width, height],
222
+ className: '',
223
+ });
224
+ }
225
+ else if (type === IconTypes.Url) {
226
+ icon = L.icon({
227
+ iconUrl: definition.url,
228
+ iconSize: [width, height],
229
+ className: '',
230
+ });
231
+ }
232
+ else {
233
+ throw new Error(`Unsupported icon type: ${type}.`);
234
+ }
235
+ element.setIcon(icon);
236
+ }
200
237
  doFitBoundsToMarkers() {
201
238
  if (this.markers.size === 0) {
202
239
  return;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symfony/ux-leaflet-map",
3
3
  "description": "Leaflet bridge for Symfony UX Map, integrate interactive maps in your Symfony applications",
4
4
  "license": "MIT",
5
- "version": "2.23.0",
5
+ "version": "2.25.0",
6
6
  "keywords": [
7
7
  "symfony-ux",
8
8
  "leaflet",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@hotwired/stimulus": "^3.0.0",
52
- "@symfony/ux-map": "2.23.0",
52
+ "@symfony/ux-map": "2.25.0",
53
53
  "@types/leaflet": "^1.9.12",
54
54
  "leaflet": "^1.9.4"
55
55
  }