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