react-map4d-map 1.3.5 → 1.3.7

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.
@@ -249,7 +249,8 @@ var MFCircle = function MFCircle(props) {
249
249
  elevation = props.elevation,
250
250
  userInteractionEnabled = props.userInteractionEnabled,
251
251
  map = props.map,
252
- onCreated = props.onCreated;
252
+ onCreated = props.onCreated,
253
+ onClick = props.onClick;
253
254
  var map4dContext = useContext(Map4dContext);
254
255
  var theMap = map || map4dContext.map;
255
256
  var circleRef = useRef();
@@ -281,8 +282,14 @@ var MFCircle = function MFCircle(props) {
281
282
  circleRef.current = new map4d.Circle(option);
282
283
  (_circleRef$current = circleRef.current) === null || _circleRef$current === void 0 ? void 0 : _circleRef$current.setMap(theMap);
283
284
  onCreated && onCreated(circleRef.current);
285
+ circleRef.current.onClick = onClick;
284
286
  }
285
287
  }, [theMap]);
288
+ useEffect(function () {
289
+ if (circleRef.current) {
290
+ circleRef.current.onClick = onClick;
291
+ }
292
+ }, [onClick]);
286
293
  useEffect(function () {
287
294
  if (theMap) {
288
295
  var _circleRef$current2;
@@ -761,25 +768,60 @@ var createId = function createId() {
761
768
  };
762
769
 
763
770
  var MFMap = function MFMap(props) {
771
+ var _options = useRef({
772
+ options: props.options,
773
+ mapId: props.mapid,
774
+ version: props.version,
775
+ environment: props.environment,
776
+ accessKey: props.accessKey,
777
+ sdkDomain: props.sdkDomain
778
+ });
779
+
764
780
  var callback = useRef("callback");
765
781
  var mapDomRef = useRef();
766
782
  var mapRef = useRef();
767
783
  var scriptElement = useRef();
768
784
  var url = useRef();
769
785
  var events = useRef([]);
786
+ var zoom = props.zoom,
787
+ bearing = props.bearing,
788
+ center = props.center,
789
+ tilt = props.tilt;
770
790
 
771
791
  var _useState = useState(),
772
792
  map = _useState[0],
773
793
  setMap = _useState[1];
774
794
 
795
+ useEffect(function () {
796
+ if (map) {
797
+ var camera = map.getCamera();
798
+
799
+ if (zoom != undefined && zoom != null) {
800
+ camera.setZoom(zoom);
801
+ }
802
+
803
+ if (bearing != undefined && bearing != null) {
804
+ camera.setBearing(bearing);
805
+ }
806
+
807
+ if (center != undefined && center != null) {
808
+ camera.setTarget(center);
809
+ }
810
+
811
+ if (tilt != undefined && tilt != null) {
812
+ camera.setTilt(center);
813
+ }
814
+
815
+ map.moveCamera(camera);
816
+ }
817
+ }, [zoom, bearing, center, map]);
775
818
  useEffect(function () {
776
819
  var id = createId();
777
820
  callback.current = "callback_" + id;
778
821
 
779
822
  var createCallback = function createCallback() {
780
823
  window[callback.current] = function () {
781
- var options = props.options;
782
- mapRef.current = new window.map4d.Map(mapDomRef.current, options);
824
+ mapRef.current = new window.map4d.Map(mapDomRef.current, _options.current.options);
783
825
 
784
826
  if (props.onMapReady) {
785
827
  props.onMapReady(mapRef.current, id);
@@ -790,16 +832,16 @@ var MFMap = function MFMap(props) {
790
832
  };
791
833
  };
792
834
 
793
- var domain = "https://api" + (props.environment ? "-" + props.environment : "") + ".map4d.vn";
835
+ var domain = "https://api" + (props.environment ? "-" + _options.current.environment : "") + ".map4d.vn";
794
836
 
795
- if (props.sdkDomain) {
796
- domain = props.sdkDomain;
837
+ if (_options.current.sdkDomain) {
838
+ domain = _options.current.sdkDomain;
797
839
  }
798
840
 
799
- var urlNew = domain + "/sdk/map/js?version=" + props.version + "&key=" + props.accessKey + "&callback=" + callback.current;
841
+ var urlNew = domain + "/sdk/map/js?version=" + _options.current.version + "&key=" + _options.current.accessKey + "&callback=" + callback.current;
800
842
 
801
- if (props.mapid) {
802
- urlNew += "&mapId=" + props.mapid;
843
+ if (_options.current.mapId) {
844
+ urlNew += "&mapId=" + _options.current.mapId;
803
845
  }
804
846
 
805
847
  createCallback();
@@ -829,10 +871,10 @@ var MFMap = function MFMap(props) {
829
871
 
830
872
  destroy();
831
873
  };
832
- }, [props.environment, props.version, props.accessKey, props.options]);
874
+ }, []);
833
875
 
834
876
  var registerEvent = function registerEvent() {
835
- var _mapRef$current2, _mapRef$current3, _mapRef$current4, _mapRef$current5, _mapRef$current6, _mapRef$current7, _mapRef$current8, _mapRef$current9, _mapRef$current10, _mapRef$current11, _mapRef$current12, _mapRef$current13, _mapRef$current14, _mapRef$current15, _mapRef$current16, _mapRef$current17, _mapRef$current18, _mapRef$current19, _mapRef$current20;
877
+ var _mapRef$current2, _mapRef$current3, _mapRef$current4, _mapRef$current5, _mapRef$current6, _mapRef$current7, _mapRef$current8, _mapRef$current9, _mapRef$current10, _mapRef$current11, _mapRef$current12, _mapRef$current13, _mapRef$current14, _mapRef$current15, _mapRef$current16, _mapRef$current17, _mapRef$current18, _mapRef$current19, _mapRef$current20, _mapRef$current21;
836
878
 
837
879
  var eventClickMarker = (_mapRef$current2 = mapRef.current) === null || _mapRef$current2 === void 0 ? void 0 : _mapRef$current2.addListener("click", function (args) {
838
880
  var _args$marker, _args$marker2;
@@ -967,12 +1009,20 @@ var MFMap = function MFMap(props) {
967
1009
  }, {
968
1010
  poi: true
969
1011
  });
970
- events.current = events.current.concat([eventClickMarker, eventRightClickMarker, eventDragEndMarker, eventHoverMarker, eventHoverPolygon, eventHoverPolyline, eventHoverDirection, eventClickPolyline, eventMouseOutDirection, eventMouseOverDirection, eventMouseMoveDirection, eventMouseOutPolyline, eventMouseOverPolyline, eventMouseMovePolyline, eventMouseOutMarker, eventMouseOverMarker, eventMouseMoveMarker, eventClickPoi, eventHoverPoi]);
1012
+ events.current = events.current.concat([eventClickMarker, eventRightClickMarker, eventDragEndMarker, eventHoverMarker, eventHoverPolygon, eventHoverPolyline, eventHoverDirection, eventClickPolyline, eventMouseOutDirection, eventMouseOverDirection, eventMouseMoveDirection, eventMouseOutPolyline, eventMouseOverPolyline, eventMouseMovePolyline, eventMouseOutMarker, eventMouseOverMarker, eventMouseMoveMarker, eventClickPoi, eventHoverPoi, (_mapRef$current21 = mapRef.current) === null || _mapRef$current21 === void 0 ? void 0 : _mapRef$current21.addListener("click", function (args) {
1013
+ var _args$circle, _args$circle2, _args$polygon3, _args$polygon3$onClic;
1014
+
1015
+ ((_args$circle = args.circle) === null || _args$circle === void 0 ? void 0 : _args$circle.onClick) && ((_args$circle2 = args.circle) === null || _args$circle2 === void 0 ? void 0 : _args$circle2.onClick(args));
1016
+ (_args$polygon3 = args.polygon) === null || _args$polygon3 === void 0 ? void 0 : (_args$polygon3$onClic = _args$polygon3.onClick) === null || _args$polygon3$onClic === void 0 ? void 0 : _args$polygon3$onClic.call(_args$polygon3, args);
1017
+ }, {
1018
+ circle: true,
1019
+ polygon: true
1020
+ })]);
971
1021
 
972
1022
  if (props.onClickLocation) {
973
- var _mapRef$current21;
1023
+ var _mapRef$current22;
974
1024
 
975
- var onClickLocation = (_mapRef$current21 = mapRef.current) === null || _mapRef$current21 === void 0 ? void 0 : _mapRef$current21.addListener("click", function (args) {
1025
+ var onClickLocation = (_mapRef$current22 = mapRef.current) === null || _mapRef$current22 === void 0 ? void 0 : _mapRef$current22.addListener("click", function (args) {
976
1026
  props.onClickLocation && props.onClickLocation(args);
977
1027
  }, {
978
1028
  location: true
@@ -981,9 +1031,9 @@ var MFMap = function MFMap(props) {
981
1031
  }
982
1032
 
983
1033
  if (props.onRightClickLocation) {
984
- var _mapRef$current22;
1034
+ var _mapRef$current23;
985
1035
 
986
- var onRightClickLocation = (_mapRef$current22 = mapRef.current) === null || _mapRef$current22 === void 0 ? void 0 : _mapRef$current22.addListener("rightClick", function (args) {
1036
+ var onRightClickLocation = (_mapRef$current23 = mapRef.current) === null || _mapRef$current23 === void 0 ? void 0 : _mapRef$current23.addListener("rightClick", function (args) {
987
1037
  props.onRightClickLocation && props.onRightClickLocation(args);
988
1038
  }, {
989
1039
  location: true
@@ -992,9 +1042,9 @@ var MFMap = function MFMap(props) {
992
1042
  }
993
1043
 
994
1044
  if (props.onTilesLoaded) {
995
- var _mapRef$current23;
1045
+ var _mapRef$current24;
996
1046
 
997
- var onTilesLoaded = (_mapRef$current23 = mapRef.current) === null || _mapRef$current23 === void 0 ? void 0 : _mapRef$current23.addListener("tilesLoaded", function (args) {
1047
+ var onTilesLoaded = (_mapRef$current24 = mapRef.current) === null || _mapRef$current24 === void 0 ? void 0 : _mapRef$current24.addListener("tilesLoaded", function (args) {
998
1048
  props.onTilesLoaded && props.onTilesLoaded(args);
999
1049
  }, {
1000
1050
  location: true
@@ -1003,9 +1053,9 @@ var MFMap = function MFMap(props) {
1003
1053
  }
1004
1054
 
1005
1055
  if (props.onCameraChanging) {
1006
- var _mapRef$current24;
1056
+ var _mapRef$current25;
1007
1057
 
1008
- var onCameraChanging = (_mapRef$current24 = mapRef.current) === null || _mapRef$current24 === void 0 ? void 0 : _mapRef$current24.addListener("cameraChanging", function (args) {
1058
+ var onCameraChanging = (_mapRef$current25 = mapRef.current) === null || _mapRef$current25 === void 0 ? void 0 : _mapRef$current25.addListener("cameraChanging", function (args) {
1009
1059
  props.onCameraChanging && props.onCameraChanging(args);
1010
1060
  }, {
1011
1061
  location: true
@@ -1599,6 +1649,7 @@ var MFPolygon = function MFPolygon(props) {
1599
1649
  userInteractionEnabled = props.userInteractionEnabled,
1600
1650
  map = props.map,
1601
1651
  onHover = props.onHover,
1652
+ onClick = props.onClick,
1602
1653
  onCreated = props.onCreated;
1603
1654
  var map4dContext = useContext(Map4dContext);
1604
1655
  var theMap = map || map4dContext.map;
@@ -1627,6 +1678,7 @@ var MFPolygon = function MFPolygon(props) {
1627
1678
  polygonRef.current = new map4d.Polygon(option);
1628
1679
  (_polygonRef$current = polygonRef.current) === null || _polygonRef$current === void 0 ? void 0 : _polygonRef$current.setMap(theMap);
1629
1680
  polygonRef.current.onHover = props.onHover;
1681
+ polygonRef.current.onClick = onClick;
1630
1682
  onCreated && onCreated(polygonRef.current);
1631
1683
  }
1632
1684
  }, [theMap]);
@@ -1655,6 +1707,11 @@ var MFPolygon = function MFPolygon(props) {
1655
1707
  polygonRef.current.onHover = onHover;
1656
1708
  }
1657
1709
  }, [onHover]);
1710
+ useEffect(function () {
1711
+ if (polygonRef.current) {
1712
+ polygonRef.current.onClick = onClick;
1713
+ }
1714
+ }, [onClick]);
1658
1715
  useEffect(function () {
1659
1716
  var _polygonRef$current5;
1660
1717