@lowdefy/blocks-google-maps 4.0.0-alpha.17

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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,362 @@
1
+ # Lowdefy Google Maps Blocks
2
+
3
+ This is a Lowdefy blocks wrapper for this the [Google Maps API](https://developers.google.com/maps/documentation/javascript/overview).
4
+
5
+ To use this block, define a [@googlemaps/react-wrapper](https://www.npmjs.com/package/@googlemaps/react-wrapper). It currently implements:
6
+
7
+ - [Map](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions)
8
+ - [Heatmap](https://developers.google.com/maps/documentation/javascript/reference/visualization#HeatmapLayerOptions)
9
+ - [Markers](https://developers.google.com/maps/documentation/javascript/reference/marker#MarkerOptions)
10
+
11
+ ### Properties
12
+
13
+ - `apiKey: string`: Your Google Maps API key.
14
+ - `libraries: array`: List of [Google libraries](https://developers.google.com/maps/documentation/javascript/libraries).
15
+ - `map: mapOptions`: All [map options](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions).
16
+ - `center: { lat: number, lng: number }`: A coordinate position object by which to center the map.
17
+ - `zoom: number`: Map zoom level.
18
+ - `options: mapOptions`: All other [map options](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions).
19
+ - `heatmap: heatmapOptions`: Add a heatmap layer, see more [heatmap options](https://developers.google.com/maps/documentation/javascript/reference/visualization#HeatmapLayerOptions). This will automatically load the `visualization` library, which must be added to the list of libraries in the `libraries` property of the `GoogleMapsScript` block.
20
+ - `data: { lat: number, lng: number, weight: number } []`: A list of heatmap data points.
21
+ - `style: cssObject`: A style object applied to the map element.
22
+ - `markers: markerOptions[]`: A list of Markers with marker options, see more [Javascript API Markers](https://developers.google.com/maps/documentation/javascript/markers).
23
+ - `position: { lat: number, lng: number }`: Position of marker on map.
24
+ - `label: string`: Label displayed on marker.
25
+ - `infoWindow: infoWindowOptions`: All infoWindow options, see [infoWindow options](https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindowOptions).
26
+ - `position: { lat: number, lng: number }`: Position of infoWindow on map.
27
+ - `visible: boolean`: When visible is true, blocks inside infoWindow content area will be rendered.
28
+
29
+ ### Events
30
+
31
+ - `onClick`: Trigger onClick actions when the map is clicked, returns `_event` object:
32
+ - `domEvent`: event object
33
+ - `latLng`:
34
+ - `lat`: latitudinal coordinate
35
+ - `lng`: longitudinal coordinate
36
+ - `pixel`:
37
+ - `x`: x position on map block
38
+ - `y`: y position on map block
39
+ - `onClickMarker`: Trigger onClickMarker actions when a marker is clicked, returns `_event` object:
40
+ - `domEvent`: event object
41
+ - `latLng`:
42
+ - `lat`: latitudinal coordinate
43
+ - `lng`: longitudinal coordinate
44
+ - `pixel`:
45
+ - `x`: x position on map block
46
+ - `y`: y position on map block
47
+ - `onZoomChanged`: Trigger onZoomChanged actions when the zoom on the map is changed.
48
+
49
+ ### Methods
50
+
51
+ - `fitBounds`: Fit map to given bounds.
52
+ - `bounds: { lat: number, lng: number } []`: A list of the coordinate positions of the boundary points.
53
+ - `zoom: number`: Map zoom level.
54
+
55
+ ## Examples
56
+
57
+ 1. Add markers:
58
+
59
+ ```yaml
60
+ - id: google_maps_script_1
61
+ type: GoogleMapsScript
62
+ properties:
63
+ apiKey:
64
+ _build.env: GOOGLE_MAPS_API_KEY
65
+ blocks:
66
+ - id: google_maps_1
67
+ type: GoogleMaps
68
+ properties:
69
+ map:
70
+ options:
71
+ panControl: true
72
+ zoomControl: true
73
+ fullscreenControl: true
74
+ zoom: 14
75
+ center:
76
+ lat: -25.344
77
+ lng: 131.036
78
+ markers:
79
+ - position:
80
+ lat: -25.344
81
+ lng: 131.036
82
+ label: One
83
+ - position:
84
+ lat: -25.348
85
+ lng: 131.038
86
+ label: Two
87
+ ```
88
+
89
+ 2. Automatically bound map around marker positions when zoom and center map properties are left out:
90
+
91
+ ```yaml
92
+ - id: google_maps_script_2
93
+ type: GoogleMapsScript
94
+ properties:
95
+ apiKey:
96
+ _build.env: GOOGLE_MAPS_API_KEY
97
+ blocks:
98
+ - id: google_maps_2
99
+ type: GoogleMaps
100
+ properties:
101
+ map:
102
+ options:
103
+ panControl: true
104
+ zoomControl: true
105
+ fullscreenControl: true
106
+ markers:
107
+ - position:
108
+ lat: -25.344
109
+ lng: 131.036
110
+ label: One
111
+ - position:
112
+ lat: -25.348
113
+ lng: 131.038
114
+ label: Two
115
+ ```
116
+
117
+ 3. Add tooltips by making use of infoWindow:
118
+
119
+ ```yaml
120
+ - id: google_maps_script_3
121
+ type: GoogleMapsScript
122
+ properties:
123
+ apiKey:
124
+ _build.env: GOOGLE_MAPS_API_KEY
125
+ blocks:
126
+ - id: google_maps_3
127
+ type: GoogleMaps
128
+ properties:
129
+ map:
130
+ options:
131
+ panControl: true
132
+ zoomControl: true
133
+ fullscreenControl: true
134
+ zoom: 14
135
+ center:
136
+ lat: -25.344
137
+ lng: 131.036
138
+ markers:
139
+ - position:
140
+ lat: -25.344
141
+ lng: 131.036
142
+ label: One
143
+ - position:
144
+ lat: -25.348
145
+ lng: 131.038
146
+ label: Two
147
+ infoWindow:
148
+ position:
149
+ _state: position
150
+ visible:
151
+ _state: show_info
152
+ events:
153
+ onMarkerClick:
154
+ - id: set
155
+ type: SetState
156
+ params:
157
+ show_info:
158
+ _not:
159
+ _state: show_info
160
+ position:
161
+ _event: latLng
162
+ areas:
163
+ infoWindow:
164
+ blocks:
165
+ - id: content
166
+ type: Html
167
+ properties:
168
+ html:
169
+ _nunjucks:
170
+ template: |
171
+ <h1>Lat: {{ position.lat }} Lng: {{ position.lng }} </h1>
172
+ on:
173
+ _state: true
174
+ ```
175
+
176
+ 4. Add markers with onClick event:
177
+
178
+ ```yaml
179
+ - id: google_maps_script_4
180
+ type: GoogleMapsScript
181
+ properties:
182
+ apiKey:
183
+ _build.env: GOOGLE_MAPS_API_KEY
184
+ blocks:
185
+ - id: google_maps_4
186
+ type: GoogleMaps
187
+ properties:
188
+ map:
189
+ options:
190
+ panControl: true
191
+ zoomControl: true
192
+ fullscreenControl: true
193
+ center:
194
+ lat: -25.344
195
+ lng: 131.036
196
+ zoom: 5
197
+ markers:
198
+ _state: markers_list
199
+ events:
200
+ onClick:
201
+ - id: markers_list
202
+ type: SetState
203
+ params:
204
+ markers_list:
205
+ _array.concat:
206
+ - - position:
207
+ _event: latLng
208
+ label: Hi
209
+ - _if_none:
210
+ - _state: markers_list
211
+ - []
212
+ ```
213
+
214
+ 5. Add a heatmap:
215
+
216
+ ```yaml
217
+ - id: google_maps_script_5
218
+ type: GoogleMapsScript
219
+ properties:
220
+ libraries:
221
+ - visualization
222
+ apiKey:
223
+ _build.env: GOOGLE_MAPS_API_KEY
224
+ blocks:
225
+ - id: google_maps_5
226
+ type: GoogleMapsHeatmap
227
+ properties:
228
+ map:
229
+ disableDefaultUI: true
230
+ heatmap:
231
+ data:
232
+ - lat: 34.091158
233
+ lng: -118.2795188
234
+ weight: 1
235
+ - lat: 34.0771192
236
+ lng: -118.2587199
237
+ weight: 2
238
+ - lat: 34.083527
239
+ lng: -118.370157
240
+ weight: 1
241
+ - lat: 34.0951843
242
+ lng: -118.283107
243
+ weight: 2
244
+ - lat: 34.1033401
245
+ lng: -118.2875469
246
+ weight: 4
247
+ - lat: 34.035798
248
+ lng: -118.251288
249
+ weight: 2
250
+ - lat: 34.0776068
251
+ lng: -118.2646526
252
+ weight: 3
253
+ - lat: 34.0919263
254
+ lng: -118.2820544
255
+ weight: 3
256
+ - lat: 34.0568525
257
+ lng: -118.3646369
258
+ weight: 3
259
+ - lat: 34.0285781
260
+ lng: -118.4115541
261
+ weight: 0
262
+ - lat: 34.017339
263
+ lng: -118.278469
264
+ weight: 0
265
+ - lat: 34.0764288
266
+ lng: -118.3661624
267
+ weight: 4
268
+ - lat: 33.9925942
269
+ lng: -118.4232475
270
+ weight: 4
271
+ - lat: 34.0764345
272
+ lng: -118.3730332
273
+ weight: 3
274
+ - lat: 34.093981
275
+ lng: -118.327638
276
+ weight: 0
277
+ - lat: 34.056385
278
+ lng: -118.2508724
279
+ weight: 1
280
+ - lat: 34.107701
281
+ lng: -118.2667943
282
+ weight: 4
283
+ - lat: 34.0450139
284
+ lng: -118.2388682
285
+ weight: 4
286
+ - lat: 34.1031997
287
+ lng: -118.2586152
288
+ weight: 1
289
+ - lat: 34.0828183
290
+ lng: -118.3241586
291
+ weight: 1
292
+ options:
293
+ radius: 20
294
+ opacity: 1
295
+ ```
296
+
297
+ 6. Trigger fitBounds using a Button:
298
+
299
+ ```yaml
300
+ - id: google_maps_script_6
301
+ type: GoogleMapsScript
302
+ properties:
303
+ apiKey:
304
+ _build.env: GOOGLE_MAPS_API_KEY
305
+ blocks:
306
+ - id: btn
307
+ type: Button
308
+ events:
309
+ onClick:
310
+ - id: set_boundaries
311
+ type: CallMethod
312
+ params:
313
+ blockId: google_maps_6
314
+ method: fitBounds
315
+ args:
316
+ - bounds:
317
+ - lat: -25.344
318
+ lng: 131.036
319
+ - lat: -25.348
320
+ lng: 131.038
321
+ zoom: 10
322
+
323
+ - id: google_maps_6
324
+ type: GoogleMaps
325
+ properties:
326
+ map:
327
+ zoom: 5
328
+ center:
329
+ lat: -35.344
330
+ lng: 31.036
331
+ ```
332
+ <!--
333
+ 7. Trigger fitBounds using the onLoad event:
334
+
335
+ ```yaml
336
+ - id: google_maps_script_7
337
+ type: GoogleMapsScript
338
+ properties:
339
+ apiKey:
340
+ _build.env: GOOGLE_MAPS_API_KEY
341
+ blocks:
342
+ - id: google_maps_7
343
+ type: GoogleMaps
344
+ properties:
345
+ map:
346
+ zoom: 5
347
+ center:
348
+ lat: -35.344
349
+ lng: 31.036
350
+ events:
351
+ onLoad:
352
+ - id: set_boundaries
353
+ type: CallMethod
354
+ params:
355
+ blockId: google_maps_7
356
+ method: fitBounds
357
+ args:
358
+ - bounds:
359
+ - lat: -25.344
360
+ lng: 131.036
361
+ zoom: 10
362
+ ``` -->
@@ -0,0 +1,30 @@
1
+ /*
2
+ Copyright 2020-2022 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 Map from '../Map.js';
18
+ const GoogleMaps = ({ blockId , content , methods , properties })=>/*#__PURE__*/ React.createElement(Map, {
19
+ blockId: blockId,
20
+ content: content,
21
+ methods: methods,
22
+ properties: properties
23
+ });
24
+ GoogleMaps.defaultProps = blockDefaultProps;
25
+ GoogleMaps.meta = {
26
+ category: 'container',
27
+ icons: [],
28
+ styles: []
29
+ };
30
+ export default GoogleMaps;
@@ -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,63 @@
1
+ function _extends() {
2
+ _extends = Object.assign || function(target) {
3
+ for(var i = 1; i < arguments.length; i++){
4
+ var source = arguments[i];
5
+ for(var key in source){
6
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
7
+ target[key] = source[key];
8
+ }
9
+ }
10
+ }
11
+ return target;
12
+ };
13
+ return _extends.apply(this, arguments);
14
+ }
15
+ /* eslint-disable react/jsx-props-no-spreading */ /*
16
+ Copyright 2020-2022 Lowdefy, Inc
17
+
18
+ Licensed under the Apache License, Version 2.0 (the "License");
19
+ you may not use this file except in compliance with the License.
20
+ You may obtain a copy of the License at
21
+
22
+ http://www.apache.org/licenses/LICENSE-2.0
23
+
24
+ Unless required by applicable law or agreed to in writing, software
25
+ distributed under the License is distributed on an "AS IS" BASIS,
26
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
+ See the License for the specific language governing permissions and
28
+ limitations under the License.
29
+ */ import React from 'react';
30
+ import { blockDefaultProps } from '@lowdefy/block-utils';
31
+ import { HeatmapLayer } from '@react-google-maps/api';
32
+ import Map from '../Map.js';
33
+ function updateHeatmap(data) {
34
+ if (data.location) {
35
+ const latLng = new window.google.maps.LatLng(data.location);
36
+ latLng.weight = data.weight || 1;
37
+ return latLng;
38
+ }
39
+ return new window.google.maps.LatLng(data);
40
+ }
41
+ const GoogleMapsHeatmap = ({ blockId , content , methods , properties })=>/*#__PURE__*/ React.createElement(Map, {
42
+ blockId: blockId,
43
+ content: content,
44
+ methods: methods,
45
+ properties: properties
46
+ }, (map, bounds)=>map && bounds && properties.heatmap && /*#__PURE__*/ React.createElement(HeatmapLayer, _extends({}, properties.heatmap, {
47
+ data: properties.heatmap?.data && window.google && (properties.heatmap?.data || []).map((item)=>updateHeatmap(item)),
48
+ onLoad: ()=>{
49
+ if (properties.autoBounds !== false && bounds && map) {
50
+ (properties.heatmap?.data || []).forEach((item)=>{
51
+ bounds.extend(item);
52
+ });
53
+ map.fitBounds(bounds);
54
+ }
55
+ }
56
+ })));
57
+ GoogleMapsHeatmap.defaultProps = blockDefaultProps;
58
+ GoogleMapsHeatmap.meta = {
59
+ category: 'container',
60
+ icons: [],
61
+ styles: []
62
+ };
63
+ 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-2022 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,46 @@
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
+ "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
+ }
46
+ }
@@ -0,0 +1,123 @@
1
+ function _extends() {
2
+ _extends = Object.assign || function(target) {
3
+ for(var i = 1; i < arguments.length; i++){
4
+ var source = arguments[i];
5
+ for(var key in source){
6
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
7
+ target[key] = source[key];
8
+ }
9
+ }
10
+ }
11
+ return target;
12
+ };
13
+ return _extends.apply(this, arguments);
14
+ }
15
+ /* eslint-disable react/jsx-props-no-spreading */ /*
16
+ Copyright 2020-2022 Lowdefy, Inc
17
+
18
+ Licensed under the Apache License, Version 2.0 (the "License");
19
+ you may not use this file except in compliance with the License.
20
+ You may obtain a copy of the License at
21
+
22
+ http://www.apache.org/licenses/LICENSE-2.0
23
+
24
+ Unless required by applicable law or agreed to in writing, software
25
+ distributed under the License is distributed on an "AS IS" BASIS,
26
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
+ See the License for the specific language governing permissions and
28
+ limitations under the License.
29
+ */ import React, { useState, useEffect } from 'react';
30
+ import { GoogleMap, Marker, InfoWindow } from '@react-google-maps/api';
31
+ const STYLE_DEFAULTS = {
32
+ width: '100%',
33
+ height: '300px'
34
+ };
35
+ const MAP_DEFAULTS = {
36
+ zoom: 3,
37
+ center: {
38
+ lat: 0,
39
+ lng: 0
40
+ }
41
+ };
42
+ // Implements https://react-google-maps-api-docs.netlify.app/#googlemap
43
+ const Map = ({ blockId , children , content , methods , properties })=>{
44
+ const [map, setMap] = useState();
45
+ const [bounds, setBounds] = useState();
46
+ useEffect(()=>{
47
+ methods.registerMethod('fitBounds', (args)=>{
48
+ if (!bounds || !map) {
49
+ throw new Error('fitBounds can only be called once google maps has been mounted.');
50
+ }
51
+ (args?.bounds ?? []).map((position)=>{
52
+ bounds.extend(position);
53
+ });
54
+ map.fitBounds(bounds);
55
+ if (args.zoom) {
56
+ map.setZoom(args.zoom);
57
+ }
58
+ });
59
+ }, [
60
+ bounds,
61
+ map
62
+ ]);
63
+ // by default, fit infoWindow and markers to bounds
64
+ if (properties.autoBounds !== false && bounds && map) {
65
+ if (properties.infoWindow) {
66
+ bounds.extend(properties.infoWindow.position ?? MAP_DEFAULTS.center);
67
+ }
68
+ (properties.markers ?? []).map((marker)=>{
69
+ bounds.extend(marker.position);
70
+ });
71
+ if (!properties.map?.center && !properties.map?.zoom) {
72
+ map.fitBounds(bounds);
73
+ }
74
+ }
75
+ return /*#__PURE__*/ React.createElement(GoogleMap, _extends({}, properties.map, {
76
+ id: blockId,
77
+ mapContainerClassName: methods.makeCssClass([
78
+ STYLE_DEFAULTS,
79
+ properties.style
80
+ ]),
81
+ center: properties.map?.center ?? MAP_DEFAULTS.center,
82
+ zoom: properties.map?.zoom ?? MAP_DEFAULTS.zoom,
83
+ onLoad: (newMap, event)=>{
84
+ setMap(newMap);
85
+ setBounds(new window.google.maps.LatLngBounds());
86
+ methods.triggerEvent({
87
+ name: 'onLoad',
88
+ event
89
+ });
90
+ },
91
+ onClick: (event)=>{
92
+ methods.triggerEvent({
93
+ name: 'onClick',
94
+ event
95
+ });
96
+ },
97
+ onZoomChanged: ()=>{
98
+ methods.triggerEvent({
99
+ name: 'onZoomChanged'
100
+ });
101
+ }
102
+ }), (properties.markers ?? []).map((marker, i)=>/*#__PURE__*/ React.createElement(Marker, _extends({}, marker, {
103
+ key: i,
104
+ onClick: (event)=>{
105
+ methods.triggerEvent({
106
+ name: 'onMarkerClick',
107
+ event
108
+ });
109
+ }
110
+ }))), properties.infoWindow?.visible === true && /*#__PURE__*/ React.createElement(InfoWindow, _extends({}, properties.infoWindow, {
111
+ onCloseClick: ()=>{
112
+ methods.triggerEvent({
113
+ name: 'onInfoWindowCloseClick'
114
+ });
115
+ },
116
+ onPositionChanged: ()=>{
117
+ methods.triggerEvent({
118
+ name: 'onInfoWindowPositionChanged'
119
+ });
120
+ }
121
+ }), content.infoWindow && content.infoWindow()), children && children(map, bounds));
122
+ };
123
+ export default Map;
package/dist/blocks.js ADDED
@@ -0,0 +1,17 @@
1
+ /*
2
+ Copyright 2020-2022 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';
package/dist/types.js ADDED
@@ -0,0 +1,29 @@
1
+ /* eslint-disable import/namespace */ /*
2
+ Copyright 2020-2022 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 * as blocks from './blocks.js';
16
+ const icons = {};
17
+ const styles = {};
18
+ Object.keys(blocks).forEach((block)=>{
19
+ icons[block] = blocks[block].meta.icons || [];
20
+ styles[block] = blocks[block].meta.styles || [];
21
+ });
22
+ export default {
23
+ blocks: Object.keys(blocks),
24
+ icons,
25
+ styles: {
26
+ default: [],
27
+ ...styles
28
+ }
29
+ };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@lowdefy/blocks-google-maps",
3
+ "version": "4.0.0-alpha.17",
4
+ "license": "Apache-2.0",
5
+ "description": "Google Maps Blocks for Lowdefy.",
6
+ "homepage": "https://lowdefy.com",
7
+ "keywords": [
8
+ "lowdefy",
9
+ "lowdefy blocks",
10
+ "google",
11
+ "maps",
12
+ "lowdefy plugin"
13
+ ],
14
+ "bugs": {
15
+ "url": "https://github.com/lowdefy/lowdefy/issues"
16
+ },
17
+ "contributors": [
18
+ {
19
+ "name": "Gerrie van Wyk",
20
+ "url": "https://github.com/Gervwyk"
21
+ }
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/lowdefy/lowdefy.git"
26
+ },
27
+ "type": "module",
28
+ "exports": {
29
+ "./*": "./dist/*",
30
+ "./blocks": "./dist/blocks.js",
31
+ "./types": "./dist/types.js"
32
+ },
33
+ "files": [
34
+ "dist/*"
35
+ ],
36
+ "scripts": {
37
+ "build": "yarn swc",
38
+ "clean": "rm -rf dist",
39
+ "copyfiles": "copyfiles -u 1 \"./src/**/*\" dist -e \"./src/**/*.js\" -e \"./src/**/*.yaml\" -e \"./src/**/*.snap\"",
40
+ "prepare": "yarn build",
41
+ "swc": "swc src --out-dir dist --config-file ../../../../.swcrc --delete-dir-on-start && yarn copyfiles",
42
+ "test:watch": "jest --coverage --watch",
43
+ "test": "jest --coverage"
44
+ },
45
+ "dependencies": {
46
+ "@lowdefy/block-utils": "4.0.0-alpha.17",
47
+ "@react-google-maps/api": "2.12.0",
48
+ "react": "18.1.0",
49
+ "react-dom": "18.1.0"
50
+ },
51
+ "devDependencies": {
52
+ "@emotion/jest": "11.9.1",
53
+ "@lowdefy/block-dev": "4.0.0-alpha.17",
54
+ "@lowdefy/jest-yaml-transform": "4.0.0-alpha.17",
55
+ "@swc/cli": "0.1.57",
56
+ "@swc/core": "1.2.194",
57
+ "@swc/jest": "0.2.21",
58
+ "@testing-library/dom": "8.13.0",
59
+ "@testing-library/react": "13.3.0",
60
+ "@testing-library/user-event": "14.2.0",
61
+ "copyfiles": "2.4.1",
62
+ "jest": "28.1.0",
63
+ "jest-environment-jsdom": "28.1.0",
64
+ "jest-serializer-html": "7.1.0"
65
+ },
66
+ "publishConfig": {
67
+ "access": "public"
68
+ },
69
+ "gitHead": "9172974b2fe19c527d3f0ea66b8dbde827ac9c0e"
70
+ }