@blaze-cms/plugin-google-maps-fe 0.124.0-alpha.7 → 0.124.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +280 -0
  2. package/lib/GoogleMaps/GoogleMaps.js +4 -3
  3. package/lib/GoogleMaps/GoogleMaps.js.map +1 -1
  4. package/lib/GoogleMaps/GoogleMapsFactory.js +3 -1
  5. package/lib/GoogleMaps/GoogleMapsFactory.js.map +1 -1
  6. package/lib/GoogleMaps/GoogleMapsHtml.js +32 -0
  7. package/lib/GoogleMaps/GoogleMapsHtml.js.map +1 -0
  8. package/lib/GoogleMaps/GoogleMapsRender.js +3 -1
  9. package/lib/GoogleMaps/GoogleMapsRender.js.map +1 -1
  10. package/lib/GoogleMaps/helpers/add-zoom-listener.js.map +1 -1
  11. package/lib/GoogleMaps/helpers/build-map-shapes.js +23 -18
  12. package/lib/GoogleMaps/helpers/build-map-shapes.js.map +1 -1
  13. package/lib/GoogleMaps/helpers/build-map-type-ids.js.map +1 -1
  14. package/lib/GoogleMaps/helpers/build-query.js.map +1 -1
  15. package/lib/GoogleMaps/helpers/build-shapes-configs.js.map +1 -1
  16. package/lib/GoogleMaps/helpers/get-center-coordinates.js.map +1 -1
  17. package/lib/GoogleMaps/helpers/get-image-ids.js.map +1 -1
  18. package/lib/GoogleMaps/helpers/get-path.js.map +1 -1
  19. package/lib/GoogleMaps/helpers/index.js.map +1 -1
  20. package/lib/GoogleMaps/helpers/set-map-options.js.map +1 -1
  21. package/lib/GoogleMaps/helpers/set-shapes.js +35 -11
  22. package/lib/GoogleMaps/helpers/set-shapes.js.map +1 -1
  23. package/lib/GoogleMaps/hooks/index.js.map +1 -1
  24. package/lib/GoogleMaps/hooks/use-get-entity-schemas.js.map +1 -1
  25. package/lib/GoogleMaps/hooks/use-get-images.js.map +1 -1
  26. package/lib/GoogleMaps/index.js.map +1 -1
  27. package/lib/GoogleMaps/queries.js.map +1 -1
  28. package/lib/constants.js +3 -1
  29. package/lib/constants.js.map +1 -1
  30. package/lib/index.js.map +1 -1
  31. package/lib-es/GoogleMaps/GoogleMaps.js +3 -3
  32. package/lib-es/GoogleMaps/GoogleMaps.js.map +1 -1
  33. package/lib-es/GoogleMaps/GoogleMapsFactory.js +2 -1
  34. package/lib-es/GoogleMaps/GoogleMapsFactory.js.map +1 -1
  35. package/lib-es/GoogleMaps/GoogleMapsHtml.js +18 -0
  36. package/lib-es/GoogleMaps/GoogleMapsHtml.js.map +1 -0
  37. package/lib-es/GoogleMaps/GoogleMapsRender.js +2 -1
  38. package/lib-es/GoogleMaps/GoogleMapsRender.js.map +1 -1
  39. package/lib-es/GoogleMaps/helpers/add-zoom-listener.js.map +1 -1
  40. package/lib-es/GoogleMaps/helpers/build-map-shapes.js +10 -20
  41. package/lib-es/GoogleMaps/helpers/build-map-shapes.js.map +1 -1
  42. package/lib-es/GoogleMaps/helpers/build-map-type-ids.js.map +1 -1
  43. package/lib-es/GoogleMaps/helpers/build-query.js.map +1 -1
  44. package/lib-es/GoogleMaps/helpers/build-shapes-configs.js.map +1 -1
  45. package/lib-es/GoogleMaps/helpers/get-center-coordinates.js.map +1 -1
  46. package/lib-es/GoogleMaps/helpers/get-image-ids.js.map +1 -1
  47. package/lib-es/GoogleMaps/helpers/get-path.js.map +1 -1
  48. package/lib-es/GoogleMaps/helpers/index.js.map +1 -1
  49. package/lib-es/GoogleMaps/helpers/set-map-options.js.map +1 -1
  50. package/lib-es/GoogleMaps/helpers/set-shapes.js +37 -11
  51. package/lib-es/GoogleMaps/helpers/set-shapes.js.map +1 -1
  52. package/lib-es/GoogleMaps/hooks/index.js.map +1 -1
  53. package/lib-es/GoogleMaps/hooks/use-get-entity-schemas.js.map +1 -1
  54. package/lib-es/GoogleMaps/hooks/use-get-images.js.map +1 -1
  55. package/lib-es/GoogleMaps/index.js.map +1 -1
  56. package/lib-es/GoogleMaps/queries.js.map +1 -1
  57. package/lib-es/constants.js +2 -1
  58. package/lib-es/constants.js.map +1 -1
  59. package/lib-es/index.js.map +1 -1
  60. package/package.json +4 -4
  61. package/src/GoogleMaps/GoogleMaps.js +2 -1
  62. package/src/GoogleMaps/GoogleMapsFactory.js +2 -1
  63. package/src/GoogleMaps/GoogleMapsHtml.js +16 -0
  64. package/src/GoogleMaps/GoogleMapsRender.js +2 -1
  65. package/src/GoogleMaps/helpers/build-map-shapes.js +1 -18
  66. package/src/GoogleMaps/helpers/set-shapes.js +43 -11
  67. package/src/constants.js +5 -1
@@ -3,13 +3,14 @@ import PropTypes from 'prop-types';
3
3
  import { useGetEntitySchemasAsObj } from '@blaze-cms/react-page-builder';
4
4
  import { buildShapesConfig } from './helpers';
5
5
  import GoogleMapsRender from './GoogleMapsRender';
6
+ import GoogleMapsHtml from './GoogleMapsHtml';
6
7
 
7
8
  const GoogleMapsFactory = ({ entityGroups, parent, ...otherProps }) => {
8
9
  const { data, loading, error } = useGetEntitySchemasAsObj(
9
10
  entityGroups.map(({ entity }) => entity)
10
11
  );
11
12
 
12
- if (loading) return '';
13
+ if (loading) return <GoogleMapsHtml />;
13
14
  if (error) return error.message;
14
15
 
15
16
  const shapeConfigs = buildShapesConfig(data, entityGroups, parent);
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ const GoogleMapsFactory = ({ mapRef }) => (
5
+ <div className={`google-maps ${!mapRef ? 'loading' : ''}`} ref={mapRef} />
6
+ );
7
+
8
+ GoogleMapsFactory.propTypes = {
9
+ mapRef: PropTypes.object
10
+ };
11
+
12
+ GoogleMapsFactory.defaultProps = {
13
+ mapRef: null
14
+ };
15
+
16
+ export default GoogleMapsFactory;
@@ -6,6 +6,7 @@ import { getAction } from '@blaze-cms/react-page-builder';
6
6
  import { useGetImages } from './hooks';
7
7
  import { buildQuery, getImageIds, getCenterCoordinates, buildMapShapes } from './helpers';
8
8
  import GoogleMaps from './GoogleMaps';
9
+ import GoogleMapsHtml from './GoogleMapsHtml';
9
10
 
10
11
  const defaultQuery = getAction('getPublishedPages', 'id');
11
12
 
@@ -22,7 +23,7 @@ const GoogleMapsRender = ({ shapeConfigs, entityGroups, id, ...otherProps }) =>
22
23
  loading: imagesLoading,
23
24
  error: imagesError
24
25
  } = useGetImages(imageIds);
25
- if (loading || imagesLoading) return '';
26
+ if (loading || imagesLoading) return <GoogleMapsHtml />;
26
27
  if (error || imagesError) return null;
27
28
 
28
29
  const centerCoordinates = getCenterCoordinates(mapShapes, otherProps);
@@ -22,16 +22,6 @@ const buildMapShapes = (shapesOptions, shapesData) => {
22
22
  shapesOptions.forEach(shape => {
23
23
  const { shapeKey, entityOptions, shapeOptions } = shape;
24
24
  const { dataSummaries, enableInfoPane } = entityOptions;
25
- const {
26
- imageId,
27
- label,
28
- markerHeight,
29
- markerWidth,
30
- maxZoom,
31
- minZoom,
32
- type,
33
- useAsCenter
34
- } = shapeOptions;
35
25
 
36
26
  const shapeData = Array.isArray(shapesData[shapeKey])
37
27
  ? shapesData[shapeKey]
@@ -44,19 +34,12 @@ const buildMapShapes = (shapesOptions, shapesData) => {
44
34
  const { latitude, longitude } = getLatLong(latProp, lonProp, shapeOptions, data);
45
35
 
46
36
  const formatedShape = {
37
+ ...shapeOptions,
47
38
  latitude,
48
39
  longitude,
49
40
  dataSummaries,
50
41
  enableInfoPane,
51
- imageId,
52
- label,
53
- markerHeight,
54
- markerWidth,
55
- maxZoom,
56
- minZoom,
57
- type,
58
42
  url,
59
- useAsCenter,
60
43
  shapeData: data
61
44
  };
62
45
 
@@ -17,7 +17,8 @@ import {
17
17
  COLOR,
18
18
  CLICK,
19
19
  HEADING_LARGE,
20
- LIST
20
+ LIST,
21
+ DEFAULT_CUSTOM_MARKER_PATH
21
22
  } from '../../constants';
22
23
 
23
24
  const shapesArray = [];
@@ -142,23 +143,54 @@ const infoWindowContent = async (imageData, dataSummaries, url, shapeData) => {
142
143
  );
143
144
  };
144
145
 
146
+ function getIcon(imageData, shape) {
147
+ const {
148
+ imageId,
149
+ markerWidth = 50,
150
+ markerHeight = 50,
151
+ strokeColor,
152
+ strokeOpacity,
153
+ strokeWeight,
154
+ fillColor,
155
+ fillOpacity,
156
+ svgPath
157
+ } = shape;
158
+ const iconUrl = getIconUrl(imageId, imageData);
159
+
160
+ const icon = iconUrl
161
+ ? {
162
+ url: iconUrl,
163
+ scaledSize: new window.google.maps.Size(markerWidth || 50, markerHeight || 50)
164
+ }
165
+ : null;
166
+
167
+ if (icon) return icon;
168
+
169
+ if (!svgPath && !fillColor && !strokeColor) return {}; // any can be true for custom marker
170
+
171
+ const svgMarker = {
172
+ path: svgPath || DEFAULT_CUSTOM_MARKER_PATH,
173
+ strokeColor,
174
+ strokeOpacity,
175
+ strokeWeight,
176
+ fillColor,
177
+ fillOpacity,
178
+ rotation: 0,
179
+ scale: 2
180
+ };
181
+ return svgMarker;
182
+ }
183
+
145
184
  const setMarker = (map, router, shape, imageData) => {
146
- const { label = '', markerWidth = 50, markerHeight = 50, latitude, longitude, imageId } = shape;
185
+ const { label = '', latitude, longitude } = shape;
147
186
 
148
187
  if (isPositionCorrect(latitude, longitude)) {
149
- const iconUrl = getIconUrl(imageId, imageData);
150
-
151
- const icon = iconUrl
152
- ? {
153
- url: iconUrl,
154
- scaledSize: new window.google.maps.Size(markerWidth || 50, markerHeight || 50)
155
- }
156
- : {};
188
+ const svgMarker = getIcon(imageData, shape);
157
189
 
158
190
  const marker = new window.google.maps.Marker({
159
191
  position: { lat: latitude, lng: longitude },
160
192
  map,
161
- icon,
193
+ icon: svgMarker,
162
194
  title: label || ''
163
195
  });
164
196
 
package/src/constants.js CHANGED
@@ -124,6 +124,9 @@ const IN_VIEW_CONFIG = {
124
124
 
125
125
  const DEFAULT_SELECT_VALUE = 'Default';
126
126
 
127
+ const DEFAULT_CUSTOM_MARKER_PATH =
128
+ 'M12,11.5A2.5,2.5 0 0,1 9.5,9A2.5,2.5 0 0,1 12,6.5A2.5,2.5 0 0,1 14.5,9A2.5,2.5 0 0,1 12,11.5M12,2A7,7 0 0,0 5,9C5,14.25 12,22 12,22C12,22 19,14.25 19,9A7,7 0 0,0 12,2Z';
129
+
127
130
  export {
128
131
  PLUGIN_NAME,
129
132
  GOOGLE_MAPS_SCRIPT,
@@ -158,5 +161,6 @@ export {
158
161
  DISABLE_POI_STYLES,
159
162
  DISABLE_BOUNDARIES_STYLES,
160
163
  DISABLE_LABELS_STYLES,
161
- DEFAULT_SELECT_VALUE
164
+ DEFAULT_SELECT_VALUE,
165
+ DEFAULT_CUSTOM_MARKER_PATH
162
166
  };