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