@micromag/element-map 0.3.311 → 0.3.318

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.
@@ -1,2 +1,2 @@
1
- .micromag-element-map-container{position:absolute;top:0;left:0;margin:0;padding:0}.micromag-element-map-container,.micromag-element-map-container .micromag-element-map-map{width:100%;height:100%}.micromag-element-map-container.micromag-element-map-preventScroll .micromag-element-map-map div{cursor:default}
2
- .micromag-element-map-container{position:absolute;top:0;left:0;width:100%;height:100%;margin:0;padding:0}
1
+ .micromag-element-map-container{height:100%;left:0;margin:0;padding:0;position:absolute;top:0;width:100%}.micromag-element-map-container .micromag-element-map-map{height:100%;width:100%}.micromag-element-map-container.micromag-element-map-preventScroll .micromag-element-map-map div{cursor:default}
2
+ .micromag-element-map-container{height:100%;left:0;margin:0;padding:0;position:absolute;top:0;width:100%}
package/es/index.js CHANGED
@@ -193,52 +193,46 @@ var eventsMapping = {
193
193
  };
194
194
  function useGoogleMap(_ref) {
195
195
  var zoom = _ref.zoom,
196
- _ref$maxZoom = _ref.maxZoom,
197
- maxZoom = _ref$maxZoom === void 0 ? null : _ref$maxZoom,
198
- _ref$center = _ref.center,
199
- center = _ref$center === void 0 ? null : _ref$center,
200
- _ref$withoutStyle = _ref.withoutStyle,
201
- withoutStyle = _ref$withoutStyle === void 0 ? false : _ref$withoutStyle,
202
- _ref$fitBounds = _ref.fitBounds,
203
- fitBounds = _ref$fitBounds === void 0 ? false : _ref$fitBounds,
204
- _ref$bounds = _ref.bounds,
205
- bounds = _ref$bounds === void 0 ? null : _ref$bounds,
206
- events = _ref.events,
207
- _ref$draggable = _ref.draggable,
208
- draggable = _ref$draggable === void 0 ? false : _ref$draggable,
209
- zoomControl = _ref.zoomControl,
210
- mapTypeControl = _ref.mapTypeControl,
211
- scaleControl = _ref.scaleControl,
212
- streetViewControl = _ref.streetViewControl,
213
- rotateControl = _ref.rotateControl,
214
- fullscreenControl = _ref.fullscreenControl;
196
+ _ref$maxZoom = _ref.maxZoom,
197
+ maxZoom = _ref$maxZoom === void 0 ? null : _ref$maxZoom,
198
+ _ref$center = _ref.center,
199
+ center = _ref$center === void 0 ? null : _ref$center,
200
+ _ref$withoutStyle = _ref.withoutStyle,
201
+ withoutStyle = _ref$withoutStyle === void 0 ? false : _ref$withoutStyle,
202
+ _ref$fitBounds = _ref.fitBounds,
203
+ fitBounds = _ref$fitBounds === void 0 ? false : _ref$fitBounds,
204
+ _ref$bounds = _ref.bounds,
205
+ bounds = _ref$bounds === void 0 ? null : _ref$bounds,
206
+ events = _ref.events,
207
+ _ref$draggable = _ref.draggable,
208
+ draggable = _ref$draggable === void 0 ? false : _ref$draggable,
209
+ zoomControl = _ref.zoomControl,
210
+ mapTypeControl = _ref.mapTypeControl,
211
+ scaleControl = _ref.scaleControl,
212
+ streetViewControl = _ref.streetViewControl,
213
+ rotateControl = _ref.rotateControl,
214
+ fullscreenControl = _ref.fullscreenControl;
215
215
  var client = useGoogleMapsClient();
216
-
217
216
  var _useState = useState(false),
218
- _useState2 = _slicedToArray(_useState, 2),
219
- ready = _useState2[0],
220
- setReady = _useState2[1];
221
-
217
+ _useState2 = _slicedToArray(_useState, 2),
218
+ ready = _useState2[0],
219
+ setReady = _useState2[1];
222
220
  var containerRef = useRef(null);
223
221
  var mapRef = useRef(null);
224
-
225
222
  var _useDimensionObserver = useDimensionObserver(),
226
- resizeRef = _useDimensionObserver.ref,
227
- _useDimensionObserver2 = _useDimensionObserver.width,
228
- width = _useDimensionObserver2 === void 0 ? null : _useDimensionObserver2,
229
- _useDimensionObserver3 = _useDimensionObserver.height,
230
- height = _useDimensionObserver3 === void 0 ? null : _useDimensionObserver3;
231
-
223
+ resizeRef = _useDimensionObserver.ref,
224
+ _useDimensionObserver2 = _useDimensionObserver.width,
225
+ width = _useDimensionObserver2 === void 0 ? null : _useDimensionObserver2,
226
+ _useDimensionObserver3 = _useDimensionObserver.height,
227
+ height = _useDimensionObserver3 === void 0 ? null : _useDimensionObserver3;
232
228
  useEffect(function () {
233
229
  var map = mapRef.current;
234
-
235
230
  if (map !== null && center !== null) {
236
231
  var _ref2 = center || {},
237
- _ref2$lat = _ref2.lat,
238
- lat = _ref2$lat === void 0 ? null : _ref2$lat,
239
- _ref2$lng = _ref2.lng,
240
- lng = _ref2$lng === void 0 ? null : _ref2$lng;
241
-
232
+ _ref2$lat = _ref2.lat,
233
+ lat = _ref2$lat === void 0 ? null : _ref2$lat,
234
+ _ref2$lng = _ref2.lng,
235
+ lng = _ref2$lng === void 0 ? null : _ref2$lng;
242
236
  map.panTo({
243
237
  lat: lat || 0,
244
238
  lng: lng || 0
@@ -247,7 +241,6 @@ function useGoogleMap(_ref) {
247
241
  }, [center]);
248
242
  useEffect(function () {
249
243
  var map = mapRef.current;
250
-
251
244
  if (map !== null && zoom !== null) {
252
245
  map.setZoom(Math.min(maxZoom, zoom));
253
246
  }
@@ -256,25 +249,20 @@ function useGoogleMap(_ref) {
256
249
  if (newBounds === null || newBounds.equals(map.getBounds())) {
257
250
  return;
258
251
  }
259
-
260
252
  map.fitBounds(newBounds);
261
-
262
253
  if (map.getZoom() > maxZoom) {
263
254
  map.setZoom(maxZoom);
264
255
  }
265
-
266
256
  map.panToBounds(newBounds);
267
257
  }, [maxZoom]);
268
258
  useEffect(function () {
269
259
  var map = mapRef.current;
270
-
271
260
  if (map !== null && fitBounds) {
272
261
  updateBounds(map, bounds);
273
262
  }
274
263
  }, [updateBounds, bounds, fitBounds, width, height]);
275
264
  useEffect(function () {
276
265
  var map = mapRef.current;
277
-
278
266
  if (ready && map !== null) {
279
267
  map.setOptions({
280
268
  draggable: draggable,
@@ -288,7 +276,6 @@ function useGoogleMap(_ref) {
288
276
  if (client === null || containerRef.current === null || mapRef.current !== null) {
289
277
  return function () {};
290
278
  }
291
-
292
279
  var map = new client.maps.Map(containerRef.current, {
293
280
  zoom: zoom,
294
281
  center: center,
@@ -300,13 +287,12 @@ function useGoogleMap(_ref) {
300
287
  rotateControl: rotateControl,
301
288
  fullscreenControl: fullscreenControl
302
289
  });
303
-
304
290
  if (fitBounds) {
305
291
  updateBounds(map, bounds);
306
292
  }
293
+ mapRef.current = map;
307
294
 
308
- mapRef.current = map; // @TODO unbind events
309
-
295
+ // @TODO unbind events
310
296
  if (events !== null) {
311
297
  Object.keys(events).forEach(function (eventName) {
312
298
  if (events[eventName] !== null) {
@@ -316,7 +302,6 @@ function useGoogleMap(_ref) {
316
302
  }
317
303
  });
318
304
  }
319
-
320
305
  setReady(true);
321
306
  return function () {};
322
307
  }, [client, setReady]);
@@ -398,47 +383,43 @@ var defaultProps$2 = {
398
383
  children: null,
399
384
  focusable: true
400
385
  };
401
-
402
386
  var Map$1 = function Map(_ref) {
403
387
  var _ref2;
404
-
405
388
  var center = _ref.center,
406
- zoom = _ref.zoom,
407
- maxZoom = _ref.maxZoom,
408
- bounds = _ref.bounds,
409
- draggable = _ref.draggable,
410
- withoutStyle = _ref.withoutStyle,
411
- events = _ref.events,
412
- fitBounds = _ref.fitBounds,
413
- zoomControl = _ref.zoomControl,
414
- mapTypeControl = _ref.mapTypeControl,
415
- scaleControl = _ref.scaleControl,
416
- streetViewControl = _ref.streetViewControl,
417
- rotateControl = _ref.rotateControl,
418
- fullscreenControl = _ref.fullscreenControl,
419
- className = _ref.className,
420
- children = _ref.children,
421
- focusable = _ref.focusable;
422
-
389
+ zoom = _ref.zoom,
390
+ maxZoom = _ref.maxZoom,
391
+ bounds = _ref.bounds,
392
+ draggable = _ref.draggable,
393
+ withoutStyle = _ref.withoutStyle,
394
+ events = _ref.events,
395
+ fitBounds = _ref.fitBounds,
396
+ zoomControl = _ref.zoomControl,
397
+ mapTypeControl = _ref.mapTypeControl,
398
+ scaleControl = _ref.scaleControl,
399
+ streetViewControl = _ref.streetViewControl,
400
+ rotateControl = _ref.rotateControl,
401
+ fullscreenControl = _ref.fullscreenControl,
402
+ className = _ref.className,
403
+ children = _ref.children,
404
+ focusable = _ref.focusable;
423
405
  var _useGoogleMap = useGoogleMap({
424
- zoom: zoom,
425
- maxZoom: maxZoom,
426
- bounds: bounds,
427
- draggable: draggable,
428
- fitBounds: fitBounds,
429
- center: center,
430
- events: events,
431
- withoutStyle: withoutStyle,
432
- zoomControl: zoomControl,
433
- mapTypeControl: mapTypeControl,
434
- scaleControl: scaleControl,
435
- streetViewControl: streetViewControl,
436
- rotateControl: rotateControl,
437
- fullscreenControl: fullscreenControl
438
- }),
439
- map = _useGoogleMap.map,
440
- mapRef = _useGoogleMap.ref;
441
-
406
+ zoom: zoom,
407
+ maxZoom: maxZoom,
408
+ bounds: bounds,
409
+ draggable: draggable,
410
+ fitBounds: fitBounds,
411
+ center: center,
412
+ events: events,
413
+ withoutStyle: withoutStyle,
414
+ zoomControl: zoomControl,
415
+ mapTypeControl: mapTypeControl,
416
+ scaleControl: scaleControl,
417
+ streetViewControl: streetViewControl,
418
+ rotateControl: rotateControl,
419
+ fullscreenControl: fullscreenControl
420
+ }),
421
+ map = _useGoogleMap.map,
422
+ mapRef = _useGoogleMap.ref;
442
423
  return /*#__PURE__*/React.createElement("div", Object.assign({
443
424
  className: classNames([styles$1.container, (_ref2 = {}, _defineProperty(_ref2, className, className !== null), _defineProperty(_ref2, styles$1.preventScroll, !draggable), _ref2)])
444
425
  }, stopDragEventsPropagation), /*#__PURE__*/React.createElement("div", {
@@ -451,7 +432,6 @@ var Map$1 = function Map(_ref) {
451
432
  });
452
433
  }));
453
434
  };
454
-
455
435
  Map$1.propTypes = propTypes$2;
456
436
  Map$1.defaultProps = defaultProps$2;
457
437
 
@@ -461,20 +441,18 @@ var eventMapping = {
461
441
  };
462
442
  function useGoogleMapMarker(map) {
463
443
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
464
- _ref$position = _ref.position,
465
- position = _ref$position === void 0 ? null : _ref$position,
466
- _ref$icon = _ref.icon,
467
- icon = _ref$icon === void 0 ? null : _ref$icon,
468
- _ref$iconSize = _ref.iconSize,
469
- iconSize = _ref$iconSize === void 0 ? null : _ref$iconSize,
470
- events = _ref.events,
471
- title = _ref.title;
472
-
444
+ _ref$position = _ref.position,
445
+ position = _ref$position === void 0 ? null : _ref$position,
446
+ _ref$icon = _ref.icon,
447
+ icon = _ref$icon === void 0 ? null : _ref$icon,
448
+ _ref$iconSize = _ref.iconSize,
449
+ iconSize = _ref$iconSize === void 0 ? null : _ref$iconSize,
450
+ events = _ref.events,
451
+ title = _ref.title;
473
452
  var client = useGoogleMapsClient();
474
453
  var markerRef = useRef(null);
475
454
  useEffect(function () {
476
455
  var marker = markerRef.current;
477
-
478
456
  if (marker !== null && position !== null) {
479
457
  marker.setPosition(position);
480
458
  }
@@ -483,12 +461,10 @@ function useGoogleMapMarker(map) {
483
461
  if (client === null) {
484
462
  return;
485
463
  }
486
-
487
464
  if (isObject(newIcon)) {
488
465
  var _ref2 = newIcon || {},
489
- _ref2$url = _ref2.url,
490
- iconUrl = _ref2$url === void 0 ? null : _ref2$url;
491
-
466
+ _ref2$url = _ref2.url,
467
+ iconUrl = _ref2$url === void 0 ? null : _ref2$url;
492
468
  marker.setIcon({
493
469
  url: iconUrl,
494
470
  scaledSize: new client.maps.Size(iconSize.width, iconSize.height)
@@ -499,18 +475,15 @@ function useGoogleMapMarker(map) {
499
475
  }, [client, iconSize]);
500
476
  useEffect(function () {
501
477
  var marker = markerRef.current;
502
-
503
478
  if (marker === null || client === null) {
504
479
  return;
505
480
  }
506
-
507
481
  updateIcon(marker, icon);
508
482
  }, [client, icon, updateIcon]);
509
483
  useEffect(function () {
510
484
  if (client === null || map === null || markerRef.current !== null) {
511
485
  return function () {};
512
486
  }
513
-
514
487
  var marker = new client.maps.Marker({
515
488
  position: position,
516
489
  map: map,
@@ -564,16 +537,15 @@ var defaultProps$1 = {
564
537
  height: 50
565
538
  }
566
539
  };
567
-
568
540
  var Marker = function Marker(_ref) {
569
541
  var map = _ref.map,
570
- position = _ref.position,
571
- type = _ref.type,
572
- events = _ref.events,
573
- active = _ref.active,
574
- title = _ref.title,
575
- image = _ref.image,
576
- iconSize = _ref.iconSize;
542
+ position = _ref.position,
543
+ type = _ref.type,
544
+ events = _ref.events,
545
+ active = _ref.active,
546
+ title = _ref.title,
547
+ image = _ref.image,
548
+ iconSize = _ref.iconSize;
577
549
  useGoogleMapMarker(map, {
578
550
  position: position,
579
551
  type: type,
@@ -584,7 +556,6 @@ var Marker = function Marker(_ref) {
584
556
  });
585
557
  return null;
586
558
  };
587
-
588
559
  Marker.propTypes = propTypes$1;
589
560
  Marker.defaultProps = defaultProps$1;
590
561
 
@@ -597,7 +568,6 @@ Marker.defaultProps = defaultProps$1;
597
568
  lng: PropTypes.number
598
569
  })).isRequired,
599
570
  events: PropTypes.object // eslint-disable-line
600
-
601
571
  });
602
572
 
603
573
  ({
@@ -657,29 +627,28 @@ var defaultProps = {
657
627
  fullscreenControl: false,
658
628
  focusable: true
659
629
  };
660
-
661
630
  var Map = function Map(_ref) {
662
631
  var center = _ref.center,
663
- zoom = _ref.zoom,
664
- draggable = _ref.draggable,
665
- markers = _ref.markers,
666
- onClickMap = _ref.onClickMap,
667
- onClickMarker = _ref.onClickMarker,
668
- className = _ref.className,
669
- onReady = _ref.onReady,
670
- onCenterChanged = _ref.onCenterChanged,
671
- onBoundsChanged = _ref.onBoundsChanged,
672
- onDrag = _ref.onDrag,
673
- onDragEnd = _ref.onDragEnd,
674
- withoutStyle = _ref.withoutStyle,
675
- fitBounds = _ref.fitBounds,
676
- zoomControl = _ref.zoomControl,
677
- mapTypeControl = _ref.mapTypeControl,
678
- scaleControl = _ref.scaleControl,
679
- streetViewControl = _ref.streetViewControl,
680
- rotateControl = _ref.rotateControl,
681
- fullscreenControl = _ref.fullscreenControl,
682
- focusable = _ref.focusable;
632
+ zoom = _ref.zoom,
633
+ draggable = _ref.draggable,
634
+ markers = _ref.markers,
635
+ onClickMap = _ref.onClickMap,
636
+ onClickMarker = _ref.onClickMarker,
637
+ className = _ref.className,
638
+ onReady = _ref.onReady,
639
+ onCenterChanged = _ref.onCenterChanged,
640
+ onBoundsChanged = _ref.onBoundsChanged,
641
+ onDrag = _ref.onDrag,
642
+ onDragEnd = _ref.onDragEnd,
643
+ withoutStyle = _ref.withoutStyle,
644
+ fitBounds = _ref.fitBounds,
645
+ zoomControl = _ref.zoomControl,
646
+ mapTypeControl = _ref.mapTypeControl,
647
+ scaleControl = _ref.scaleControl,
648
+ streetViewControl = _ref.streetViewControl,
649
+ rotateControl = _ref.rotateControl,
650
+ fullscreenControl = _ref.fullscreenControl,
651
+ focusable = _ref.focusable;
683
652
  var client = useGoogleMapsClient();
684
653
  var onClick = useCallback(function (position) {
685
654
  if (onClickMap !== null) {
@@ -690,35 +659,28 @@ var Map = function Map(_ref) {
690
659
  var correctMarkers = (markers || []).filter(function (it) {
691
660
  return it !== null && (it.geoPosition || null) !== null;
692
661
  });
693
-
694
662
  if (client === null || correctMarkers === null || correctMarkers.length === 0) {
695
663
  return null;
696
664
  }
697
-
698
665
  var markersBounds = correctMarkers.reduce(function (newBounds, _ref2) {
699
666
  var _ref2$geoPosition = _ref2.geoPosition,
700
- geoPosition = _ref2$geoPosition === void 0 ? null : _ref2$geoPosition;
701
-
667
+ geoPosition = _ref2$geoPosition === void 0 ? null : _ref2$geoPosition;
702
668
  var _ref3 = geoPosition || {},
703
- _ref3$lat = _ref3.lat,
704
- lat = _ref3$lat === void 0 ? null : _ref3$lat,
705
- _ref3$lng = _ref3.lng,
706
- lng = _ref3$lng === void 0 ? null : _ref3$lng;
707
-
669
+ _ref3$lat = _ref3.lat,
670
+ lat = _ref3$lat === void 0 ? null : _ref3$lat,
671
+ _ref3$lng = _ref3.lng,
672
+ lng = _ref3$lng === void 0 ? null : _ref3$lng;
708
673
  if (lat !== null && lng !== null) {
709
674
  newBounds.extend(new client.maps.LatLng(lat, lng));
710
675
  }
711
-
712
676
  return newBounds;
713
677
  }, new client.maps.LatLngBounds());
714
678
  return markersBounds;
715
679
  }, [client, markers]);
716
-
717
680
  var _useState = useState(false),
718
- _useState2 = _slicedToArray(_useState, 2),
719
- loaded = _useState2[0],
720
- setLoaded = _useState2[1];
721
-
681
+ _useState2 = _slicedToArray(_useState, 2),
682
+ loaded = _useState2[0],
683
+ setLoaded = _useState2[1];
722
684
  useEffect(function () {
723
685
  if (client !== null && loaded) {
724
686
  if (onReady !== null) {
@@ -758,13 +720,13 @@ var Map = function Map(_ref) {
758
720
  focusable: focusable
759
721
  }, markers !== null ? markers.map(function (_ref5, index) {
760
722
  var _ref5$active = _ref5.active,
761
- active = _ref5$active === void 0 ? true : _ref5$active,
762
- _ref5$geoPosition = _ref5.geoPosition,
763
- geoPosition = _ref5$geoPosition === void 0 ? null : _ref5$geoPosition,
764
- _ref5$image = _ref5.image,
765
- image = _ref5$image === void 0 ? null : _ref5$image,
766
- _ref5$title = _ref5.title,
767
- title = _ref5$title === void 0 ? null : _ref5$title;
723
+ active = _ref5$active === void 0 ? true : _ref5$active,
724
+ _ref5$geoPosition = _ref5.geoPosition,
725
+ geoPosition = _ref5$geoPosition === void 0 ? null : _ref5$geoPosition,
726
+ _ref5$image = _ref5.image,
727
+ image = _ref5$image === void 0 ? null : _ref5$image,
728
+ _ref5$title = _ref5.title,
729
+ title = _ref5$title === void 0 ? null : _ref5$title;
768
730
  return geoPosition !== null && (geoPosition.lat || null) !== null && (geoPosition.lng || null) !== null ? /*#__PURE__*/React.createElement(Marker, {
769
731
  key: "marker-".concat(index),
770
732
  active: active,
@@ -777,12 +739,10 @@ var Map = function Map(_ref) {
777
739
  } : function () {
778
740
  return console.log(index);
779
741
  } // eslint-disable-line no-console
780
-
781
742
  }
782
743
  }) : /*#__PURE__*/React.createElement("div", null);
783
744
  }) : null));
784
745
  };
785
-
786
746
  Map.propTypes = propTypes;
787
747
  Map.defaultProps = defaultProps;
788
748
 
package/lib/index.js CHANGED
@@ -207,52 +207,46 @@ var eventsMapping = {
207
207
  };
208
208
  function useGoogleMap(_ref) {
209
209
  var zoom = _ref.zoom,
210
- _ref$maxZoom = _ref.maxZoom,
211
- maxZoom = _ref$maxZoom === void 0 ? null : _ref$maxZoom,
212
- _ref$center = _ref.center,
213
- center = _ref$center === void 0 ? null : _ref$center,
214
- _ref$withoutStyle = _ref.withoutStyle,
215
- withoutStyle = _ref$withoutStyle === void 0 ? false : _ref$withoutStyle,
216
- _ref$fitBounds = _ref.fitBounds,
217
- fitBounds = _ref$fitBounds === void 0 ? false : _ref$fitBounds,
218
- _ref$bounds = _ref.bounds,
219
- bounds = _ref$bounds === void 0 ? null : _ref$bounds,
220
- events = _ref.events,
221
- _ref$draggable = _ref.draggable,
222
- draggable = _ref$draggable === void 0 ? false : _ref$draggable,
223
- zoomControl = _ref.zoomControl,
224
- mapTypeControl = _ref.mapTypeControl,
225
- scaleControl = _ref.scaleControl,
226
- streetViewControl = _ref.streetViewControl,
227
- rotateControl = _ref.rotateControl,
228
- fullscreenControl = _ref.fullscreenControl;
210
+ _ref$maxZoom = _ref.maxZoom,
211
+ maxZoom = _ref$maxZoom === void 0 ? null : _ref$maxZoom,
212
+ _ref$center = _ref.center,
213
+ center = _ref$center === void 0 ? null : _ref$center,
214
+ _ref$withoutStyle = _ref.withoutStyle,
215
+ withoutStyle = _ref$withoutStyle === void 0 ? false : _ref$withoutStyle,
216
+ _ref$fitBounds = _ref.fitBounds,
217
+ fitBounds = _ref$fitBounds === void 0 ? false : _ref$fitBounds,
218
+ _ref$bounds = _ref.bounds,
219
+ bounds = _ref$bounds === void 0 ? null : _ref$bounds,
220
+ events = _ref.events,
221
+ _ref$draggable = _ref.draggable,
222
+ draggable = _ref$draggable === void 0 ? false : _ref$draggable,
223
+ zoomControl = _ref.zoomControl,
224
+ mapTypeControl = _ref.mapTypeControl,
225
+ scaleControl = _ref.scaleControl,
226
+ streetViewControl = _ref.streetViewControl,
227
+ rotateControl = _ref.rotateControl,
228
+ fullscreenControl = _ref.fullscreenControl;
229
229
  var client = contexts.useGoogleMapsClient();
230
-
231
230
  var _useState = React.useState(false),
232
- _useState2 = _slicedToArray__default["default"](_useState, 2),
233
- ready = _useState2[0],
234
- setReady = _useState2[1];
235
-
231
+ _useState2 = _slicedToArray__default["default"](_useState, 2),
232
+ ready = _useState2[0],
233
+ setReady = _useState2[1];
236
234
  var containerRef = React.useRef(null);
237
235
  var mapRef = React.useRef(null);
238
-
239
236
  var _useDimensionObserver = hooks.useDimensionObserver(),
240
- resizeRef = _useDimensionObserver.ref,
241
- _useDimensionObserver2 = _useDimensionObserver.width,
242
- width = _useDimensionObserver2 === void 0 ? null : _useDimensionObserver2,
243
- _useDimensionObserver3 = _useDimensionObserver.height,
244
- height = _useDimensionObserver3 === void 0 ? null : _useDimensionObserver3;
245
-
237
+ resizeRef = _useDimensionObserver.ref,
238
+ _useDimensionObserver2 = _useDimensionObserver.width,
239
+ width = _useDimensionObserver2 === void 0 ? null : _useDimensionObserver2,
240
+ _useDimensionObserver3 = _useDimensionObserver.height,
241
+ height = _useDimensionObserver3 === void 0 ? null : _useDimensionObserver3;
246
242
  React.useEffect(function () {
247
243
  var map = mapRef.current;
248
-
249
244
  if (map !== null && center !== null) {
250
245
  var _ref2 = center || {},
251
- _ref2$lat = _ref2.lat,
252
- lat = _ref2$lat === void 0 ? null : _ref2$lat,
253
- _ref2$lng = _ref2.lng,
254
- lng = _ref2$lng === void 0 ? null : _ref2$lng;
255
-
246
+ _ref2$lat = _ref2.lat,
247
+ lat = _ref2$lat === void 0 ? null : _ref2$lat,
248
+ _ref2$lng = _ref2.lng,
249
+ lng = _ref2$lng === void 0 ? null : _ref2$lng;
256
250
  map.panTo({
257
251
  lat: lat || 0,
258
252
  lng: lng || 0
@@ -261,7 +255,6 @@ function useGoogleMap(_ref) {
261
255
  }, [center]);
262
256
  React.useEffect(function () {
263
257
  var map = mapRef.current;
264
-
265
258
  if (map !== null && zoom !== null) {
266
259
  map.setZoom(Math.min(maxZoom, zoom));
267
260
  }
@@ -270,25 +263,20 @@ function useGoogleMap(_ref) {
270
263
  if (newBounds === null || newBounds.equals(map.getBounds())) {
271
264
  return;
272
265
  }
273
-
274
266
  map.fitBounds(newBounds);
275
-
276
267
  if (map.getZoom() > maxZoom) {
277
268
  map.setZoom(maxZoom);
278
269
  }
279
-
280
270
  map.panToBounds(newBounds);
281
271
  }, [maxZoom]);
282
272
  React.useEffect(function () {
283
273
  var map = mapRef.current;
284
-
285
274
  if (map !== null && fitBounds) {
286
275
  updateBounds(map, bounds);
287
276
  }
288
277
  }, [updateBounds, bounds, fitBounds, width, height]);
289
278
  React.useEffect(function () {
290
279
  var map = mapRef.current;
291
-
292
280
  if (ready && map !== null) {
293
281
  map.setOptions({
294
282
  draggable: draggable,
@@ -302,7 +290,6 @@ function useGoogleMap(_ref) {
302
290
  if (client === null || containerRef.current === null || mapRef.current !== null) {
303
291
  return function () {};
304
292
  }
305
-
306
293
  var map = new client.maps.Map(containerRef.current, {
307
294
  zoom: zoom,
308
295
  center: center,
@@ -314,13 +301,12 @@ function useGoogleMap(_ref) {
314
301
  rotateControl: rotateControl,
315
302
  fullscreenControl: fullscreenControl
316
303
  });
317
-
318
304
  if (fitBounds) {
319
305
  updateBounds(map, bounds);
320
306
  }
307
+ mapRef.current = map;
321
308
 
322
- mapRef.current = map; // @TODO unbind events
323
-
309
+ // @TODO unbind events
324
310
  if (events !== null) {
325
311
  Object.keys(events).forEach(function (eventName) {
326
312
  if (events[eventName] !== null) {
@@ -330,7 +316,6 @@ function useGoogleMap(_ref) {
330
316
  }
331
317
  });
332
318
  }
333
-
334
319
  setReady(true);
335
320
  return function () {};
336
321
  }, [client, setReady]);
@@ -412,47 +397,43 @@ var defaultProps$2 = {
412
397
  children: null,
413
398
  focusable: true
414
399
  };
415
-
416
400
  var Map$1 = function Map(_ref) {
417
401
  var _ref2;
418
-
419
402
  var center = _ref.center,
420
- zoom = _ref.zoom,
421
- maxZoom = _ref.maxZoom,
422
- bounds = _ref.bounds,
423
- draggable = _ref.draggable,
424
- withoutStyle = _ref.withoutStyle,
425
- events = _ref.events,
426
- fitBounds = _ref.fitBounds,
427
- zoomControl = _ref.zoomControl,
428
- mapTypeControl = _ref.mapTypeControl,
429
- scaleControl = _ref.scaleControl,
430
- streetViewControl = _ref.streetViewControl,
431
- rotateControl = _ref.rotateControl,
432
- fullscreenControl = _ref.fullscreenControl,
433
- className = _ref.className,
434
- children = _ref.children,
435
- focusable = _ref.focusable;
436
-
403
+ zoom = _ref.zoom,
404
+ maxZoom = _ref.maxZoom,
405
+ bounds = _ref.bounds,
406
+ draggable = _ref.draggable,
407
+ withoutStyle = _ref.withoutStyle,
408
+ events = _ref.events,
409
+ fitBounds = _ref.fitBounds,
410
+ zoomControl = _ref.zoomControl,
411
+ mapTypeControl = _ref.mapTypeControl,
412
+ scaleControl = _ref.scaleControl,
413
+ streetViewControl = _ref.streetViewControl,
414
+ rotateControl = _ref.rotateControl,
415
+ fullscreenControl = _ref.fullscreenControl,
416
+ className = _ref.className,
417
+ children = _ref.children,
418
+ focusable = _ref.focusable;
437
419
  var _useGoogleMap = useGoogleMap({
438
- zoom: zoom,
439
- maxZoom: maxZoom,
440
- bounds: bounds,
441
- draggable: draggable,
442
- fitBounds: fitBounds,
443
- center: center,
444
- events: events,
445
- withoutStyle: withoutStyle,
446
- zoomControl: zoomControl,
447
- mapTypeControl: mapTypeControl,
448
- scaleControl: scaleControl,
449
- streetViewControl: streetViewControl,
450
- rotateControl: rotateControl,
451
- fullscreenControl: fullscreenControl
452
- }),
453
- map = _useGoogleMap.map,
454
- mapRef = _useGoogleMap.ref;
455
-
420
+ zoom: zoom,
421
+ maxZoom: maxZoom,
422
+ bounds: bounds,
423
+ draggable: draggable,
424
+ fitBounds: fitBounds,
425
+ center: center,
426
+ events: events,
427
+ withoutStyle: withoutStyle,
428
+ zoomControl: zoomControl,
429
+ mapTypeControl: mapTypeControl,
430
+ scaleControl: scaleControl,
431
+ streetViewControl: streetViewControl,
432
+ rotateControl: rotateControl,
433
+ fullscreenControl: fullscreenControl
434
+ }),
435
+ map = _useGoogleMap.map,
436
+ mapRef = _useGoogleMap.ref;
456
437
  return /*#__PURE__*/React__default["default"].createElement("div", Object.assign({
457
438
  className: classNames__default["default"]([styles$1.container, (_ref2 = {}, _defineProperty__default["default"](_ref2, className, className !== null), _defineProperty__default["default"](_ref2, styles$1.preventScroll, !draggable), _ref2)])
458
439
  }, stopDragEventsPropagation), /*#__PURE__*/React__default["default"].createElement("div", {
@@ -465,7 +446,6 @@ var Map$1 = function Map(_ref) {
465
446
  });
466
447
  }));
467
448
  };
468
-
469
449
  Map$1.propTypes = propTypes$2;
470
450
  Map$1.defaultProps = defaultProps$2;
471
451
 
@@ -475,20 +455,18 @@ var eventMapping = {
475
455
  };
476
456
  function useGoogleMapMarker(map) {
477
457
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
478
- _ref$position = _ref.position,
479
- position = _ref$position === void 0 ? null : _ref$position,
480
- _ref$icon = _ref.icon,
481
- icon = _ref$icon === void 0 ? null : _ref$icon,
482
- _ref$iconSize = _ref.iconSize,
483
- iconSize = _ref$iconSize === void 0 ? null : _ref$iconSize,
484
- events = _ref.events,
485
- title = _ref.title;
486
-
458
+ _ref$position = _ref.position,
459
+ position = _ref$position === void 0 ? null : _ref$position,
460
+ _ref$icon = _ref.icon,
461
+ icon = _ref$icon === void 0 ? null : _ref$icon,
462
+ _ref$iconSize = _ref.iconSize,
463
+ iconSize = _ref$iconSize === void 0 ? null : _ref$iconSize,
464
+ events = _ref.events,
465
+ title = _ref.title;
487
466
  var client = contexts.useGoogleMapsClient();
488
467
  var markerRef = React.useRef(null);
489
468
  React.useEffect(function () {
490
469
  var marker = markerRef.current;
491
-
492
470
  if (marker !== null && position !== null) {
493
471
  marker.setPosition(position);
494
472
  }
@@ -497,12 +475,10 @@ function useGoogleMapMarker(map) {
497
475
  if (client === null) {
498
476
  return;
499
477
  }
500
-
501
478
  if (isObject__default["default"](newIcon)) {
502
479
  var _ref2 = newIcon || {},
503
- _ref2$url = _ref2.url,
504
- iconUrl = _ref2$url === void 0 ? null : _ref2$url;
505
-
480
+ _ref2$url = _ref2.url,
481
+ iconUrl = _ref2$url === void 0 ? null : _ref2$url;
506
482
  marker.setIcon({
507
483
  url: iconUrl,
508
484
  scaledSize: new client.maps.Size(iconSize.width, iconSize.height)
@@ -513,18 +489,15 @@ function useGoogleMapMarker(map) {
513
489
  }, [client, iconSize]);
514
490
  React.useEffect(function () {
515
491
  var marker = markerRef.current;
516
-
517
492
  if (marker === null || client === null) {
518
493
  return;
519
494
  }
520
-
521
495
  updateIcon(marker, icon);
522
496
  }, [client, icon, updateIcon]);
523
497
  React.useEffect(function () {
524
498
  if (client === null || map === null || markerRef.current !== null) {
525
499
  return function () {};
526
500
  }
527
-
528
501
  var marker = new client.maps.Marker({
529
502
  position: position,
530
503
  map: map,
@@ -578,16 +551,15 @@ var defaultProps$1 = {
578
551
  height: 50
579
552
  }
580
553
  };
581
-
582
554
  var Marker = function Marker(_ref) {
583
555
  var map = _ref.map,
584
- position = _ref.position,
585
- type = _ref.type,
586
- events = _ref.events,
587
- active = _ref.active,
588
- title = _ref.title,
589
- image = _ref.image,
590
- iconSize = _ref.iconSize;
556
+ position = _ref.position,
557
+ type = _ref.type,
558
+ events = _ref.events,
559
+ active = _ref.active,
560
+ title = _ref.title,
561
+ image = _ref.image,
562
+ iconSize = _ref.iconSize;
591
563
  useGoogleMapMarker(map, {
592
564
  position: position,
593
565
  type: type,
@@ -598,7 +570,6 @@ var Marker = function Marker(_ref) {
598
570
  });
599
571
  return null;
600
572
  };
601
-
602
573
  Marker.propTypes = propTypes$1;
603
574
  Marker.defaultProps = defaultProps$1;
604
575
 
@@ -611,7 +582,6 @@ Marker.defaultProps = defaultProps$1;
611
582
  lng: PropTypes__default["default"].number
612
583
  })).isRequired,
613
584
  events: PropTypes__default["default"].object // eslint-disable-line
614
-
615
585
  });
616
586
 
617
587
  ({
@@ -671,29 +641,28 @@ var defaultProps = {
671
641
  fullscreenControl: false,
672
642
  focusable: true
673
643
  };
674
-
675
644
  var Map = function Map(_ref) {
676
645
  var center = _ref.center,
677
- zoom = _ref.zoom,
678
- draggable = _ref.draggable,
679
- markers = _ref.markers,
680
- onClickMap = _ref.onClickMap,
681
- onClickMarker = _ref.onClickMarker,
682
- className = _ref.className,
683
- onReady = _ref.onReady,
684
- onCenterChanged = _ref.onCenterChanged,
685
- onBoundsChanged = _ref.onBoundsChanged,
686
- onDrag = _ref.onDrag,
687
- onDragEnd = _ref.onDragEnd,
688
- withoutStyle = _ref.withoutStyle,
689
- fitBounds = _ref.fitBounds,
690
- zoomControl = _ref.zoomControl,
691
- mapTypeControl = _ref.mapTypeControl,
692
- scaleControl = _ref.scaleControl,
693
- streetViewControl = _ref.streetViewControl,
694
- rotateControl = _ref.rotateControl,
695
- fullscreenControl = _ref.fullscreenControl,
696
- focusable = _ref.focusable;
646
+ zoom = _ref.zoom,
647
+ draggable = _ref.draggable,
648
+ markers = _ref.markers,
649
+ onClickMap = _ref.onClickMap,
650
+ onClickMarker = _ref.onClickMarker,
651
+ className = _ref.className,
652
+ onReady = _ref.onReady,
653
+ onCenterChanged = _ref.onCenterChanged,
654
+ onBoundsChanged = _ref.onBoundsChanged,
655
+ onDrag = _ref.onDrag,
656
+ onDragEnd = _ref.onDragEnd,
657
+ withoutStyle = _ref.withoutStyle,
658
+ fitBounds = _ref.fitBounds,
659
+ zoomControl = _ref.zoomControl,
660
+ mapTypeControl = _ref.mapTypeControl,
661
+ scaleControl = _ref.scaleControl,
662
+ streetViewControl = _ref.streetViewControl,
663
+ rotateControl = _ref.rotateControl,
664
+ fullscreenControl = _ref.fullscreenControl,
665
+ focusable = _ref.focusable;
697
666
  var client = contexts.useGoogleMapsClient();
698
667
  var onClick = React.useCallback(function (position) {
699
668
  if (onClickMap !== null) {
@@ -704,35 +673,28 @@ var Map = function Map(_ref) {
704
673
  var correctMarkers = (markers || []).filter(function (it) {
705
674
  return it !== null && (it.geoPosition || null) !== null;
706
675
  });
707
-
708
676
  if (client === null || correctMarkers === null || correctMarkers.length === 0) {
709
677
  return null;
710
678
  }
711
-
712
679
  var markersBounds = correctMarkers.reduce(function (newBounds, _ref2) {
713
680
  var _ref2$geoPosition = _ref2.geoPosition,
714
- geoPosition = _ref2$geoPosition === void 0 ? null : _ref2$geoPosition;
715
-
681
+ geoPosition = _ref2$geoPosition === void 0 ? null : _ref2$geoPosition;
716
682
  var _ref3 = geoPosition || {},
717
- _ref3$lat = _ref3.lat,
718
- lat = _ref3$lat === void 0 ? null : _ref3$lat,
719
- _ref3$lng = _ref3.lng,
720
- lng = _ref3$lng === void 0 ? null : _ref3$lng;
721
-
683
+ _ref3$lat = _ref3.lat,
684
+ lat = _ref3$lat === void 0 ? null : _ref3$lat,
685
+ _ref3$lng = _ref3.lng,
686
+ lng = _ref3$lng === void 0 ? null : _ref3$lng;
722
687
  if (lat !== null && lng !== null) {
723
688
  newBounds.extend(new client.maps.LatLng(lat, lng));
724
689
  }
725
-
726
690
  return newBounds;
727
691
  }, new client.maps.LatLngBounds());
728
692
  return markersBounds;
729
693
  }, [client, markers]);
730
-
731
694
  var _useState = React.useState(false),
732
- _useState2 = _slicedToArray__default["default"](_useState, 2),
733
- loaded = _useState2[0],
734
- setLoaded = _useState2[1];
735
-
695
+ _useState2 = _slicedToArray__default["default"](_useState, 2),
696
+ loaded = _useState2[0],
697
+ setLoaded = _useState2[1];
736
698
  React.useEffect(function () {
737
699
  if (client !== null && loaded) {
738
700
  if (onReady !== null) {
@@ -772,13 +734,13 @@ var Map = function Map(_ref) {
772
734
  focusable: focusable
773
735
  }, markers !== null ? markers.map(function (_ref5, index) {
774
736
  var _ref5$active = _ref5.active,
775
- active = _ref5$active === void 0 ? true : _ref5$active,
776
- _ref5$geoPosition = _ref5.geoPosition,
777
- geoPosition = _ref5$geoPosition === void 0 ? null : _ref5$geoPosition,
778
- _ref5$image = _ref5.image,
779
- image = _ref5$image === void 0 ? null : _ref5$image,
780
- _ref5$title = _ref5.title,
781
- title = _ref5$title === void 0 ? null : _ref5$title;
737
+ active = _ref5$active === void 0 ? true : _ref5$active,
738
+ _ref5$geoPosition = _ref5.geoPosition,
739
+ geoPosition = _ref5$geoPosition === void 0 ? null : _ref5$geoPosition,
740
+ _ref5$image = _ref5.image,
741
+ image = _ref5$image === void 0 ? null : _ref5$image,
742
+ _ref5$title = _ref5.title,
743
+ title = _ref5$title === void 0 ? null : _ref5$title;
782
744
  return geoPosition !== null && (geoPosition.lat || null) !== null && (geoPosition.lng || null) !== null ? /*#__PURE__*/React__default["default"].createElement(Marker, {
783
745
  key: "marker-".concat(index),
784
746
  active: active,
@@ -791,12 +753,10 @@ var Map = function Map(_ref) {
791
753
  } : function () {
792
754
  return console.log(index);
793
755
  } // eslint-disable-line no-console
794
-
795
756
  }
796
757
  }) : /*#__PURE__*/React__default["default"].createElement("div", null);
797
758
  }) : null));
798
759
  };
799
-
800
760
  Map.propTypes = propTypes;
801
761
  Map.defaultProps = defaultProps;
802
762
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/element-map",
3
- "version": "0.3.311",
3
+ "version": "0.3.318",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -49,15 +49,15 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@babel/runtime": "^7.13.10",
52
- "@micromag/core": "^0.3.311",
52
+ "@micromag/core": "^0.3.318",
53
53
  "classnames": "^2.2.6",
54
54
  "lodash": "^4.17.21",
55
55
  "prop-types": "^15.7.2",
56
56
  "react-intl": "^5.12.1",
57
- "uuid": "^8.3.2"
57
+ "uuid": "^9.0.0"
58
58
  },
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "gitHead": "fab297a7ad204611597c749b969f14d992d35d47"
62
+ "gitHead": "7d1a296e0c0d410e1225279e1f19e3a7715bfa96"
63
63
  }