react-map4d-map 1.3.5 → 1.3.6

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,18 @@ 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;
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
+ }, {
1017
+ circle: true
1018
+ })]);
971
1019
 
972
1020
  if (props.onClickLocation) {
973
- var _mapRef$current21;
1021
+ var _mapRef$current22;
974
1022
 
975
- var onClickLocation = (_mapRef$current21 = mapRef.current) === null || _mapRef$current21 === void 0 ? void 0 : _mapRef$current21.addListener("click", function (args) {
1023
+ var onClickLocation = (_mapRef$current22 = mapRef.current) === null || _mapRef$current22 === void 0 ? void 0 : _mapRef$current22.addListener("click", function (args) {
976
1024
  props.onClickLocation && props.onClickLocation(args);
977
1025
  }, {
978
1026
  location: true
@@ -981,9 +1029,9 @@ var MFMap = function MFMap(props) {
981
1029
  }
982
1030
 
983
1031
  if (props.onRightClickLocation) {
984
- var _mapRef$current22;
1032
+ var _mapRef$current23;
985
1033
 
986
- var onRightClickLocation = (_mapRef$current22 = mapRef.current) === null || _mapRef$current22 === void 0 ? void 0 : _mapRef$current22.addListener("rightClick", function (args) {
1034
+ var onRightClickLocation = (_mapRef$current23 = mapRef.current) === null || _mapRef$current23 === void 0 ? void 0 : _mapRef$current23.addListener("rightClick", function (args) {
987
1035
  props.onRightClickLocation && props.onRightClickLocation(args);
988
1036
  }, {
989
1037
  location: true
@@ -992,9 +1040,9 @@ var MFMap = function MFMap(props) {
992
1040
  }
993
1041
 
994
1042
  if (props.onTilesLoaded) {
995
- var _mapRef$current23;
1043
+ var _mapRef$current24;
996
1044
 
997
- var onTilesLoaded = (_mapRef$current23 = mapRef.current) === null || _mapRef$current23 === void 0 ? void 0 : _mapRef$current23.addListener("tilesLoaded", function (args) {
1045
+ var onTilesLoaded = (_mapRef$current24 = mapRef.current) === null || _mapRef$current24 === void 0 ? void 0 : _mapRef$current24.addListener("tilesLoaded", function (args) {
998
1046
  props.onTilesLoaded && props.onTilesLoaded(args);
999
1047
  }, {
1000
1048
  location: true
@@ -1003,9 +1051,9 @@ var MFMap = function MFMap(props) {
1003
1051
  }
1004
1052
 
1005
1053
  if (props.onCameraChanging) {
1006
- var _mapRef$current24;
1054
+ var _mapRef$current25;
1007
1055
 
1008
- var onCameraChanging = (_mapRef$current24 = mapRef.current) === null || _mapRef$current24 === void 0 ? void 0 : _mapRef$current24.addListener("cameraChanging", function (args) {
1056
+ var onCameraChanging = (_mapRef$current25 = mapRef.current) === null || _mapRef$current25 === void 0 ? void 0 : _mapRef$current25.addListener("cameraChanging", function (args) {
1009
1057
  props.onCameraChanging && props.onCameraChanging(args);
1010
1058
  }, {
1011
1059
  location: true