@symfony/ux-google-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-google-map
2
+
3
+ JavaScript assets of the [symfony/ux-google-map](https://packagist.org/packages/symfony/ux-google-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-google-map](https://packagist.org/packages/symfony/ux-google-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-google-map](https://packagist.org/packages/symfony/ux-google-map) PHP package version:
12
+ ```shell
13
+ composer require symfony/ux-google-map:2.23.0
14
+ npm add @symfony/ux-google-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,10 +1,11 @@
1
1
  import type { LoaderOptions } from '@googlemaps/js-api-loader';
2
2
  import AbstractMapController from '@symfony/ux-map';
3
- import type { InfoWindowWithoutPositionDefinition, MarkerDefinition, Point, PolygonDefinition, PolylineDefinition } from '@symfony/ux-map';
3
+ import type { Icon, InfoWindowWithoutPositionDefinition, MarkerDefinition, Point, PolygonDefinition, PolylineDefinition } from '@symfony/ux-map';
4
4
  type MapOptions = Pick<google.maps.MapOptions, 'mapId' | 'gestureHandling' | 'backgroundColor' | 'disableDoubleClickZoom' | 'zoomControl' | 'zoomControlOptions' | 'mapTypeControl' | 'mapTypeControlOptions' | 'streetViewControl' | 'streetViewControlOptions' | 'fullscreenControl' | 'fullscreenControlOptions'>;
5
5
  export default class extends AbstractMapController<MapOptions, google.maps.Map, google.maps.marker.AdvancedMarkerElementOptions, google.maps.marker.AdvancedMarkerElement, google.maps.InfoWindowOptions, google.maps.InfoWindow, google.maps.PolygonOptions, google.maps.Polygon, google.maps.PolylineOptions, google.maps.Polyline> {
6
6
  providerOptionsValue: Pick<LoaderOptions, 'apiKey' | 'id' | 'language' | 'region' | 'nonce' | 'retries' | 'url' | 'version' | 'libraries'>;
7
7
  map: google.maps.Map;
8
+ parser: DOMParser;
8
9
  connect(): Promise<void>;
9
10
  centerValueChanged(): void;
10
11
  zoomValueChanged(): void;
@@ -32,6 +33,10 @@ export default class extends AbstractMapController<MapOptions, google.maps.Map,
32
33
  }): google.maps.InfoWindow;
33
34
  protected doFitBoundsToMarkers(): void;
34
35
  private createTextOrElement;
36
+ protected doCreateIcon({ definition, element, }: {
37
+ definition: Icon;
38
+ element: google.maps.marker.AdvancedMarkerElement;
39
+ }): void;
35
40
  private closeInfoWindowsExcept;
36
41
  }
37
42
  export {};
@@ -1,6 +1,11 @@
1
1
  import { Loader } from '@googlemaps/js-api-loader';
2
2
  import { Controller } from '@hotwired/stimulus';
3
3
 
4
+ const IconTypes = {
5
+ Url: 'url',
6
+ Svg: 'svg',
7
+ UxIcon: 'ux-icon',
8
+ };
4
9
  class default_1 extends Controller {
5
10
  constructor() {
6
11
  super(...arguments);
@@ -104,6 +109,7 @@ default_1.values = {
104
109
  };
105
110
 
106
111
  let _google;
112
+ const parser = new DOMParser();
107
113
  class map_controller extends default_1 {
108
114
  async connect() {
109
115
  if (!_google) {
@@ -126,6 +132,7 @@ class map_controller extends default_1 {
126
132
  });
127
133
  }
128
134
  super.connect();
135
+ this.parser = new DOMParser();
129
136
  }
130
137
  centerValueChanged() {
131
138
  if (this.map && this.hasCenterValue && this.centerValue) {
@@ -158,7 +165,7 @@ class map_controller extends default_1 {
158
165
  });
159
166
  }
160
167
  doCreateMarker({ definition, }) {
161
- const { '@id': _id, position, title, infoWindow, extra, rawOptions = {}, ...otherOptions } = definition;
168
+ const { '@id': _id, position, title, infoWindow, icon, extra, rawOptions = {}, ...otherOptions } = definition;
162
169
  const marker = new _google.maps.marker.AdvancedMarkerElement({
163
170
  position,
164
171
  title,
@@ -169,6 +176,9 @@ class map_controller extends default_1 {
169
176
  if (infoWindow) {
170
177
  this.createInfoWindow({ definition: infoWindow, element: marker });
171
178
  }
179
+ if (icon) {
180
+ this.doCreateIcon({ definition: icon, element: marker });
181
+ }
172
182
  return marker;
173
183
  }
174
184
  doRemoveMarker(marker) {
@@ -272,6 +282,25 @@ class map_controller extends default_1 {
272
282
  }
273
283
  return content;
274
284
  }
285
+ doCreateIcon({ definition, element, }) {
286
+ const { type, width, height } = definition;
287
+ if (type === IconTypes.Svg) {
288
+ element.content = parser.parseFromString(definition.html, 'image/svg+xml').documentElement;
289
+ }
290
+ else if (type === IconTypes.UxIcon) {
291
+ element.content = parser.parseFromString(definition._generated_html, 'image/svg+xml').documentElement;
292
+ }
293
+ else if (type === IconTypes.Url) {
294
+ const icon = document.createElement('img');
295
+ icon.width = width;
296
+ icon.height = height;
297
+ icon.src = definition.url;
298
+ element.content = icon;
299
+ }
300
+ else {
301
+ throw new Error(`Unsupported icon type: ${type}.`);
302
+ }
303
+ }
275
304
  closeInfoWindowsExcept(infoWindow) {
276
305
  this.infoWindows.forEach((otherInfoWindow) => {
277
306
  if (otherInfoWindow !== infoWindow) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symfony/ux-google-map",
3
3
  "description": "GoogleMaps 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
  "google-maps",
@@ -50,7 +50,7 @@
50
50
  "devDependencies": {
51
51
  "@googlemaps/js-api-loader": "^1.16.6",
52
52
  "@hotwired/stimulus": "^3.0.0",
53
- "@symfony/ux-map": "2.23.0",
53
+ "@symfony/ux-map": "2.25.0",
54
54
  "@types/google.maps": "^3.55.9"
55
55
  }
56
56
  }