react-map4d-map 1.0.1 → 1.0.3

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.
@@ -706,23 +706,6 @@ var MFImageOverlay = function MFImageOverlay(props) {
706
706
  return null;
707
707
  };
708
708
 
709
- function _extends() {
710
- _extends = Object.assign ? Object.assign.bind() : function (target) {
711
- for (var i = 1; i < arguments.length; i++) {
712
- var source = arguments[i];
713
-
714
- for (var key in source) {
715
- if (Object.prototype.hasOwnProperty.call(source, key)) {
716
- target[key] = source[key];
717
- }
718
- }
719
- }
720
-
721
- return target;
722
- };
723
- return _extends.apply(this, arguments);
724
- }
725
-
726
709
  function _inheritsLoose(subClass, superClass) {
727
710
  subClass.prototype = Object.create(superClass.prototype);
728
711
  subClass.prototype.constructor = subClass;
@@ -779,6 +762,7 @@ var MFMap = /*#__PURE__*/function (_React$Component) {
779
762
  var _this;
780
763
 
781
764
  _this = _React$Component.call(this, props) || this;
765
+ _this.events = [];
782
766
  _this.state = {
783
767
  map: null
784
768
  };
@@ -799,7 +783,7 @@ var MFMap = /*#__PURE__*/function (_React$Component) {
799
783
  };
800
784
 
801
785
  _proto.destroy = function destroy() {
802
- var _this$mapRef;
786
+ var _this$events, _this$mapRef;
803
787
 
804
788
  delete window[this.callback];
805
789
 
@@ -807,24 +791,103 @@ var MFMap = /*#__PURE__*/function (_React$Component) {
807
791
  this.scriptElement.remove();
808
792
  }
809
793
 
794
+ (_this$events = this.events) === null || _this$events === void 0 ? void 0 : _this$events.forEach(function (t) {
795
+ t === null || t === void 0 ? void 0 : t.remove();
796
+ });
810
797
  ((_this$mapRef = this.mapRef) === null || _this$mapRef === void 0 ? void 0 : _this$mapRef.destroy) && this.mapRef.destroy();
811
798
  this.url = null;
812
799
  };
813
800
 
801
+ _proto.registerEvent = function registerEvent() {
802
+ var _this$mapRef2,
803
+ _this$mapRef3,
804
+ _this$mapRef4,
805
+ _this2 = this;
806
+
807
+ var eventClickMarker = (_this$mapRef2 = this.mapRef) === null || _this$mapRef2 === void 0 ? void 0 : _this$mapRef2.addListener("click", function (args) {
808
+ var _args$marker, _args$marker2;
809
+
810
+ ((_args$marker = args.marker) === null || _args$marker === void 0 ? void 0 : _args$marker.onClick) && ((_args$marker2 = args.marker) === null || _args$marker2 === void 0 ? void 0 : _args$marker2.onClick());
811
+ }, {
812
+ marker: true
813
+ });
814
+ var eventRightClickMarker = (_this$mapRef3 = this.mapRef) === null || _this$mapRef3 === void 0 ? void 0 : _this$mapRef3.addListener("rightClick", function (args) {
815
+ var _args$marker3, _args$marker4;
816
+
817
+ ((_args$marker3 = args.marker) === null || _args$marker3 === void 0 ? void 0 : _args$marker3.onRightClick) && ((_args$marker4 = args.marker) === null || _args$marker4 === void 0 ? void 0 : _args$marker4.onRightClick());
818
+ }, {
819
+ marker: true
820
+ });
821
+ var eventDragEndMarker = (_this$mapRef4 = this.mapRef) === null || _this$mapRef4 === void 0 ? void 0 : _this$mapRef4.addListener("dragEnd", function (args) {
822
+ var _args$marker5, _args$marker6;
823
+
824
+ ((_args$marker5 = args.marker) === null || _args$marker5 === void 0 ? void 0 : _args$marker5.onDragEnd) && ((_args$marker6 = args.marker) === null || _args$marker6 === void 0 ? void 0 : _args$marker6.onDragEnd());
825
+ }, {
826
+ marker: true
827
+ });
828
+ this.events.push([eventClickMarker, eventRightClickMarker, eventDragEndMarker]);
829
+
830
+ if (this.props.onClickLocation) {
831
+ var _this$mapRef5;
832
+
833
+ var onClickLocation = (_this$mapRef5 = this.mapRef) === null || _this$mapRef5 === void 0 ? void 0 : _this$mapRef5.addListener("click", function (args) {
834
+ _this2.props.onClickLocation && _this2.props.onClickLocation(args);
835
+ }, {
836
+ location: true
837
+ });
838
+ this.events.push(onClickLocation);
839
+ }
840
+
841
+ if (this.props.onRightClickLocation) {
842
+ var _this$mapRef6;
843
+
844
+ var onRightClickLocation = (_this$mapRef6 = this.mapRef) === null || _this$mapRef6 === void 0 ? void 0 : _this$mapRef6.addListener("rightClick", function (args) {
845
+ _this2.props.onRightClickLocation && _this2.props.onRightClickLocation(args);
846
+ }, {
847
+ location: true
848
+ });
849
+ this.events.push(onRightClickLocation);
850
+ }
851
+
852
+ if (this.props.onTilesLoaded) {
853
+ var _this$mapRef7;
854
+
855
+ var onTilesLoaded = (_this$mapRef7 = this.mapRef) === null || _this$mapRef7 === void 0 ? void 0 : _this$mapRef7.addListener("tilesLoaded", function (args) {
856
+ _this2.props.onTilesLoaded && _this2.props.onTilesLoaded(args);
857
+ }, {
858
+ location: true
859
+ });
860
+ this.events.push(onTilesLoaded);
861
+ }
862
+
863
+ if (this.props.onCameraChanging) {
864
+ var _this$mapRef8;
865
+
866
+ var onCameraChanging = (_this$mapRef8 = this.mapRef) === null || _this$mapRef8 === void 0 ? void 0 : _this$mapRef8.addListener("cameraChanging", function (args) {
867
+ _this2.props.onCameraChanging && _this2.props.onCameraChanging(args);
868
+ }, {
869
+ location: true
870
+ });
871
+ this.events.push(onCameraChanging);
872
+ }
873
+ };
874
+
814
875
  _proto.createCallback = function createCallback() {
815
- var _this2 = this;
876
+ var _this3 = this;
816
877
 
817
878
  window[this.callback] = function () {
818
- if (_this2.mapDomRef) {
819
- var options = _this2.props.options;
820
- _this2.mapRef = new window.map4d.Map(_this2.mapDomRef, options);
879
+ if (_this3.mapDomRef) {
880
+ var options = _this3.props.options;
881
+ _this3.mapRef = new window.map4d.Map(_this3.mapDomRef, options);
821
882
 
822
- if (_this2.props.onMapReady) {
823
- _this2.props.onMapReady(_this2.mapRef, _this2.mapKey);
883
+ if (_this3.props.onMapReady) {
884
+ _this3.props.onMapReady(_this3.mapRef, _this3.mapKey);
824
885
  }
825
886
 
826
- _this2.setState({
827
- map: _this2.mapRef
887
+ _this3.registerEvent();
888
+
889
+ _this3.setState({
890
+ map: _this3.mapRef
828
891
  });
829
892
  } else {
830
893
  console.error("MFMap: map element is NOT found");
@@ -850,10 +913,9 @@ var MFMap = /*#__PURE__*/function (_React$Component) {
850
913
  }
851
914
 
852
915
  this.url = url;
853
-
854
- var newContext = _extends({}, this.context);
855
-
856
- newContext.map = this.state.map;
916
+ var newContext = {
917
+ map: this.state.map
918
+ };
857
919
  return React.createElement(Map4dContext.Provider, {
858
920
  value: newContext
859
921
  }, React.createElement("div", {
@@ -890,7 +952,8 @@ var MFMarker = function MFMarker(props) {
890
952
  iconView = props.iconView,
891
953
  userInteractionEnabled = props.userInteractionEnabled,
892
954
  map = props.map,
893
- onCreated = props.onCreated;
955
+ onCreated = props.onCreated,
956
+ onClick = props.onClick;
894
957
  var map4dContext = useContext(Map4dContext);
895
958
  var markerClusterContext = useContext(MarkerClusterContext);
896
959
  var theMap = map || map4dContext.map;
@@ -925,11 +988,12 @@ var MFMarker = function MFMarker(props) {
925
988
  markerRef.current = new map4d.Marker(option);
926
989
 
927
990
  if (!(markerClusterContext !== null && markerClusterContext !== void 0 && markerClusterContext.addMarker)) {
928
- var _markerRef$current;
929
-
930
- (_markerRef$current = markerRef.current) === null || _markerRef$current === void 0 ? void 0 : _markerRef$current.setMap(theMap);
991
+ markerRef.current.setMap(theMap);
931
992
  }
932
993
 
994
+ markerRef.current.onClick = onClick;
995
+ markerRef.current.onRightClick = props.onRightClick;
996
+ markerRef.current.onDragEnd = props.onDragEnd;
933
997
  onCreated && onCreated(markerRef.current);
934
998
  (markerClusterContext === null || markerClusterContext === void 0 ? void 0 : markerClusterContext.addMarker) && (markerClusterContext === null || markerClusterContext === void 0 ? void 0 : markerClusterContext.addMarker(markerRef.current));
935
999
  }
@@ -937,105 +1001,105 @@ var MFMarker = function MFMarker(props) {
937
1001
  useEffect(function () {
938
1002
  if (theMap) {
939
1003
  if (!(markerClusterContext !== null && markerClusterContext !== void 0 && markerClusterContext.addMarker)) {
940
- var _markerRef$current2;
1004
+ var _markerRef$current;
941
1005
 
942
- (_markerRef$current2 = markerRef.current) === null || _markerRef$current2 === void 0 ? void 0 : _markerRef$current2.setMap(theMap);
1006
+ (_markerRef$current = markerRef.current) === null || _markerRef$current === void 0 ? void 0 : _markerRef$current.setMap(theMap);
943
1007
  }
944
1008
  }
945
1009
 
946
1010
  return function () {
947
1011
  if (!(markerClusterContext !== null && markerClusterContext !== void 0 && markerClusterContext.addMarker)) {
948
- var _markerRef$current3;
1012
+ var _markerRef$current2;
949
1013
 
950
- (_markerRef$current3 = markerRef.current) === null || _markerRef$current3 === void 0 ? void 0 : _markerRef$current3.setMap(null);
1014
+ (_markerRef$current2 = markerRef.current) === null || _markerRef$current2 === void 0 ? void 0 : _markerRef$current2.setMap(null);
951
1015
  }
952
1016
  };
953
1017
  }, [theMap]);
954
1018
  useEffect(function () {
955
1019
  return function () {
956
1020
  if (!(markerClusterContext !== null && markerClusterContext !== void 0 && markerClusterContext.addMarker)) {
957
- var _markerRef$current4;
1021
+ var _markerRef$current3;
958
1022
 
959
- (_markerRef$current4 = markerRef.current) === null || _markerRef$current4 === void 0 ? void 0 : _markerRef$current4.setMap(null);
1023
+ (_markerRef$current3 = markerRef.current) === null || _markerRef$current3 === void 0 ? void 0 : _markerRef$current3.setMap(null);
960
1024
  }
961
1025
 
962
1026
  markerRef.current && (markerClusterContext === null || markerClusterContext === void 0 ? void 0 : markerClusterContext.removeMarker) && (markerClusterContext === null || markerClusterContext === void 0 ? void 0 : markerClusterContext.removeMarker(markerRef.current));
963
1027
  };
964
1028
  }, []);
965
1029
  useEffect(function () {
966
- var _markerRef$current5;
1030
+ var _markerRef$current4;
967
1031
 
968
- (_markerRef$current5 = markerRef.current) === null || _markerRef$current5 === void 0 ? void 0 : _markerRef$current5.setPosition(position);
1032
+ (_markerRef$current4 = markerRef.current) === null || _markerRef$current4 === void 0 ? void 0 : _markerRef$current4.setPosition(position);
969
1033
  }, [position]);
970
1034
  useEffect(function () {
971
- var _markerRef$current6;
1035
+ var _markerRef$current5;
972
1036
 
973
- (_markerRef$current6 = markerRef.current) === null || _markerRef$current6 === void 0 ? void 0 : _markerRef$current6.setVisible(visible);
1037
+ (_markerRef$current5 = markerRef.current) === null || _markerRef$current5 === void 0 ? void 0 : _markerRef$current5.setVisible(visible);
974
1038
  }, [visible]);
975
1039
  useEffect(function () {
976
- var _markerRef$current7;
1040
+ var _markerRef$current6;
977
1041
 
978
- anchor != undefined && ((_markerRef$current7 = markerRef.current) === null || _markerRef$current7 === void 0 ? void 0 : _markerRef$current7.setAnchor(anchor));
1042
+ anchor != undefined && ((_markerRef$current6 = markerRef.current) === null || _markerRef$current6 === void 0 ? void 0 : _markerRef$current6.setAnchor(anchor));
979
1043
  }, [anchor]);
980
1044
  useEffect(function () {
981
- var _markerRef$current8;
1045
+ var _markerRef$current7;
982
1046
 
983
- labelAnchor != undefined && ((_markerRef$current8 = markerRef.current) === null || _markerRef$current8 === void 0 ? void 0 : _markerRef$current8.setLabelAnchor(labelAnchor));
1047
+ labelAnchor != undefined && ((_markerRef$current7 = markerRef.current) === null || _markerRef$current7 === void 0 ? void 0 : _markerRef$current7.setLabelAnchor(labelAnchor));
984
1048
  }, [labelAnchor]);
985
1049
  useEffect(function () {
986
- var _markerRef$current9;
1050
+ var _markerRef$current8;
987
1051
 
988
- icon != undefined && ((_markerRef$current9 = markerRef.current) === null || _markerRef$current9 === void 0 ? void 0 : _markerRef$current9.setIcon(icon));
1052
+ icon != undefined && ((_markerRef$current8 = markerRef.current) === null || _markerRef$current8 === void 0 ? void 0 : _markerRef$current8.setIcon(icon));
989
1053
  }, [icon]);
990
1054
  useEffect(function () {
991
- var _markerRef$current10;
1055
+ var _markerRef$current9;
992
1056
 
993
- elevation != undefined && ((_markerRef$current10 = markerRef.current) === null || _markerRef$current10 === void 0 ? void 0 : _markerRef$current10.setElevation(elevation));
1057
+ elevation != undefined && ((_markerRef$current9 = markerRef.current) === null || _markerRef$current9 === void 0 ? void 0 : _markerRef$current9.setElevation(elevation));
994
1058
  }, [elevation]);
995
1059
  useEffect(function () {
996
- var _markerRef$current11;
1060
+ var _markerRef$current10;
997
1061
 
998
- rotation != undefined && ((_markerRef$current11 = markerRef.current) === null || _markerRef$current11 === void 0 ? void 0 : _markerRef$current11.setRotation(rotation));
1062
+ rotation != undefined && ((_markerRef$current10 = markerRef.current) === null || _markerRef$current10 === void 0 ? void 0 : _markerRef$current10.setRotation(rotation));
999
1063
  }, [rotation]);
1000
1064
  useEffect(function () {
1001
- var _markerRef$current12;
1065
+ var _markerRef$current11;
1002
1066
 
1003
- title != undefined && ((_markerRef$current12 = markerRef.current) === null || _markerRef$current12 === void 0 ? void 0 : _markerRef$current12.setTitle(title));
1067
+ title != undefined && ((_markerRef$current11 = markerRef.current) === null || _markerRef$current11 === void 0 ? void 0 : _markerRef$current11.setTitle(title));
1004
1068
  }, [title]);
1005
1069
  useEffect(function () {
1006
- var _markerRef$current13;
1070
+ var _markerRef$current12;
1007
1071
 
1008
- snippet != undefined && ((_markerRef$current13 = markerRef.current) === null || _markerRef$current13 === void 0 ? void 0 : _markerRef$current13.setSnippet(snippet));
1072
+ snippet != undefined && ((_markerRef$current12 = markerRef.current) === null || _markerRef$current12 === void 0 ? void 0 : _markerRef$current12.setSnippet(snippet));
1009
1073
  }, [snippet]);
1010
1074
  useEffect(function () {
1011
- var _markerRef$current14;
1075
+ var _markerRef$current13;
1012
1076
 
1013
- windowAnchor != undefined && ((_markerRef$current14 = markerRef.current) === null || _markerRef$current14 === void 0 ? void 0 : _markerRef$current14.setWindowAnchor(windowAnchor));
1077
+ windowAnchor != undefined && ((_markerRef$current13 = markerRef.current) === null || _markerRef$current13 === void 0 ? void 0 : _markerRef$current13.setWindowAnchor(windowAnchor));
1014
1078
  }, [windowAnchor]);
1015
1079
  useEffect(function () {
1016
- var _markerRef$current15;
1080
+ var _markerRef$current14;
1017
1081
 
1018
- zIndex != undefined && ((_markerRef$current15 = markerRef.current) === null || _markerRef$current15 === void 0 ? void 0 : _markerRef$current15.setZIndex(zIndex));
1082
+ zIndex != undefined && ((_markerRef$current14 = markerRef.current) === null || _markerRef$current14 === void 0 ? void 0 : _markerRef$current14.setZIndex(zIndex));
1019
1083
  }, [zIndex]);
1020
1084
  useEffect(function () {
1021
- var _markerRef$current16;
1085
+ var _markerRef$current15;
1022
1086
 
1023
- label != undefined && ((_markerRef$current16 = markerRef.current) === null || _markerRef$current16 === void 0 ? void 0 : _markerRef$current16.setLabel(label));
1087
+ label != undefined && ((_markerRef$current15 = markerRef.current) === null || _markerRef$current15 === void 0 ? void 0 : _markerRef$current15.setLabel(label));
1024
1088
  }, [label]);
1025
1089
  useEffect(function () {
1026
- var _markerRef$current17;
1090
+ var _markerRef$current16;
1027
1091
 
1028
- draggable != undefined && ((_markerRef$current17 = markerRef.current) === null || _markerRef$current17 === void 0 ? void 0 : _markerRef$current17.setDraggable(draggable));
1092
+ draggable != undefined && ((_markerRef$current16 = markerRef.current) === null || _markerRef$current16 === void 0 ? void 0 : _markerRef$current16.setDraggable(draggable));
1029
1093
  }, [draggable]);
1030
1094
  useEffect(function () {
1031
- var _markerRef$current18;
1095
+ var _markerRef$current17;
1032
1096
 
1033
- iconView != undefined && ((_markerRef$current18 = markerRef.current) === null || _markerRef$current18 === void 0 ? void 0 : _markerRef$current18.setIconView(iconView));
1097
+ iconView != undefined && ((_markerRef$current17 = markerRef.current) === null || _markerRef$current17 === void 0 ? void 0 : _markerRef$current17.setIconView(iconView));
1034
1098
  }, [iconView]);
1035
1099
  useEffect(function () {
1036
- var _markerRef$current19;
1100
+ var _markerRef$current18;
1037
1101
 
1038
- userInteractionEnabled != undefined && ((_markerRef$current19 = markerRef.current) === null || _markerRef$current19 === void 0 ? void 0 : _markerRef$current19.setUserInteraction(userInteractionEnabled));
1102
+ userInteractionEnabled != undefined && ((_markerRef$current18 = markerRef.current) === null || _markerRef$current18 === void 0 ? void 0 : _markerRef$current18.setUserInteraction(userInteractionEnabled));
1039
1103
  }, [userInteractionEnabled]);
1040
1104
  return null;
1041
1105
  };