@lowdefy/blocks-google-maps 0.0.0-experimental-20231123101256

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.
@@ -0,0 +1,207 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "properties": {
7
+ "map": {
8
+ "type": "object",
9
+ "description": "Map settings object.",
10
+ "properties": {
11
+ "center": {
12
+ "type": "object",
13
+ "description": "A coordinate position object by which to center the map.",
14
+ "properties": {
15
+ "lat": {
16
+ "type": "number",
17
+ "description": "Lateral coordinate."
18
+ },
19
+ "lng": {
20
+ "type": "number",
21
+ "description": "Longitudinal coordinate."
22
+ }
23
+ }
24
+ },
25
+ "zoom": {
26
+ "type": "number",
27
+ "description": "Map zoom level."
28
+ },
29
+ "options": {
30
+ "type": "object",
31
+ "description": "Map options, see <a href='https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions'>more</a>."
32
+ }
33
+ }
34
+ },
35
+ "heatmap": {
36
+ "type": "object",
37
+ "description": "Add a heatmap layer, see more <a href='https://developers.google.com/maps/documentation/javascript/reference/visualization#HeatmapLayerOptions'>heatmap options</a>. This will automatically load the 'visualization' library.",
38
+ "properties": {
39
+ "data": {
40
+ "type": "array",
41
+ "description": "A list of heatmap data points.",
42
+ "items": {
43
+ "type": "object",
44
+ "properties": {
45
+ "lat": {
46
+ "type": "number",
47
+ "description": "Lateral coordinate."
48
+ },
49
+ "lng": {
50
+ "type": "number",
51
+ "description": "Longitudinal coordinate."
52
+ },
53
+ "weight": {
54
+ "type": "number",
55
+ "description": "Item weight on heatmap."
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ },
62
+ "markers": {
63
+ "type": "array",
64
+ "description": "A list of Markers with marker options.",
65
+ "items": {
66
+ "type": "object",
67
+ "properties": {
68
+ "position": {
69
+ "type": "object",
70
+ "properties": {
71
+ "lat": {
72
+ "type": "number",
73
+ "description": "Lateral coordinate."
74
+ },
75
+ "lng": {
76
+ "type": "number",
77
+ "description": "Longitudinal coordinate."
78
+ }
79
+ }
80
+ },
81
+ "label": {
82
+ "type": "string",
83
+ "description": "Label displayed on marker."
84
+ }
85
+ }
86
+ }
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
+ },
152
+ "infoWindow": {
153
+ "type": "object",
154
+ "description": "infoWindow options, see <a href='https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindowOptions'>more</a>.",
155
+ "properties": {
156
+ "visible": {
157
+ "type": "boolean",
158
+ "description": "When visible is true, blocks inside infoWindow content area will be rendered."
159
+ },
160
+ "position": {
161
+ "type": "object",
162
+ "properties": {
163
+ "lat": {
164
+ "type": "number",
165
+ "description": "Lateral coordinate."
166
+ },
167
+ "lng": {
168
+ "type": "number",
169
+ "description": "Longitudinal coordinate."
170
+ }
171
+ }
172
+ }
173
+ }
174
+ },
175
+ "style": {
176
+ "type": "object",
177
+ "description": "Custom map css properties to apply to map block."
178
+ }
179
+ }
180
+ },
181
+ "events": {
182
+ "type": "object",
183
+ "additionalProperties": false,
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
+ },
193
+ "onClick": {
194
+ "type": "array",
195
+ "description": "Trigger actions when the map is clicked."
196
+ },
197
+ "onMarkerClick": {
198
+ "type": "array",
199
+ "description": "Trigger actions when marker is clicked."
200
+ },
201
+ "onZoomChanged": {
202
+ "type": "array",
203
+ "description": "Trigger actions when the zoom on the map is changed."
204
+ }
205
+ }
206
+ }
207
+ }
@@ -0,0 +1,50 @@
1
+ /* eslint-disable react/jsx-props-no-spreading */ /*
2
+ Copyright 2020-2023 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import React from 'react';
16
+ import { blockDefaultProps } from '@lowdefy/block-utils';
17
+ import { HeatmapLayer } from '@react-google-maps/api';
18
+ import Map from '../Map.js';
19
+ function updateHeatmap(data) {
20
+ if (data.location) {
21
+ const latLng = new window.google.maps.LatLng(data.location);
22
+ latLng.weight = data.weight ?? 1;
23
+ return latLng;
24
+ }
25
+ return new window.google.maps.LatLng(data);
26
+ }
27
+ const GoogleMapsHeatmap = ({ blockId, content, methods, properties })=>/*#__PURE__*/ React.createElement(Map, {
28
+ blockId: blockId,
29
+ content: content,
30
+ methods: methods,
31
+ properties: properties
32
+ }, (map, bounds)=>map && bounds && properties.heatmap && /*#__PURE__*/ React.createElement(HeatmapLayer, {
33
+ ...properties.heatmap,
34
+ data: properties.heatmap?.data && window.google && (properties.heatmap?.data || []).map((item)=>updateHeatmap(item)),
35
+ onLoad: ()=>{
36
+ if (properties.autoBounds !== false && bounds && map) {
37
+ (properties.heatmap?.data || []).forEach((item)=>{
38
+ bounds.extend(item);
39
+ });
40
+ map.fitBounds(bounds);
41
+ }
42
+ }
43
+ }));
44
+ GoogleMapsHeatmap.defaultProps = blockDefaultProps;
45
+ GoogleMapsHeatmap.meta = {
46
+ category: 'container',
47
+ icons: [],
48
+ styles: []
49
+ };
50
+ export default GoogleMapsHeatmap;
@@ -0,0 +1,135 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "properties": {
7
+ "map": {
8
+ "type": "object",
9
+ "description": "Map settings object.",
10
+ "properties": {
11
+ "center": {
12
+ "type": "object",
13
+ "description": "A coordinate position object by which to center the map.",
14
+ "properties": {
15
+ "lat": {
16
+ "type": "number",
17
+ "description": "Lateral coordinate."
18
+ },
19
+ "lng": {
20
+ "type": "number",
21
+ "description": "Longitudinal coordinate."
22
+ }
23
+ }
24
+ },
25
+ "zoom": {
26
+ "type": "number",
27
+ "description": "Map zoom level."
28
+ },
29
+ "options": {
30
+ "type": "object",
31
+ "description": "Map options, see <a href='https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions'>more</a>."
32
+ }
33
+ }
34
+ },
35
+ "heatmap": {
36
+ "type": "object",
37
+ "description": "Add a heatmap layer, see more <a href='https://developers.google.com/maps/documentation/javascript/reference/visualization#HeatmapLayerOptions'>heatmap options</a>. This will automatically load the 'visualization' library.",
38
+ "properties": {
39
+ "data": {
40
+ "type": "array",
41
+ "description": "A list of heatmap data points.",
42
+ "items": {
43
+ "type": "object",
44
+ "properties": {
45
+ "lat": {
46
+ "type": "number",
47
+ "description": "Lateral coordinate."
48
+ },
49
+ "lng": {
50
+ "type": "number",
51
+ "description": "Longitudinal coordinate."
52
+ },
53
+ "weight": {
54
+ "type": "number",
55
+ "description": "Item weight on heatmap."
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ },
62
+ "markers": {
63
+ "type": "array",
64
+ "description": "A list of Markers with marker options.",
65
+ "items": {
66
+ "type": "object",
67
+ "properties": {
68
+ "position": {
69
+ "type": "object",
70
+ "properties": {
71
+ "lat": {
72
+ "type": "number",
73
+ "description": "Lateral coordinate."
74
+ },
75
+ "lng": {
76
+ "type": "number",
77
+ "description": "Longitudinal coordinate."
78
+ }
79
+ }
80
+ },
81
+ "label": {
82
+ "type": "string",
83
+ "description": "Label displayed on marker."
84
+ }
85
+ }
86
+ }
87
+ },
88
+ "infoWindow": {
89
+ "type": "object",
90
+ "description": "infoWindow options, see <a href='https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindowOptions'>more</a>.",
91
+ "properties": {
92
+ "visible": {
93
+ "type": "boolean",
94
+ "description": "When visible is true, blocks inside infoWindow content area will be rendered."
95
+ },
96
+ "position": {
97
+ "type": "object",
98
+ "properties": {
99
+ "lat": {
100
+ "type": "number",
101
+ "description": "Lateral coordinate."
102
+ },
103
+ "lng": {
104
+ "type": "number",
105
+ "description": "Longitudinal coordinate."
106
+ }
107
+ }
108
+ }
109
+ }
110
+ },
111
+ "style": {
112
+ "type": "object",
113
+ "description": "Custom map css properties to apply to map block."
114
+ }
115
+ }
116
+ },
117
+ "events": {
118
+ "type": "object",
119
+ "additionalProperties": false,
120
+ "properties": {
121
+ "onClick": {
122
+ "type": "array",
123
+ "description": "Trigger actions when the map is clicked."
124
+ },
125
+ "onMarkerClick": {
126
+ "type": "array",
127
+ "description": "Trigger actions when marker is clicked."
128
+ },
129
+ "onZoomChanged": {
130
+ "type": "array",
131
+ "description": "Trigger actions when the zoom on the map is changed."
132
+ }
133
+ }
134
+ }
135
+ }
@@ -0,0 +1,44 @@
1
+ /*
2
+ Copyright 2020-2023 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import React from 'react';
16
+ import { LoadScriptNext } from '@react-google-maps/api';
17
+ import { blockDefaultProps } from '@lowdefy/block-utils';
18
+ let GoogleMapsScript = class GoogleMapsScript extends React.Component {
19
+ render() {
20
+ const { blockId, properties, content } = this.props;
21
+ return /*#__PURE__*/ React.createElement(LoadScriptNext, {
22
+ id: blockId,
23
+ channel: properties.channel,
24
+ googleMapsApiKey: properties.apiKey,
25
+ language: properties.language,
26
+ libraries: this.libraries,
27
+ region: properties.region,
28
+ version: properties.version
29
+ }, content.content && content.content());
30
+ }
31
+ constructor(props){
32
+ super(props);
33
+ this.libraries = [
34
+ ...new Set(props.properties?.libraries || [])
35
+ ];
36
+ }
37
+ };
38
+ GoogleMapsScript.defaultProps = blockDefaultProps;
39
+ GoogleMapsScript.meta = {
40
+ category: 'container',
41
+ icons: [],
42
+ styles: []
43
+ };
44
+ export default GoogleMapsScript;
@@ -0,0 +1,28 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "properties": {
7
+ "apiKey": {
8
+ "type": "string",
9
+ "description": "Your Google Maps API key."
10
+ },
11
+ "libraries": {
12
+ "type": "array",
13
+ "description": "A list of Google libraries, see <a href='https://developers.google.com/maps/documentation/javascript/libraries'>more</a>.",
14
+ "items": {
15
+ "type": "string",
16
+ "enum": [
17
+ "drawing",
18
+ "geometry",
19
+ "journeySharing",
20
+ "localContext",
21
+ "places",
22
+ "visualization"
23
+ ]
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,187 @@
1
+ /* eslint-disable react/jsx-props-no-spreading */ /*
2
+ Copyright 2020-2023 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import React, { useState, useEffect } from 'react';
16
+ import { GoogleMap, Marker, MarkerClusterer, InfoWindow } from '@react-google-maps/api';
17
+ const STYLE_DEFAULTS = {
18
+ width: '100%',
19
+ height: '300px'
20
+ };
21
+ const MAP_DEFAULTS = {
22
+ zoom: 3,
23
+ center: {
24
+ lat: 0,
25
+ lng: 0
26
+ }
27
+ };
28
+ const MAP_PROPS = {
29
+ zoom: null,
30
+ center: {
31
+ lat: 0,
32
+ lng: 0
33
+ }
34
+ };
35
+ // Implements https://react-google-maps-api-docs.netlify.app/#googlemap
36
+ const Map = ({ blockId, children, content, methods, properties })=>{
37
+ const [map, setMap] = useState();
38
+ const [bounds, setBounds] = useState();
39
+ useEffect(()=>{
40
+ methods.registerMethod('fitBounds', (args)=>{
41
+ if (!bounds || !map) {
42
+ throw new Error('fitBounds can only be called once google maps has been mounted.');
43
+ }
44
+ (args?.bounds ?? []).forEach((position)=>{
45
+ bounds.extend(position);
46
+ });
47
+ map.fitBounds(bounds);
48
+ if (args.zoom) {
49
+ map.setZoom(args.zoom);
50
+ }
51
+ });
52
+ methods.registerMethod('getBounds', ()=>{
53
+ return map.getBounds();
54
+ });
55
+ methods.registerMethod('getCenter', ()=>{
56
+ return map.getCenter();
57
+ });
58
+ methods.registerMethod('getZoom', ()=>{
59
+ return map.getZoom();
60
+ });
61
+ }, [
62
+ bounds,
63
+ map
64
+ ]);
65
+ // by default, fit infoWindow and markers to bounds
66
+ if (properties.autoBounds !== false && bounds && map) {
67
+ if (properties.infoWindow) {
68
+ bounds.extend(properties.infoWindow.position ?? MAP_DEFAULTS.center);
69
+ }
70
+ (properties.markers ?? []).forEach((marker)=>{
71
+ bounds.extend(marker.position);
72
+ });
73
+ (properties.markerClusterers ?? []).forEach((markerClusterer)=>{
74
+ (markerClusterer.markers ?? []).forEach((marker)=>{
75
+ bounds.extend(marker.position);
76
+ });
77
+ });
78
+ if (!properties.map?.center && !properties.map?.zoom && MAP_PROPS.zoom === null) {
79
+ map.fitBounds(bounds);
80
+ MAP_PROPS.zoom = map.getZoom();
81
+ }
82
+ }
83
+ if (properties.map?.center && (properties.map.center?.lat !== MAP_PROPS.center.lat || properties.map.center?.lng !== MAP_PROPS.center.lng)) {
84
+ MAP_PROPS.center = properties.map.center;
85
+ }
86
+ if (properties.map?.zoom && properties.map.zoom !== MAP_PROPS.zoom) {
87
+ MAP_PROPS.zoom = properties.map.zoom;
88
+ }
89
+ return /*#__PURE__*/ React.createElement(GoogleMap, {
90
+ ...properties.map,
91
+ id: blockId,
92
+ mapContainerClassName: methods.makeCssClass([
93
+ STYLE_DEFAULTS,
94
+ properties.style
95
+ ]),
96
+ center: MAP_PROPS.center,
97
+ zoom: MAP_PROPS.zoom,
98
+ onLoad: (newMap, event)=>{
99
+ setMap(newMap);
100
+ setBounds(new window.google.maps.LatLngBounds());
101
+ methods.triggerEvent({
102
+ name: 'onLoad',
103
+ event
104
+ });
105
+ },
106
+ onBoundsChanged: ()=>{
107
+ methods.triggerEvent({
108
+ name: 'onBoundsChanged',
109
+ event: {
110
+ center: map?.getCenter(),
111
+ bounds: map?.getBounds(),
112
+ zoom: map?.getZoom()
113
+ }
114
+ });
115
+ },
116
+ onCenterChanged: ()=>{
117
+ methods.triggerEvent({
118
+ name: 'onCenterChanged',
119
+ event: {
120
+ center: map?.getCenter(),
121
+ bounds: map?.getBounds(),
122
+ zoom: map?.getZoom()
123
+ }
124
+ });
125
+ },
126
+ onClick: (event)=>{
127
+ methods.triggerEvent({
128
+ name: 'onClick',
129
+ event
130
+ });
131
+ },
132
+ onZoomChanged: ()=>{
133
+ if (map) {
134
+ MAP_PROPS.zoom = map.getZoom();
135
+ }
136
+ methods.triggerEvent({
137
+ name: 'onZoomChanged',
138
+ event: {
139
+ center: map?.getCenter(),
140
+ bounds: map?.getBounds(),
141
+ zoom: map?.getZoom()
142
+ }
143
+ });
144
+ }
145
+ }, (properties.markers ?? []).map((marker, i)=>/*#__PURE__*/ React.createElement(Marker, {
146
+ ...marker,
147
+ key: i,
148
+ onClick: (event)=>{
149
+ methods.triggerEvent({
150
+ name: 'onMarkerClick',
151
+ event
152
+ });
153
+ }
154
+ })), (properties.markerClusterers ?? []).map((markerClusterer, i)=>/*#__PURE__*/ React.createElement(MarkerClusterer, {
155
+ key: i,
156
+ ...markerClusterer.options,
157
+ onClick: (event)=>{
158
+ methods.triggerEvent({
159
+ name: 'onClusterClick',
160
+ event
161
+ });
162
+ }
163
+ }, (clusterer)=>markerClusterer?.markers.map((marker, i)=>/*#__PURE__*/ React.createElement(Marker, {
164
+ ...marker,
165
+ key: i,
166
+ clusterer: clusterer,
167
+ onClick: (event)=>{
168
+ methods.triggerEvent({
169
+ name: 'onMarkerClick',
170
+ event
171
+ });
172
+ }
173
+ })))), properties.infoWindow?.visible === true && /*#__PURE__*/ React.createElement(InfoWindow, {
174
+ ...properties.infoWindow,
175
+ onCloseClick: ()=>{
176
+ methods.triggerEvent({
177
+ name: 'onInfoWindowCloseClick'
178
+ });
179
+ },
180
+ onPositionChanged: ()=>{
181
+ methods.triggerEvent({
182
+ name: 'onInfoWindowPositionChanged'
183
+ });
184
+ }
185
+ }, content.infoWindow && content.infoWindow()), children?.(map, bounds));
186
+ };
187
+ export default Map;
package/dist/blocks.js ADDED
@@ -0,0 +1,17 @@
1
+ /*
2
+ Copyright 2020-2023 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export { default as GoogleMaps } from './blocks/GoogleMaps/GoogleMaps.js';
16
+ export { default as GoogleMapsHeatmap } from './blocks/GoogleMapsHeatmap/GoogleMapsHeatmap.js';
17
+ export { default as GoogleMapsScript } from './blocks/GoogleMapsScript/GoogleMapsScript.js';