@aibee/crc-bmap 0.0.29 → 0.0.30
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/example/src/main.ts +25 -25
- package/lib/bmap.cjs.min.js +2 -2
- package/lib/bmap.cjs.min.js.map +3 -3
- package/lib/bmap.esm.js +116 -24
- package/lib/bmap.esm.js.map +2 -2
- package/lib/bmap.esm.min.js +2 -2
- package/lib/bmap.esm.min.js.map +3 -3
- package/lib/bmap.min.js +2 -2
- package/lib/bmap.min.js.map +3 -3
- package/lib/src/context.d.ts +6 -0
- package/lib/src/elements/overlay.d.ts +5 -0
- package/lib/src/elements/poi.d.ts +20 -1
- package/lib/src/layer/poi-layer.d.ts +1 -0
- package/lib/src/operations/selection/selection.d.ts +2 -0
- package/package.json +1 -1
package/lib/bmap.esm.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -15,6 +17,7 @@ var __spreadValues = (a, b) => {
|
|
|
15
17
|
}
|
|
16
18
|
return a;
|
|
17
19
|
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
18
21
|
var __publicField = (obj, key, value) => {
|
|
19
22
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
20
23
|
return value;
|
|
@@ -646,10 +649,13 @@ var Overlay = class extends EventDispatcher {
|
|
|
646
649
|
__publicField(this, "div");
|
|
647
650
|
__publicField(this, "element");
|
|
648
651
|
__publicField(this, "position", new Vector33());
|
|
652
|
+
__publicField(this, "clientPos", { x: 0, y: 0 });
|
|
653
|
+
__publicField(this, "visible", true);
|
|
649
654
|
__publicField(this, "onUpdate", () => {
|
|
650
655
|
const vector = this.getPosition();
|
|
651
|
-
const {
|
|
652
|
-
const { x, y } = vector3ToDevice(vector, this.context.camera,
|
|
656
|
+
const { width, height } = this.context.clientSize;
|
|
657
|
+
const { x, y } = vector3ToDevice(vector, this.context.camera, width, height);
|
|
658
|
+
this.clientPos = { x, y };
|
|
653
659
|
this.div.style.left = `${x}px`;
|
|
654
660
|
this.div.style.top = `${y}px`;
|
|
655
661
|
});
|
|
@@ -664,12 +670,17 @@ var Overlay = class extends EventDispatcher {
|
|
|
664
670
|
}
|
|
665
671
|
bindElement(element) {
|
|
666
672
|
this.element = element;
|
|
673
|
+
this.onUpdate();
|
|
667
674
|
}
|
|
668
675
|
unBindElement() {
|
|
669
676
|
this.element = void 0;
|
|
670
677
|
}
|
|
671
678
|
setVisible(visible, display = "block") {
|
|
679
|
+
if (visible === this.visible) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
672
682
|
this.div.style.display = visible ? display : "none";
|
|
683
|
+
this.visible = visible;
|
|
673
684
|
}
|
|
674
685
|
setOpacity(opacity) {
|
|
675
686
|
this.div.style.opacity = `${opacity}`;
|
|
@@ -706,23 +717,26 @@ var defaultOptions2 = {
|
|
|
706
717
|
level: 1,
|
|
707
718
|
collision_enable: true,
|
|
708
719
|
opacity: 1,
|
|
709
|
-
id: ""
|
|
720
|
+
id: "",
|
|
721
|
+
position: { x: 0, y: 0, z: 0 }
|
|
710
722
|
};
|
|
711
723
|
var Poi = class extends Object3D4 {
|
|
712
724
|
constructor(context, options) {
|
|
725
|
+
var _a, _b, _c;
|
|
713
726
|
super();
|
|
714
727
|
this.context = context;
|
|
715
728
|
__publicField(this, "textDiv");
|
|
716
729
|
__publicField(this, "img");
|
|
717
730
|
__publicField(this, "overlay");
|
|
718
731
|
__publicField(this, "options");
|
|
732
|
+
__publicField(this, "size", { width: 0, height: 0 });
|
|
719
733
|
__publicField(this, "_changePosition", () => {
|
|
720
734
|
this.overlay.div.style.transform = `translate3d(-50%, ${this.options.icon ? "-100%" : "-50%"}, 0)`;
|
|
721
735
|
});
|
|
722
736
|
this.options = proxyOptions(merge2({}, defaultOptions2, options), this);
|
|
737
|
+
this.position.set(((_a = options.position) == null ? void 0 : _a.x) || 0, ((_b = options.position) == null ? void 0 : _b.y) || 0, ((_c = options.position) == null ? void 0 : _c.z) || 0);
|
|
723
738
|
this.overlay = new Overlay(this.context);
|
|
724
739
|
this.overlay.bindElement(this);
|
|
725
|
-
this._changePosition();
|
|
726
740
|
this.registryEvent();
|
|
727
741
|
this.initDiv();
|
|
728
742
|
this.addEventListener("change-icon", ({ value }) => {
|
|
@@ -735,15 +749,35 @@ var Poi = class extends Object3D4 {
|
|
|
735
749
|
} else {
|
|
736
750
|
this.img && this.overlay.div.removeChild(this.img);
|
|
737
751
|
this.img = void 0;
|
|
752
|
+
this.resetSize();
|
|
738
753
|
}
|
|
739
754
|
});
|
|
740
755
|
this.addEventListener("change-text", ({ value }) => {
|
|
741
756
|
this.overlay.div.removeChild(this.textDiv);
|
|
742
757
|
this.overlay.div.appendChild(this.initText());
|
|
758
|
+
this.resetSize();
|
|
743
759
|
});
|
|
744
760
|
this.addEventListener("change-opacity", ({ value }) => {
|
|
745
761
|
this.overlay.setOpacity(value);
|
|
746
762
|
});
|
|
763
|
+
this.addEventListener("change-icon_size", ({ value }) => {
|
|
764
|
+
if (this.img) {
|
|
765
|
+
this.img.style.width = `${(value == null ? void 0 : value[0]) || 32}px`;
|
|
766
|
+
this.img.style.height = `${(value == null ? void 0 : value[1]) || 32}px`;
|
|
767
|
+
this.resetSize();
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
resetSize() {
|
|
772
|
+
const { width, height } = this.overlay.div.getBoundingClientRect();
|
|
773
|
+
this.size = {
|
|
774
|
+
width,
|
|
775
|
+
height
|
|
776
|
+
};
|
|
777
|
+
this._changePosition();
|
|
778
|
+
}
|
|
779
|
+
get clientPos() {
|
|
780
|
+
return this.overlay.clientPos;
|
|
747
781
|
}
|
|
748
782
|
initDiv() {
|
|
749
783
|
const div = this.overlay.div;
|
|
@@ -758,6 +792,7 @@ var Poi = class extends Object3D4 {
|
|
|
758
792
|
div.style.alignItems = `center`;
|
|
759
793
|
div.style.pointerEvents = `none`;
|
|
760
794
|
this.overlay.setOpacity(this.options.opacity);
|
|
795
|
+
this.resetSize();
|
|
761
796
|
return div;
|
|
762
797
|
}
|
|
763
798
|
getPosition() {
|
|
@@ -788,22 +823,33 @@ var Poi = class extends Object3D4 {
|
|
|
788
823
|
img.setAttribute("src", this.options.icon);
|
|
789
824
|
img.style.width = `${((_a = this.options.icon_size) == null ? void 0 : _a[0]) || 32}px`;
|
|
790
825
|
img.style.height = `${((_b = this.options.icon_size) == null ? void 0 : _b[1]) || 32}px`;
|
|
826
|
+
img.onload = () => {
|
|
827
|
+
this.resetSize();
|
|
828
|
+
};
|
|
791
829
|
this.img = img;
|
|
792
830
|
return img;
|
|
793
831
|
}
|
|
794
832
|
registryEvent() {
|
|
795
|
-
this.context.addEventListener("update", this._changePosition);
|
|
796
833
|
}
|
|
797
834
|
unRegistryEvent() {
|
|
798
|
-
this.context.removeEventListener("update", this._changePosition);
|
|
799
835
|
}
|
|
800
836
|
setVisible(visible) {
|
|
801
837
|
this.overlay.setVisible(visible, "flex");
|
|
802
838
|
}
|
|
803
839
|
getBox() {
|
|
804
|
-
|
|
840
|
+
const { width, height } = this.size;
|
|
841
|
+
const { x, y } = this.overlay.clientPos;
|
|
842
|
+
return {
|
|
843
|
+
left: x - width / 2,
|
|
844
|
+
right: x + width / 2,
|
|
845
|
+
top: this.options.icon ? y - height : y - height / 2,
|
|
846
|
+
bottom: this.options.icon ? y : y + height / 2
|
|
847
|
+
};
|
|
805
848
|
}
|
|
806
849
|
isContain(x, y) {
|
|
850
|
+
if (!this.overlay.visible) {
|
|
851
|
+
return false;
|
|
852
|
+
}
|
|
807
853
|
const box = this.getBox();
|
|
808
854
|
return x >= box.left && x <= box.right && y >= box.top && y <= box.bottom;
|
|
809
855
|
}
|
|
@@ -882,14 +928,19 @@ var GraphicLayer = class extends Layer {
|
|
|
882
928
|
};
|
|
883
929
|
|
|
884
930
|
// src/layer/poi-layer.ts
|
|
931
|
+
import { debounce } from "lodash";
|
|
885
932
|
var PoiLayer = class extends Layer {
|
|
886
933
|
constructor(context) {
|
|
887
934
|
super(context);
|
|
888
935
|
__publicField(this, "pois", []);
|
|
936
|
+
__publicField(this, "debounceCollisionDetection");
|
|
889
937
|
__publicField(this, "onUpdate", () => {
|
|
890
|
-
|
|
938
|
+
Promise.resolve().then(() => {
|
|
939
|
+
this.collisionDetection();
|
|
940
|
+
});
|
|
891
941
|
});
|
|
892
942
|
this.registryEvent();
|
|
943
|
+
this.debounceCollisionDetection = debounce(this.collisionDetection, 10);
|
|
893
944
|
}
|
|
894
945
|
clear() {
|
|
895
946
|
super.clear();
|
|
@@ -902,6 +953,9 @@ var PoiLayer = class extends Layer {
|
|
|
902
953
|
this.pushPoi(poi);
|
|
903
954
|
poi.addEventListener("change-level", () => this.changePoiLevelOrCollisionEnable(poi));
|
|
904
955
|
poi.addEventListener("change-collision_enable", () => this.changePoiLevelOrCollisionEnable(poi));
|
|
956
|
+
Promise.resolve().then(() => {
|
|
957
|
+
this.debounceCollisionDetection();
|
|
958
|
+
});
|
|
905
959
|
return poi;
|
|
906
960
|
}
|
|
907
961
|
changePoiLevelOrCollisionEnable(poi) {
|
|
@@ -966,20 +1020,28 @@ var PoiLayer = class extends Layer {
|
|
|
966
1020
|
* 碰撞检测
|
|
967
1021
|
*/
|
|
968
1022
|
collisionDetection() {
|
|
1023
|
+
const { clientSize: { width, height } } = this.context;
|
|
969
1024
|
const range = [];
|
|
970
|
-
this.pois.
|
|
971
|
-
item.
|
|
1025
|
+
const pois = this.pois.filter((item) => {
|
|
1026
|
+
const { x, y } = item.clientPos;
|
|
1027
|
+
return !(x < 0 || x > width || y < 0 || y > height);
|
|
1028
|
+
});
|
|
1029
|
+
pois.forEach((item, index) => {
|
|
972
1030
|
const { left, right, top, bottom } = item.getBox();
|
|
973
1031
|
if (index === 0) {
|
|
974
1032
|
range.push({ left, right, top, bottom });
|
|
975
1033
|
return;
|
|
976
1034
|
}
|
|
977
1035
|
const valid = range.some((box) => {
|
|
978
|
-
const xIntersect = right < box.left || left > box.right;
|
|
979
|
-
|
|
980
|
-
|
|
1036
|
+
const xIntersect = right < box.right && right > box.left || left > box.left && left < box.right || left === box.left && right === box.right;
|
|
1037
|
+
if (xIntersect) {
|
|
1038
|
+
const yIntersect = bottom <= box.bottom && bottom > box.top || top >= box.top && top < box.bottom;
|
|
1039
|
+
return yIntersect;
|
|
1040
|
+
}
|
|
1041
|
+
return false;
|
|
981
1042
|
});
|
|
982
|
-
item.setVisible(valid);
|
|
1043
|
+
item.setVisible(!valid);
|
|
1044
|
+
range.push({ left, right, top, bottom });
|
|
983
1045
|
});
|
|
984
1046
|
}
|
|
985
1047
|
registryEvent() {
|
|
@@ -991,6 +1053,8 @@ var PoiLayer = class extends Layer {
|
|
|
991
1053
|
dispose() {
|
|
992
1054
|
this.pois.forEach((item) => item.dispose());
|
|
993
1055
|
this.pois.length = 0;
|
|
1056
|
+
this.debounceCollisionDetection = () => {
|
|
1057
|
+
};
|
|
994
1058
|
super.dispose();
|
|
995
1059
|
this.unRegistryEvent();
|
|
996
1060
|
}
|
|
@@ -1694,10 +1758,22 @@ var Selection = class extends EventDispatcher3 {
|
|
|
1694
1758
|
__publicField(this, "boxSelection");
|
|
1695
1759
|
__publicField(this, "prevPanStatus");
|
|
1696
1760
|
__publicField(this, "prevRotateStatus");
|
|
1761
|
+
__publicField(this, "downPoint", null);
|
|
1697
1762
|
__publicField(this, "onPointerDown", (e) => {
|
|
1698
|
-
|
|
1763
|
+
this.downPoint = { x: e.offsetX, y: e.offsetY };
|
|
1764
|
+
});
|
|
1765
|
+
__publicField(this, "onPointerUp", (e) => {
|
|
1766
|
+
if (!this.downPoint) {
|
|
1767
|
+
return;
|
|
1768
|
+
}
|
|
1769
|
+
const { offsetX, offsetY } = e;
|
|
1770
|
+
const { x, y } = this.downPoint;
|
|
1771
|
+
if (Math.sqrt(__pow(x - offsetX, 2) + __pow(y - offsetY, 2)) > 3) {
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
const { graphics } = this.context.getGraphicsByDeviceXy(offsetX, offsetY);
|
|
1699
1775
|
const graphicIdSet = new Set(graphics.map((item) => item.options.id));
|
|
1700
|
-
const pois = this.context.getPoisByDeviceXy(
|
|
1776
|
+
const pois = this.context.getPoisByDeviceXy(offsetX, offsetY);
|
|
1701
1777
|
pois.forEach((item) => {
|
|
1702
1778
|
var _a;
|
|
1703
1779
|
if (!graphicIdSet.has(item.options.id)) {
|
|
@@ -1713,6 +1789,7 @@ var Selection = class extends EventDispatcher3 {
|
|
|
1713
1789
|
}
|
|
1714
1790
|
graphics.forEach((item) => this._list.add(item));
|
|
1715
1791
|
this.selectEnd();
|
|
1792
|
+
this.downPoint = null;
|
|
1716
1793
|
});
|
|
1717
1794
|
__publicField(this, "onKeyDown", (e) => {
|
|
1718
1795
|
if (e.key === "Control") {
|
|
@@ -1749,12 +1826,14 @@ var Selection = class extends EventDispatcher3 {
|
|
|
1749
1826
|
}
|
|
1750
1827
|
registryEvent() {
|
|
1751
1828
|
this.context.container.addEventListener("pointerdown", this.onPointerDown);
|
|
1829
|
+
this.context.container.addEventListener("pointerup", this.onPointerUp);
|
|
1752
1830
|
window.addEventListener("keydown", this.onKeyDown);
|
|
1753
1831
|
window.addEventListener("keyup", this.onKeyUp);
|
|
1754
1832
|
this.boxSelection.addEventListener("selected", this.onBoxSelected);
|
|
1755
1833
|
}
|
|
1756
1834
|
unRegistryEvent() {
|
|
1757
1835
|
this.context.container.removeEventListener("pointerdown", this.onPointerDown);
|
|
1836
|
+
this.context.container.removeEventListener("pointerup", this.onPointerUp);
|
|
1758
1837
|
window.removeEventListener("keydown", this.onKeyDown);
|
|
1759
1838
|
window.removeEventListener("keyup", this.onKeyUp);
|
|
1760
1839
|
this.boxSelection.removeEventListener("selected", this.onBoxSelected);
|
|
@@ -1836,7 +1915,6 @@ var HoverHelper = class extends EventDispatcher4 {
|
|
|
1836
1915
|
|
|
1837
1916
|
// src/context.ts
|
|
1838
1917
|
var Context = class extends EventDispatcher5 {
|
|
1839
|
-
// zoom=1的时候,100M对应的像素个数
|
|
1840
1918
|
constructor(container, config) {
|
|
1841
1919
|
super();
|
|
1842
1920
|
this.container = container;
|
|
@@ -1853,6 +1931,11 @@ var Context = class extends EventDispatcher5 {
|
|
|
1853
1931
|
__publicField(this, "selection");
|
|
1854
1932
|
__publicField(this, "hoverHelper");
|
|
1855
1933
|
__publicField(this, "basicRatio");
|
|
1934
|
+
// zoom=1的时候,100M对应的像素个数
|
|
1935
|
+
__publicField(this, "clientSize", {
|
|
1936
|
+
width: 0,
|
|
1937
|
+
height: 0
|
|
1938
|
+
});
|
|
1856
1939
|
__publicField(this, "onWindowResize", () => {
|
|
1857
1940
|
const { container, camera, renderer } = this;
|
|
1858
1941
|
const { clientWidth: w, clientHeight: h } = container;
|
|
@@ -1862,6 +1945,7 @@ var Context = class extends EventDispatcher5 {
|
|
|
1862
1945
|
camera.bottom = -h / 2;
|
|
1863
1946
|
camera.updateProjectionMatrix();
|
|
1864
1947
|
renderer.setSize(w, h);
|
|
1948
|
+
this.resizeClientSize(w, h);
|
|
1865
1949
|
});
|
|
1866
1950
|
__publicField(this, "onClick", (e) => {
|
|
1867
1951
|
const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
|
|
@@ -1872,19 +1956,20 @@ var Context = class extends EventDispatcher5 {
|
|
|
1872
1956
|
position
|
|
1873
1957
|
});
|
|
1874
1958
|
}
|
|
1875
|
-
|
|
1959
|
+
console.log("onClick", e.offsetX, e.offsetY);
|
|
1960
|
+
const pois = this.getPoisByDeviceXy(e.offsetX, e.offsetY);
|
|
1876
1961
|
if (pois.length) {
|
|
1877
1962
|
this.dispatchEvent({ type: "poi-click", pois });
|
|
1878
1963
|
}
|
|
1879
1964
|
});
|
|
1880
1965
|
__publicField(this, "onPointerover", (e) => {
|
|
1881
1966
|
const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
|
|
1882
|
-
const pois = this.getPoisByDeviceXy(e.
|
|
1967
|
+
const pois = this.getPoisByDeviceXy(e.offsetX, e.offsetY);
|
|
1883
1968
|
this.dispatchEvent({ type: "pointer-over", graphics, pois, position });
|
|
1884
1969
|
});
|
|
1885
1970
|
__publicField(this, "onPointermove", (e) => {
|
|
1886
1971
|
const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
|
|
1887
|
-
const pois = this.getPoisByDeviceXy(e.
|
|
1972
|
+
const pois = this.getPoisByDeviceXy(e.offsetX, e.offsetY);
|
|
1888
1973
|
this.dispatchEvent({ type: "pointer-move", graphics, pois, position });
|
|
1889
1974
|
});
|
|
1890
1975
|
__publicField(this, "onPointerleave", () => {
|
|
@@ -1901,8 +1986,15 @@ var Context = class extends EventDispatcher5 {
|
|
|
1901
1986
|
this.init();
|
|
1902
1987
|
this.selection = new Selection(this);
|
|
1903
1988
|
this.hoverHelper = new HoverHelper(this);
|
|
1989
|
+
this.resizeClientSize();
|
|
1904
1990
|
this.registryEvent();
|
|
1905
1991
|
}
|
|
1992
|
+
resizeClientSize(width, height) {
|
|
1993
|
+
this.clientSize = {
|
|
1994
|
+
width: width || this.container.clientWidth,
|
|
1995
|
+
height: height || this.container.clientHeight
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1906
1998
|
init() {
|
|
1907
1999
|
const { clientWidth: w, clientHeight: h } = this.container;
|
|
1908
2000
|
this.camera = initCamera(w, h);
|
|
@@ -1916,6 +2008,7 @@ var Context = class extends EventDispatcher5 {
|
|
|
1916
2008
|
const polarAngle = this.control.getPolarAngle();
|
|
1917
2009
|
(_a = this.currentFloor) == null ? void 0 : _a.setShadowOpacity(polarAngle / this.config.control.maxPolar);
|
|
1918
2010
|
this.dispatchEvent({ type: "change-ratio", px: (this.basicRatio || 0) * this.camera.zoom });
|
|
2011
|
+
this.dispatchEvent({ type: "control-change" });
|
|
1919
2012
|
});
|
|
1920
2013
|
}
|
|
1921
2014
|
/**
|
|
@@ -2359,11 +2452,10 @@ var BMap = class extends EventDispatcher6 {
|
|
|
2359
2452
|
if (options.id === void 0) {
|
|
2360
2453
|
options.id = graphic.options.id;
|
|
2361
2454
|
}
|
|
2362
|
-
const poi = this.context.currentFloor.addPoi(options);
|
|
2363
2455
|
const position = graphic.getCenter();
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2456
|
+
const poi = this.context.currentFloor.addPoi(__spreadProps(__spreadValues({}, options), {
|
|
2457
|
+
position: __spreadProps(__spreadValues({}, position), { z: position.z + graphic.options.height / 2 })
|
|
2458
|
+
}));
|
|
2367
2459
|
return poi;
|
|
2368
2460
|
}
|
|
2369
2461
|
return null;
|