react-map4d-map 1.0.7 → 1.0.8
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.
- package/dist/components/MFMap.d.ts +8 -17
- package/dist/context/Map4dContext.d.ts +2 -2
- package/dist/index.js +97 -143
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +98 -144
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
|
@@ -22,26 +22,17 @@ interface MapProps {
|
|
|
22
22
|
version: string;
|
|
23
23
|
accessKey: string;
|
|
24
24
|
environment?: "dev" | "test" | undefined | null;
|
|
25
|
-
onMapReady
|
|
25
|
+
onMapReady?: (map: any, key?: string) => void;
|
|
26
26
|
onClickLocation?: (args: any) => void;
|
|
27
27
|
onRightClickLocation?: (args: any) => void;
|
|
28
28
|
onCameraChanging?: (args: any) => void;
|
|
29
29
|
onTilesLoaded?: (args: any) => void;
|
|
30
|
+
children: any;
|
|
30
31
|
}
|
|
31
|
-
declare
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
url: string | null;
|
|
38
|
-
events: any[];
|
|
39
|
-
constructor(props: MapProps);
|
|
40
|
-
setMapDomRef(e: any): void;
|
|
41
|
-
componentWillUnmount(): void;
|
|
42
|
-
destroy(): void;
|
|
43
|
-
registerEvent(): void;
|
|
44
|
-
createCallback(): void;
|
|
45
|
-
render(): JSX.Element;
|
|
46
|
-
}
|
|
32
|
+
declare const MFMap: {
|
|
33
|
+
(props: MapProps): JSX.Element;
|
|
34
|
+
contextType: React.Context<{
|
|
35
|
+
map: any;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
47
38
|
export default MFMap;
|
package/dist/index.js
CHANGED
|
@@ -709,29 +709,6 @@ var MFImageOverlay = function MFImageOverlay(props) {
|
|
|
709
709
|
return null;
|
|
710
710
|
};
|
|
711
711
|
|
|
712
|
-
function _inheritsLoose(subClass, superClass) {
|
|
713
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
714
|
-
subClass.prototype.constructor = subClass;
|
|
715
|
-
|
|
716
|
-
_setPrototypeOf(subClass, superClass);
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
function _setPrototypeOf(o, p) {
|
|
720
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
721
|
-
o.__proto__ = p;
|
|
722
|
-
return o;
|
|
723
|
-
};
|
|
724
|
-
return _setPrototypeOf(o, p);
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
function _assertThisInitialized(self) {
|
|
728
|
-
if (self === void 0) {
|
|
729
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
return self;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
712
|
function addLibrary(url, id) {
|
|
736
713
|
var scriptId = "script_" + id;
|
|
737
714
|
var exist = document.getElementById(scriptId);
|
|
@@ -758,182 +735,159 @@ var createId = function createId() {
|
|
|
758
735
|
return uuid;
|
|
759
736
|
};
|
|
760
737
|
|
|
761
|
-
var MFMap =
|
|
762
|
-
|
|
738
|
+
var MFMap = function MFMap(props) {
|
|
739
|
+
var mapKey = React.useRef(createId());
|
|
740
|
+
var callback = React.useRef("callback_" + mapKey.current);
|
|
741
|
+
var mapDomRef = React.useRef();
|
|
742
|
+
var mapRef = React.useRef();
|
|
743
|
+
var scriptElement = React.useRef();
|
|
744
|
+
var url = React.useRef();
|
|
745
|
+
var events = React.useRef([]);
|
|
746
|
+
|
|
747
|
+
var _useState = React.useState(),
|
|
748
|
+
map = _useState[0],
|
|
749
|
+
setMap = _useState[1];
|
|
750
|
+
|
|
751
|
+
React.useEffect(function () {
|
|
752
|
+
var createCallback = function createCallback() {
|
|
753
|
+
window[callback.current] = function () {
|
|
754
|
+
if (mapDomRef.current) {
|
|
755
|
+
var options = props.options;
|
|
756
|
+
mapRef.current = new window.map4d.Map(mapDomRef.current, options);
|
|
757
|
+
|
|
758
|
+
if (props.onMapReady) {
|
|
759
|
+
props.onMapReady(mapRef.current, mapKey.current);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
registerEvent();
|
|
763
|
+
setMap(mapRef.current);
|
|
764
|
+
} else {
|
|
765
|
+
console.error("MFMap: map element is NOT found");
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
};
|
|
763
769
|
|
|
764
|
-
|
|
765
|
-
var _this;
|
|
770
|
+
var urlNew = "https://api" + (props.environment ? "-" + props.environment : "") + ".map4d.vn/sdk/map/js?version=" + props.version + "&key=" + props.accessKey + "&callback=" + callback.current;
|
|
766
771
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
map: null
|
|
771
|
-
};
|
|
772
|
-
_this.mapKey = createId();
|
|
773
|
-
_this.callback = "callback_" + _this.mapKey;
|
|
774
|
-
_this.setMapDomRef = _this.setMapDomRef.bind(_assertThisInitialized(_this));
|
|
775
|
-
return _this;
|
|
776
|
-
}
|
|
772
|
+
if (props.mapid) {
|
|
773
|
+
urlNew += "&mapId=" + props.mapid;
|
|
774
|
+
}
|
|
777
775
|
|
|
778
|
-
|
|
776
|
+
createCallback();
|
|
777
|
+
var script = addLibrary(urlNew, mapKey.current);
|
|
779
778
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
779
|
+
if (script) {
|
|
780
|
+
scriptElement.current = script;
|
|
781
|
+
}
|
|
783
782
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
783
|
+
url.current = urlNew;
|
|
784
|
+
return function () {
|
|
785
|
+
var destroy = function destroy() {
|
|
786
|
+
var _events$current, _mapRef$current;
|
|
787
787
|
|
|
788
|
-
|
|
789
|
-
var _this$events, _this$mapRef;
|
|
788
|
+
delete window[callback.current];
|
|
790
789
|
|
|
791
|
-
|
|
790
|
+
if (scriptElement.current != null) {
|
|
791
|
+
scriptElement.current.remove();
|
|
792
|
+
}
|
|
792
793
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
794
|
+
(_events$current = events.current) === null || _events$current === void 0 ? void 0 : _events$current.forEach(function (t) {
|
|
795
|
+
t === null || t === void 0 ? void 0 : t.remove();
|
|
796
|
+
});
|
|
797
|
+
(_mapRef$current = mapRef.current) === null || _mapRef$current === void 0 ? void 0 : _mapRef$current.destroy();
|
|
798
|
+
url.current = undefined;
|
|
799
|
+
};
|
|
796
800
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
((_this$mapRef = this.mapRef) === null || _this$mapRef === void 0 ? void 0 : _this$mapRef.destroy) && this.mapRef.destroy();
|
|
801
|
-
this.url = null;
|
|
802
|
-
};
|
|
801
|
+
destroy();
|
|
802
|
+
};
|
|
803
|
+
}, [props.environment, props.version, props.accessKey]);
|
|
803
804
|
|
|
804
|
-
|
|
805
|
-
var
|
|
806
|
-
_this$mapRef3,
|
|
807
|
-
_this$mapRef4,
|
|
808
|
-
_this2 = this;
|
|
805
|
+
var registerEvent = function registerEvent() {
|
|
806
|
+
var _mapRef$current2, _mapRef$current3, _mapRef$current4;
|
|
809
807
|
|
|
810
|
-
var eventClickMarker = (
|
|
808
|
+
var eventClickMarker = (_mapRef$current2 = mapRef.current) === null || _mapRef$current2 === void 0 ? void 0 : _mapRef$current2.addListener("click", function (args) {
|
|
811
809
|
var _args$marker, _args$marker2;
|
|
812
810
|
|
|
813
811
|
((_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
812
|
}, {
|
|
815
813
|
marker: true
|
|
816
814
|
});
|
|
817
|
-
var eventRightClickMarker = (
|
|
815
|
+
var eventRightClickMarker = (_mapRef$current3 = mapRef.current) === null || _mapRef$current3 === void 0 ? void 0 : _mapRef$current3.addListener("rightClick", function (args) {
|
|
818
816
|
var _args$marker3, _args$marker4;
|
|
819
817
|
|
|
820
818
|
((_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
819
|
}, {
|
|
822
820
|
marker: true
|
|
823
821
|
});
|
|
824
|
-
var eventDragEndMarker = (
|
|
822
|
+
var eventDragEndMarker = (_mapRef$current4 = mapRef.current) === null || _mapRef$current4 === void 0 ? void 0 : _mapRef$current4.addListener("dragEnd", function (args) {
|
|
825
823
|
var _args$marker5, _args$marker6;
|
|
826
824
|
|
|
827
825
|
((_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
826
|
}, {
|
|
829
827
|
marker: true
|
|
830
828
|
});
|
|
831
|
-
|
|
829
|
+
events.current = events.current.concat([eventClickMarker, eventRightClickMarker, eventDragEndMarker]);
|
|
832
830
|
|
|
833
|
-
if (
|
|
834
|
-
var
|
|
831
|
+
if (props.onClickLocation) {
|
|
832
|
+
var _mapRef$current5;
|
|
835
833
|
|
|
836
|
-
var onClickLocation = (
|
|
837
|
-
|
|
834
|
+
var onClickLocation = (_mapRef$current5 = mapRef.current) === null || _mapRef$current5 === void 0 ? void 0 : _mapRef$current5.addListener("click", function (args) {
|
|
835
|
+
props.onClickLocation && props.onClickLocation(args);
|
|
838
836
|
}, {
|
|
839
837
|
location: true
|
|
840
838
|
});
|
|
841
|
-
|
|
839
|
+
events.current.push(onClickLocation);
|
|
842
840
|
}
|
|
843
841
|
|
|
844
|
-
if (
|
|
845
|
-
var
|
|
842
|
+
if (props.onRightClickLocation) {
|
|
843
|
+
var _mapRef$current6;
|
|
846
844
|
|
|
847
|
-
var onRightClickLocation = (
|
|
848
|
-
|
|
845
|
+
var onRightClickLocation = (_mapRef$current6 = mapRef.current) === null || _mapRef$current6 === void 0 ? void 0 : _mapRef$current6.addListener("rightClick", function (args) {
|
|
846
|
+
props.onRightClickLocation && props.onRightClickLocation(args);
|
|
849
847
|
}, {
|
|
850
848
|
location: true
|
|
851
849
|
});
|
|
852
|
-
|
|
850
|
+
events.current.push(onRightClickLocation);
|
|
853
851
|
}
|
|
854
852
|
|
|
855
|
-
if (
|
|
856
|
-
var
|
|
853
|
+
if (props.onTilesLoaded) {
|
|
854
|
+
var _mapRef$current7;
|
|
857
855
|
|
|
858
|
-
var onTilesLoaded = (
|
|
859
|
-
|
|
856
|
+
var onTilesLoaded = (_mapRef$current7 = mapRef.current) === null || _mapRef$current7 === void 0 ? void 0 : _mapRef$current7.addListener("tilesLoaded", function (args) {
|
|
857
|
+
props.onTilesLoaded && props.onTilesLoaded(args);
|
|
860
858
|
}, {
|
|
861
859
|
location: true
|
|
862
860
|
});
|
|
863
|
-
|
|
861
|
+
events.current.push(onTilesLoaded);
|
|
864
862
|
}
|
|
865
863
|
|
|
866
|
-
if (
|
|
867
|
-
var
|
|
864
|
+
if (props.onCameraChanging) {
|
|
865
|
+
var _mapRef$current8;
|
|
868
866
|
|
|
869
|
-
var onCameraChanging = (
|
|
870
|
-
|
|
867
|
+
var onCameraChanging = (_mapRef$current8 = mapRef.current) === null || _mapRef$current8 === void 0 ? void 0 : _mapRef$current8.addListener("cameraChanging", function (args) {
|
|
868
|
+
props.onCameraChanging && props.onCameraChanging(args);
|
|
871
869
|
}, {
|
|
872
870
|
location: true
|
|
873
871
|
});
|
|
874
|
-
|
|
872
|
+
events.current.push(onCameraChanging);
|
|
875
873
|
}
|
|
876
874
|
};
|
|
877
875
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
window[this.callback] = function () {
|
|
882
|
-
if (_this3.mapDomRef) {
|
|
883
|
-
var options = _this3.props.options;
|
|
884
|
-
_this3.mapRef = new window.map4d.Map(_this3.mapDomRef, options);
|
|
885
|
-
|
|
886
|
-
if (_this3.props.onMapReady) {
|
|
887
|
-
_this3.props.onMapReady(_this3.mapRef, _this3.mapKey);
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
_this3.registerEvent();
|
|
891
|
-
|
|
892
|
-
_this3.setState({
|
|
893
|
-
map: _this3.mapRef
|
|
894
|
-
});
|
|
895
|
-
} else {
|
|
896
|
-
console.error("MFMap: map element is NOT found");
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
};
|
|
900
|
-
|
|
901
|
-
_proto.render = function render() {
|
|
902
|
-
var url = "https://api" + (this.props.environment ? "-" + this.props.environment : "") + ".map4d.vn/sdk/map/js?version=" + this.props.version + "&key=" + this.props.accessKey + "&callback=" + this.callback;
|
|
903
|
-
|
|
904
|
-
if (this.props.mapid) {
|
|
905
|
-
url += "&mapId=" + this.props.mapid;
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
if (url != this.url) {
|
|
909
|
-
this.destroy();
|
|
910
|
-
this.createCallback();
|
|
911
|
-
var script = addLibrary(url, this.mapKey);
|
|
912
|
-
|
|
913
|
-
if (script) {
|
|
914
|
-
this.scriptElement = script;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
this.url = url;
|
|
919
|
-
var newContext = {
|
|
920
|
-
map: this.state.map
|
|
921
|
-
};
|
|
922
|
-
return React__default.createElement(Map4dContext.Provider, {
|
|
923
|
-
value: newContext
|
|
924
|
-
}, React__default.createElement("div", {
|
|
925
|
-
style: {
|
|
926
|
-
width: '100%',
|
|
927
|
-
height: '100%',
|
|
928
|
-
display: 'block'
|
|
929
|
-
},
|
|
930
|
-
id: "" + this.mapKey,
|
|
931
|
-
ref: this.setMapDomRef
|
|
932
|
-
}), this.props.children);
|
|
876
|
+
var newContext = {
|
|
877
|
+
map: map
|
|
933
878
|
};
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
}
|
|
879
|
+
return React__default.createElement(Map4dContext.Provider, {
|
|
880
|
+
value: newContext
|
|
881
|
+
}, React__default.createElement("div", {
|
|
882
|
+
style: {
|
|
883
|
+
width: '100%',
|
|
884
|
+
height: '100%',
|
|
885
|
+
display: 'block'
|
|
886
|
+
},
|
|
887
|
+
id: mapKey.current,
|
|
888
|
+
ref: mapDomRef.current
|
|
889
|
+
}), props.children);
|
|
890
|
+
};
|
|
937
891
|
|
|
938
892
|
MFMap.contextType = Map4dContext;
|
|
939
893
|
|