@lowdefy/blocks-google-maps 4.0.0-rc.4 → 4.0.0-rc.6

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/README.md CHANGED
@@ -7,6 +7,7 @@ To use this block, define a [@googlemaps/react-wrapper](https://www.npmjs.com/pa
7
7
  - [Map](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions)
8
8
  - [Heatmap](https://developers.google.com/maps/documentation/javascript/reference/visualization#HeatmapLayerOptions)
9
9
  - [Markers](https://developers.google.com/maps/documentation/javascript/reference/marker#MarkerOptions)
10
+ - [Marker Clusterers](https://developers.google.com/maps/documentation/javascript/marker-clustering)
10
11
 
11
12
  ### Properties
12
13
 
@@ -22,12 +23,39 @@ To use this block, define a [@googlemaps/react-wrapper](https://www.npmjs.com/pa
22
23
  - `markers: markerOptions[]`: A list of Markers with marker options, see more [Javascript API Markers](https://developers.google.com/maps/documentation/javascript/markers).
23
24
  - `position: { lat: number, lng: number }`: Position of marker on map.
24
25
  - `label: string`: Label displayed on marker.
26
+ - `markerClusterers: markerClustererOptions[]`: A list of MarkerClusterers with marker clusterer options.
27
+ - `markers: markerOptions[]`: A list of Markers with marker options, see more [Javascript API Markers](https://developers.google.com/maps/documentation/javascript/markers).
28
+ - `position: { lat: number, lng: number }`: Position of marker on map.
29
+ - `label: string`: Label displayed on marker.
30
+ - `options: markerClustererOptions`: All other [marker clusterer options](https://react-google-maps-api-docs.netlify.app/#markerclusterer).
25
31
  - `infoWindow: infoWindowOptions`: All infoWindow options, see [infoWindow options](https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindowOptions).
26
32
  - `position: { lat: number, lng: number }`: Position of infoWindow on map.
27
33
  - `visible: boolean`: When visible is true, blocks inside infoWindow content area will be rendered.
28
34
 
29
35
  ### Events
30
36
 
37
+ - `onBoundsChanged`: Trigger onBoundsChanged actions when the bounds of the map are changed, returns `_event`
38
+ object:
39
+ - `bounds`:
40
+ - `east`: latitudinal coordinate
41
+ - `north`: longitudinal coordinate
42
+ - `south`: longitudinal coordinate
43
+ - `west`: latitudinal coordinate
44
+ - `center`:
45
+ - `lat`: latitudinal coordinate
46
+ - `lng`: longitudinal coordinate
47
+ - `zoom`: zoom level
48
+ - `onCenterChanged`: Trigger onCenterChanged actions when the center of the map is changed, returns `_event`
49
+ object:
50
+ - `bounds`:
51
+ - `east`: latitudinal coordinate
52
+ - `north`: longitudinal coordinate
53
+ - `south`: longitudinal coordinate
54
+ - `west`: latitudinal coordinate
55
+ - `center`:
56
+ - `lat`: latitudinal coordinate
57
+ - `lng`: longitudinal coordinate
58
+ - `zoom`: zoom level
31
59
  - `onClick`: Trigger onClick actions when the map is clicked, returns `_event` object:
32
60
  - `domEvent`: event object
33
61
  - `latLng`:
@@ -36,7 +64,9 @@ To use this block, define a [@googlemaps/react-wrapper](https://www.npmjs.com/pa
36
64
  - `pixel`:
37
65
  - `x`: x position on map block
38
66
  - `y`: y position on map block
39
- - `onClickMarker`: Trigger onClickMarker actions when a marker is clicked, returns `_event` object:
67
+ - `onClusterClick`: Trigger onClusterClick actions when a cluster is clicked, returns `_event`
68
+ - `onMarkerClick`: Trigger onMarkerClick actions when a marker is clicked, returns `_event`
69
+ object:
40
70
  - `domEvent`: event object
41
71
  - `latLng`:
42
72
  - `lat`: latitudinal coordinate
@@ -44,13 +74,26 @@ To use this block, define a [@googlemaps/react-wrapper](https://www.npmjs.com/pa
44
74
  - `pixel`:
45
75
  - `x`: x position on map block
46
76
  - `y`: y position on map block
47
- - `onZoomChanged`: Trigger onZoomChanged actions when the zoom on the map is changed.
77
+ - `onZoomChanged`: Trigger onZoomChanged actions when the zoom on the map is changed. returns `_event`
78
+ object:
79
+ - `bounds`:
80
+ - `east`: latitudinal coordinate
81
+ - `north`: longitudinal coordinate
82
+ - `south`: longitudinal coordinate
83
+ - `west`: latitudinal coordinate
84
+ - `center`:
85
+ - `lat`: latitudinal coordinate
86
+ - `lng`: longitudinal coordinate
87
+ - `zoom`: zoom level
48
88
 
49
89
  ### Methods
50
90
 
51
91
  - `fitBounds`: Fit map to given bounds.
52
92
  - `bounds: { lat: number, lng: number } []`: A list of the coordinate positions of the boundary points.
53
93
  - `zoom: number`: Map zoom level.
94
+ - `getBounds`: Returns the bounds of the map.
95
+ - `getCenter`: Returns the center of the map.
96
+ - `getZoom`: Returns the zoom of the map.
54
97
 
55
98
  ## Examples
56
99
 
@@ -177,11 +220,11 @@ To use this block, define a [@googlemaps/react-wrapper](https://www.npmjs.com/pa
177
220
 
178
221
  ```yaml
179
222
  - id: google_maps_script_4
180
- type: GoogleMapsScript
181
- properties:
182
- apiKey:
183
- _build.env: GOOGLE_MAPS_API_KEY
184
- blocks:
223
+ type: GoogleMapsScript
224
+ properties:
225
+ apiKey:
226
+ _build.env: GOOGLE_MAPS_API_KEY
227
+ blocks:
185
228
  - id: google_maps_4
186
229
  type: GoogleMaps
187
230
  properties:
@@ -329,6 +372,126 @@ To use this block, define a [@googlemaps/react-wrapper](https://www.npmjs.com/pa
329
372
  lat: -35.344
330
373
  lng: 31.036
331
374
  ```
375
+
376
+ 7. Add a marker clusterer:
377
+
378
+ ```yaml
379
+ - id: google_maps_script_7
380
+ type: GoogleMapsScript
381
+ properties:
382
+ libraries:
383
+ - visualization
384
+ apiKey:
385
+ _build.env: GOOGLE_MAPS_API_KEY
386
+ blocks:
387
+ - id: google_maps_7
388
+ type: GoogleMaps
389
+ properties:
390
+ map:
391
+ disableDefaultUI: true
392
+ markerClusterers:
393
+ - markers:
394
+ - position:
395
+ lat: 34.091158
396
+ lng: -118.2795188
397
+ - position:
398
+ lat: 34.0771192
399
+ lng: -118.2587199
400
+ - position:
401
+ lat: 34.083527
402
+ lng: -118.370157
403
+ - position:
404
+ lat: 34.0951843
405
+ lng: -118.283107
406
+ - position:
407
+ lat: 34.1033401
408
+ lng: -118.2875469
409
+ - position:
410
+ lat: 34.035798
411
+ lng: -118.251288
412
+ - position:
413
+ lat: 34.0776068
414
+ lng: -118.2646526
415
+ - position:
416
+ lat: 34.0919263
417
+ lng: -118.2820544
418
+ - position:
419
+ lat: 34.0568525
420
+ lng: -118.3646369
421
+ - position:
422
+ lat: 34.0285781
423
+ lng: -118.4115541
424
+ - position:
425
+ lat: 34.017339
426
+ lng: -118.278469
427
+ - position:
428
+ lat: 34.0764288
429
+ lng: -118.3661624
430
+ - position:
431
+ lat: 33.9925942
432
+ lng: -118.4232475
433
+ - position:
434
+ lat: 34.0764345
435
+ lng: -118.3730332
436
+ - position:
437
+ lat: 34.093981
438
+ lng: -118.327638
439
+ - position:
440
+ lat: 34.056385
441
+ lng: -118.2508724
442
+ - position:
443
+ lat: 34.107701
444
+ lng: -118.2667943
445
+ - position:
446
+ lat: 34.0450139
447
+ lng: -118.2388682
448
+ - position:
449
+ lat: 34.1031997
450
+ lng: -118.2586152
451
+ - position:
452
+ lat: 34.0828183
453
+ lng: -118.3241586
454
+ options:
455
+ averageCenter: true
456
+ zoomOnClick: false
457
+ minimumClusterSize: 3
458
+ maxZoom: 13
459
+ ```
460
+
461
+ 8. Call method getZoom:
462
+
463
+ ```yaml
464
+ - id: google_maps_script_8
465
+ type: GoogleMapsScript
466
+ properties:
467
+ apiKey:
468
+ _build.env: GOOGLE_MAPS_API_KEY
469
+ blocks:
470
+ - id: google_maps_8
471
+ type: GoogleMaps
472
+ properties:
473
+ map:
474
+ options:
475
+ panControl: true
476
+ zoomControl: true
477
+ fullscreenControl: true
478
+ zoom: 14
479
+ center:
480
+ lat: -25.344
481
+ lng: 131.036
482
+ events:
483
+ onClick:
484
+ - id: get_zoom
485
+ type: CallMethod
486
+ params:
487
+ blockId: google_maps_8
488
+ method: getZoom
489
+ - id: get_zoom_result
490
+ type: SetState
491
+ params:
492
+ zoom:
493
+ _actions: get_zoom.response
494
+ ```
332
495
  <!--
333
496
  7. Trigger fitBounds using the onLoad event:
334
497
 
@@ -85,6 +85,70 @@
85
85
  }
86
86
  }
87
87
  },
88
+ "markerClusterers": {
89
+ "type": "array",
90
+ "description": "A list of Marker Clusterers with marker clusterer options.",
91
+ "items": {
92
+ "type": "object",
93
+ "properties": {
94
+ "markers": {
95
+ "type": "array",
96
+ "description": "A list of Markers with marker options.",
97
+ "items": {
98
+ "type": "object",
99
+ "properties": {
100
+ "position": {
101
+ "type": "object",
102
+ "properties": {
103
+ "lat": {
104
+ "type": "number",
105
+ "description": "Lateral coordinate."
106
+ },
107
+ "lng": {
108
+ "type": "number",
109
+ "description": "Longitudinal coordinate."
110
+ }
111
+ }
112
+ },
113
+ "label": {
114
+ "type": "string",
115
+ "description": "Label displayed on marker."
116
+ }
117
+ }
118
+ }
119
+ },
120
+ "options": {
121
+ "type": "object",
122
+ "properties": {
123
+ "averageCenter": {
124
+ "type": "boolean",
125
+ "description": "Whether the position of a cluster marker should be the average position of all markers in the cluster."
126
+ },
127
+ "gridSize": {
128
+ "type": "number",
129
+ "description": "The grid size of a cluster in pixels."
130
+ },
131
+ "maxZoom": {
132
+ "type": "number",
133
+ "description": "The maximum zoom level at which clustering is enabled."
134
+ },
135
+ "minimumClusterSize": {
136
+ "type": "number",
137
+ "description": "The minimum number of markers needed to form a cluster."
138
+ },
139
+ "styles": {
140
+ "type": "array",
141
+ "description": "Styles of the cluster markers to be used."
142
+ },
143
+ "zoomOnClick": {
144
+ "type": "boolean",
145
+ "description": "Whether to zoom the map when a cluster marker is clicked."
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }
151
+ },
88
152
  "infoWindow": {
89
153
  "type": "object",
90
154
  "description": "infoWindow options, see <a href='https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindowOptions'>more</a>.",
@@ -118,6 +182,14 @@
118
182
  "type": "object",
119
183
  "additionalProperties": false,
120
184
  "properties": {
185
+ "onBoundsChanged": {
186
+ "type": "array",
187
+ "description": "Trigger actions when the bounds of the map are changed."
188
+ },
189
+ "onCenterChanged": {
190
+ "type": "array",
191
+ "description": "Trigger actions when the center of the map is changed."
192
+ },
121
193
  "onClick": {
122
194
  "type": "array",
123
195
  "description": "Trigger actions when the map is clicked."
@@ -24,23 +24,5 @@
24
24
  }
25
25
  }
26
26
  }
27
- },
28
- "events": {
29
- "type": "object",
30
- "additionalProperties": false,
31
- "properties": {
32
- "onClick": {
33
- "type": "array",
34
- "description": "Trigger actions when the map is clicked."
35
- },
36
- "onMarkerClick": {
37
- "type": "array",
38
- "description": "Trigger actions when marker is clicked."
39
- },
40
- "onZoomChanged": {
41
- "type": "array",
42
- "description": "Trigger actions when the zoom on the map is changed."
43
- }
44
- }
45
27
  }
46
28
  }
@@ -27,7 +27,7 @@
27
27
  return _extends.apply(this, arguments);
28
28
  }
29
29
  import React, { useState, useEffect } from 'react';
30
- import { GoogleMap, Marker, InfoWindow } from '@react-google-maps/api';
30
+ import { GoogleMap, Marker, MarkerClusterer, InfoWindow } from '@react-google-maps/api';
31
31
  const STYLE_DEFAULTS = {
32
32
  width: '100%',
33
33
  height: '300px'
@@ -40,6 +40,7 @@ const MAP_DEFAULTS = {
40
40
  }
41
41
  };
42
42
  const MAP_PROPS = {
43
+ zoom: null,
43
44
  center: {
44
45
  lat: 0,
45
46
  lng: 0
@@ -62,6 +63,15 @@ const Map = ({ blockId , children , content , methods , properties })=>{
62
63
  map.setZoom(args.zoom);
63
64
  }
64
65
  });
66
+ methods.registerMethod('getBounds', ()=>{
67
+ return map.getBounds();
68
+ });
69
+ methods.registerMethod('getCenter', ()=>{
70
+ return map.getCenter();
71
+ });
72
+ methods.registerMethod('getZoom', ()=>{
73
+ return map.getZoom();
74
+ });
65
75
  }, [
66
76
  bounds,
67
77
  map
@@ -74,13 +84,22 @@ const Map = ({ blockId , children , content , methods , properties })=>{
74
84
  (properties.markers ?? []).map((marker)=>{
75
85
  bounds.extend(marker.position);
76
86
  });
77
- if (!properties.map?.center && !properties.map?.zoom) {
87
+ (properties.markerClusterers ?? []).map((markerClusterer)=>{
88
+ (markerClusterer.markers ?? []).map((marker)=>{
89
+ bounds.extend(marker.position);
90
+ });
91
+ });
92
+ if (!properties.map?.center && !properties.map?.zoom && MAP_PROPS.zoom === null) {
78
93
  map.fitBounds(bounds);
94
+ MAP_PROPS.zoom = map.getZoom();
79
95
  }
80
96
  }
81
97
  if (properties.map?.center && (properties.map.center?.lat !== MAP_PROPS.center.lat || properties.map.center?.lng !== MAP_PROPS.center.lng)) {
82
98
  MAP_PROPS.center = properties.map.center;
83
99
  }
100
+ if (properties.map?.zoom && properties.map.zoom !== MAP_PROPS.zoom) {
101
+ MAP_PROPS.zoom = properties.map.zoom;
102
+ }
84
103
  return /*#__PURE__*/ React.createElement(GoogleMap, _extends({}, properties.map, {
85
104
  id: blockId,
86
105
  mapContainerClassName: methods.makeCssClass([
@@ -88,7 +107,7 @@ const Map = ({ blockId , children , content , methods , properties })=>{
88
107
  properties.style
89
108
  ]),
90
109
  center: MAP_PROPS.center,
91
- zoom: properties.map?.zoom ?? MAP_DEFAULTS.zoom,
110
+ zoom: MAP_PROPS.zoom,
92
111
  onLoad: (newMap, event)=>{
93
112
  setMap(newMap);
94
113
  setBounds(new window.google.maps.LatLngBounds());
@@ -97,6 +116,26 @@ const Map = ({ blockId , children , content , methods , properties })=>{
97
116
  event
98
117
  });
99
118
  },
119
+ onBoundsChanged: ()=>{
120
+ methods.triggerEvent({
121
+ name: 'onBoundsChanged',
122
+ event: {
123
+ center: map?.getCenter(),
124
+ bounds: map?.getBounds(),
125
+ zoom: map?.getZoom()
126
+ }
127
+ });
128
+ },
129
+ onCenterChanged: ()=>{
130
+ methods.triggerEvent({
131
+ name: 'onCenterChanged',
132
+ event: {
133
+ center: map?.getCenter(),
134
+ bounds: map?.getBounds(),
135
+ zoom: map?.getZoom()
136
+ }
137
+ });
138
+ },
100
139
  onClick: (event)=>{
101
140
  methods.triggerEvent({
102
141
  name: 'onClick',
@@ -104,8 +143,16 @@ const Map = ({ blockId , children , content , methods , properties })=>{
104
143
  });
105
144
  },
106
145
  onZoomChanged: ()=>{
146
+ if (map) {
147
+ MAP_PROPS.zoom = map.getZoom();
148
+ }
107
149
  methods.triggerEvent({
108
- name: 'onZoomChanged'
150
+ name: 'onZoomChanged',
151
+ event: {
152
+ center: map?.getCenter(),
153
+ bounds: map?.getBounds(),
154
+ zoom: map?.getZoom()
155
+ }
109
156
  });
110
157
  }
111
158
  }), (properties.markers ?? []).map((marker, i)=>/*#__PURE__*/ React.createElement(Marker, _extends({}, marker, {
@@ -116,7 +163,25 @@ const Map = ({ blockId , children , content , methods , properties })=>{
116
163
  event
117
164
  });
118
165
  }
119
- }))), properties.infoWindow?.visible === true && /*#__PURE__*/ React.createElement(InfoWindow, _extends({}, properties.infoWindow, {
166
+ }))), (properties.markerClusterers ?? []).map((markerClusterer, i)=>/*#__PURE__*/ React.createElement(MarkerClusterer, _extends({
167
+ key: i
168
+ }, markerClusterer.options, {
169
+ onClick: (event)=>{
170
+ methods.triggerEvent({
171
+ name: 'onClusterClick',
172
+ event
173
+ });
174
+ }
175
+ }), (clusterer)=>markerClusterer?.markers.map((marker, i)=>/*#__PURE__*/ React.createElement(Marker, _extends({}, marker, {
176
+ key: i,
177
+ clusterer: clusterer,
178
+ onClick: (event)=>{
179
+ methods.triggerEvent({
180
+ name: 'onMarkerClick',
181
+ event
182
+ });
183
+ }
184
+ }))))), properties.infoWindow?.visible === true && /*#__PURE__*/ React.createElement(InfoWindow, _extends({}, properties.infoWindow, {
120
185
  onCloseClick: ()=>{
121
186
  methods.triggerEvent({
122
187
  name: 'onInfoWindowCloseClick'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/blocks-google-maps",
3
- "version": "4.0.0-rc.4",
3
+ "version": "4.0.0-rc.6",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Google Maps Blocks for Lowdefy.",
6
6
  "homepage": "https://lowdefy.com",
@@ -41,15 +41,15 @@
41
41
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
42
42
  },
43
43
  "dependencies": {
44
- "@lowdefy/block-utils": "4.0.0-rc.4",
44
+ "@lowdefy/block-utils": "4.0.0-rc.6",
45
45
  "@react-google-maps/api": "2.17.1",
46
46
  "react": "18.2.0",
47
47
  "react-dom": "18.2.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@emotion/jest": "11.10.5",
51
- "@lowdefy/block-dev": "4.0.0-rc.4",
52
- "@lowdefy/jest-yaml-transform": "4.0.0-rc.4",
51
+ "@lowdefy/block-dev": "4.0.0-rc.6",
52
+ "@lowdefy/jest-yaml-transform": "4.0.0-rc.6",
53
53
  "@swc/cli": "0.1.59",
54
54
  "@swc/core": "1.3.24",
55
55
  "@swc/jest": "0.2.24",
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "64ac69e424c881ee15a5333b75bd22156bd58ccb"
67
+ "gitHead": "8238145a9eb26c6f3dc48661ab6eca6e3aca4f83"
68
68
  }