@aibee/crc-bmap 0.0.89 → 0.0.91
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 +2 -2
- package/lib/bmap.cjs.min.js +16 -4
- package/lib/bmap.cjs.min.js.map +3 -3
- package/lib/bmap.esm.js +109 -20
- package/lib/bmap.esm.js.map +2 -2
- package/lib/bmap.esm.min.js +16 -4
- package/lib/bmap.esm.min.js.map +3 -3
- package/lib/bmap.min.js +16 -4
- package/lib/bmap.min.js.map +3 -3
- package/lib/src/elements/graphic.d.ts +4 -0
- package/lib/src/elements/poi.d.ts +3 -0
- package/lib/src/factory/material.d.ts +1 -1
- package/package.json +1 -1
package/lib/bmap.esm.js
CHANGED
|
@@ -500,7 +500,8 @@ import {
|
|
|
500
500
|
Box3,
|
|
501
501
|
Vector3 as Vector32,
|
|
502
502
|
BufferGeometry,
|
|
503
|
-
LineSegments
|
|
503
|
+
LineSegments,
|
|
504
|
+
Ray
|
|
504
505
|
} from "three";
|
|
505
506
|
var defaultOptions = {
|
|
506
507
|
id: "",
|
|
@@ -642,7 +643,7 @@ var Graphic = class extends Object3D {
|
|
|
642
643
|
}
|
|
643
644
|
getPosition() {
|
|
644
645
|
const center2 = this.getCenter();
|
|
645
|
-
center2.setZ(center2.z + this.options.height);
|
|
646
|
+
center2.setZ(center2.z + this.options.height / 2);
|
|
646
647
|
return center2;
|
|
647
648
|
}
|
|
648
649
|
init() {
|
|
@@ -685,31 +686,67 @@ var Graphic = class extends Object3D {
|
|
|
685
686
|
this.material = [material, material1];
|
|
686
687
|
return [material, material1];
|
|
687
688
|
}
|
|
689
|
+
// createMesh(pos: Vector3, color = 0xff0000) {
|
|
690
|
+
// const geometry = new BoxGeometry(1, 1, 1)
|
|
691
|
+
// const material = new MeshBasicMaterial({ color })
|
|
692
|
+
// const mesh = new Mesh(geometry, material)
|
|
693
|
+
// mesh.position.copy(pos)
|
|
694
|
+
// this.context.scene.add(mesh)
|
|
695
|
+
// }
|
|
696
|
+
// createLine(points: Vector3[], color = 0xff0000) {
|
|
697
|
+
// const material = new LineBasicMaterial({
|
|
698
|
+
// color: color
|
|
699
|
+
// });
|
|
700
|
+
// const geometry = new BufferGeometry().setFromPoints(points);
|
|
701
|
+
// const line = new Line( geometry, material );
|
|
702
|
+
// this.context.scene.add(line)
|
|
703
|
+
// }
|
|
704
|
+
getMaxAndMin(pos, dir) {
|
|
705
|
+
const box = new Box3().setFromObject(this);
|
|
706
|
+
const minOrigin = pos.clone().add(dir.clone().multiplyScalar(1e3));
|
|
707
|
+
const raycaster = new Ray(minOrigin, dir.clone().multiplyScalar(-1));
|
|
708
|
+
const min = new Vector32();
|
|
709
|
+
raycaster.intersectBox(box, min);
|
|
710
|
+
const maxOrigin = pos.clone().add(dir.clone().multiplyScalar(-1e3));
|
|
711
|
+
const raycaster2 = new Ray(maxOrigin, dir.clone());
|
|
712
|
+
const max = new Vector32();
|
|
713
|
+
raycaster2.intersectBox(box, max);
|
|
714
|
+
return {
|
|
715
|
+
max,
|
|
716
|
+
min
|
|
717
|
+
};
|
|
718
|
+
}
|
|
688
719
|
initGradualMaterial() {
|
|
689
720
|
const { max, min } = new Box3().setFromObject(this);
|
|
690
721
|
const _max = max.clone().sub(min);
|
|
691
722
|
const maxValue = Math.max(_max.x, _max.y, _max.z) / 2;
|
|
723
|
+
const pos = this.getPosition();
|
|
724
|
+
const dir = new Vector32(-1, 0.2, 0).normalize();
|
|
725
|
+
const { max: __max, min: _min } = this.getMaxAndMin(pos, dir);
|
|
692
726
|
const material = this.context.materialFactory.createShaderMaterial({
|
|
693
727
|
gradualColor: this.options.gradualColor,
|
|
694
728
|
center: this.getPosition(),
|
|
695
729
|
maxValue,
|
|
696
730
|
opacity: this.options.fillOpacity,
|
|
697
731
|
direction: new Vector32(-1, 0.2, 0),
|
|
698
|
-
max,
|
|
699
|
-
min
|
|
732
|
+
max: __max,
|
|
733
|
+
min: _min
|
|
700
734
|
});
|
|
701
735
|
if (this.options.height <= 0.1) {
|
|
702
736
|
this.material = material;
|
|
703
737
|
return material;
|
|
704
738
|
}
|
|
739
|
+
const center2 = this.getCenter();
|
|
740
|
+
const dir2 = new Vector32(-1, 0.2, 1).normalize();
|
|
741
|
+
const { max: ___max, min: __min } = this.getMaxAndMin(center2, dir2);
|
|
705
742
|
const material1 = this.context.materialFactory.createShaderMaterial({
|
|
706
743
|
gradualColor: [darkenColor(this.options.gradualColor[0], this.options.colorFactor), darkenColor(this.options.gradualColor[1], this.options.colorFactor)],
|
|
707
744
|
center: this.getCenter(),
|
|
708
745
|
maxValue,
|
|
709
746
|
opacity: this.options.fillOpacity,
|
|
710
747
|
direction: new Vector32(-1, 0.2, 1),
|
|
711
|
-
max,
|
|
712
|
-
min
|
|
748
|
+
max: ___max,
|
|
749
|
+
min: __min
|
|
713
750
|
});
|
|
714
751
|
this.material = [material, material1];
|
|
715
752
|
return [material, material1];
|
|
@@ -969,6 +1006,7 @@ var Overlay = class extends EventDispatcher {
|
|
|
969
1006
|
var defaultOptions3 = {
|
|
970
1007
|
texts: [{ text: "" }],
|
|
971
1008
|
level: 1,
|
|
1009
|
+
icon_position: "bottom",
|
|
972
1010
|
collision_enable: true,
|
|
973
1011
|
opacity: 1,
|
|
974
1012
|
id: "",
|
|
@@ -1010,7 +1048,7 @@ var Poi = class extends EventDispatcher2 {
|
|
|
1010
1048
|
this.addEventListener("change-icon", ({ value }) => {
|
|
1011
1049
|
if (value) {
|
|
1012
1050
|
if (!this.img) {
|
|
1013
|
-
this.
|
|
1051
|
+
this.addIcon();
|
|
1014
1052
|
this._changePosition();
|
|
1015
1053
|
} else {
|
|
1016
1054
|
this.img.setAttribute("src", value);
|
|
@@ -1024,11 +1062,7 @@ var Poi = class extends EventDispatcher2 {
|
|
|
1024
1062
|
});
|
|
1025
1063
|
this.addEventListener("change-texts", ({ value }) => {
|
|
1026
1064
|
this.div.removeChild(this.textDiv);
|
|
1027
|
-
|
|
1028
|
-
this.div.insertBefore(this.initText(), this.div.firstChild);
|
|
1029
|
-
} else {
|
|
1030
|
-
this.div.appendChild(this.initText());
|
|
1031
|
-
}
|
|
1065
|
+
this.addText();
|
|
1032
1066
|
this.resetSize();
|
|
1033
1067
|
});
|
|
1034
1068
|
this.addEventListener("change-opacity", ({ value }) => {
|
|
@@ -1086,9 +1120,10 @@ var Poi = class extends EventDispatcher2 {
|
|
|
1086
1120
|
}
|
|
1087
1121
|
initDiv() {
|
|
1088
1122
|
const div = document.createElement("div");
|
|
1089
|
-
|
|
1123
|
+
this.div = div;
|
|
1124
|
+
this.addText();
|
|
1090
1125
|
if (this.options.icon) {
|
|
1091
|
-
|
|
1126
|
+
this.addIcon();
|
|
1092
1127
|
}
|
|
1093
1128
|
div.style.fontSize = `12px`;
|
|
1094
1129
|
div.style.textShadow = `#fff 1px 0 0, #fff 0 1px 0, #fff -1px 0 0, #fff 0 -1px 0`;
|
|
@@ -1101,10 +1136,35 @@ var Poi = class extends EventDispatcher2 {
|
|
|
1101
1136
|
this.overlay.div.style.pointerEvents = `none`;
|
|
1102
1137
|
this.overlay.div.style.userSelect = `none`;
|
|
1103
1138
|
this.overlay.div.appendChild(div);
|
|
1104
|
-
this.div = div;
|
|
1105
1139
|
this.resetSize();
|
|
1106
1140
|
return div;
|
|
1107
1141
|
}
|
|
1142
|
+
addIcon() {
|
|
1143
|
+
if (!this.img) {
|
|
1144
|
+
const icon = this.initIcon();
|
|
1145
|
+
if (this.options.icon_position === "top") {
|
|
1146
|
+
if (this.div.firstChild) {
|
|
1147
|
+
this.div.insertBefore(icon, this.div.firstChild);
|
|
1148
|
+
} else {
|
|
1149
|
+
this.div.appendChild(icon);
|
|
1150
|
+
}
|
|
1151
|
+
} else {
|
|
1152
|
+
this.div.appendChild(icon);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
addText() {
|
|
1157
|
+
const text = this.initText();
|
|
1158
|
+
if (this.options.icon_position === "top") {
|
|
1159
|
+
this.div.appendChild(text);
|
|
1160
|
+
} else {
|
|
1161
|
+
if (this.div.firstChild) {
|
|
1162
|
+
this.div.insertBefore(text, this.div.firstChild);
|
|
1163
|
+
} else {
|
|
1164
|
+
this.div.appendChild(text);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1108
1168
|
getPosition() {
|
|
1109
1169
|
return this.position;
|
|
1110
1170
|
}
|
|
@@ -2419,7 +2479,14 @@ var HoverHelper = class extends EventDispatcher5 {
|
|
|
2419
2479
|
};
|
|
2420
2480
|
|
|
2421
2481
|
// src/factory/material.ts
|
|
2422
|
-
import {
|
|
2482
|
+
import {
|
|
2483
|
+
Color as Color4,
|
|
2484
|
+
LineBasicMaterial as LineBasicMaterial2,
|
|
2485
|
+
MeshStandardMaterial as MeshStandardMaterial2,
|
|
2486
|
+
MeshBasicMaterial as MeshBasicMaterial3,
|
|
2487
|
+
ShaderMaterial as ShaderMaterial2,
|
|
2488
|
+
DoubleSide as DoubleSide4
|
|
2489
|
+
} from "three";
|
|
2423
2490
|
function vectorToString(vector) {
|
|
2424
2491
|
return `${vector.x}-${vector.y}-${vector.z}`;
|
|
2425
2492
|
}
|
|
@@ -2476,8 +2543,18 @@ var MaterialFactory = class {
|
|
|
2476
2543
|
this.meshBasicMaterialMap.set(key, material);
|
|
2477
2544
|
return material;
|
|
2478
2545
|
}
|
|
2479
|
-
createShaderMaterial({
|
|
2480
|
-
|
|
2546
|
+
createShaderMaterial({
|
|
2547
|
+
gradualColor,
|
|
2548
|
+
center: center2,
|
|
2549
|
+
maxValue,
|
|
2550
|
+
opacity,
|
|
2551
|
+
direction,
|
|
2552
|
+
max,
|
|
2553
|
+
min
|
|
2554
|
+
}) {
|
|
2555
|
+
const key = `${gradualColor.toString()}-${vectorToString(
|
|
2556
|
+
center2
|
|
2557
|
+
)}-${maxValue}-${opacity}-${vectorToString(direction)}`;
|
|
2481
2558
|
if (this.shaderMaterialMap.has(key)) {
|
|
2482
2559
|
return this.shaderMaterialMap.get(key);
|
|
2483
2560
|
}
|
|
@@ -2492,11 +2569,23 @@ var MaterialFactory = class {
|
|
|
2492
2569
|
varying vec3 vColor;
|
|
2493
2570
|
|
|
2494
2571
|
void main() {
|
|
2572
|
+
vec3 lineVec = uMax - uMin; // \u7EBF\u6BB5AB\u7684\u65B9\u5411\u5411\u91CF
|
|
2573
|
+
vec3 AP = position - uMin; // \u5411\u91CFAP
|
|
2574
|
+
float t = dot(AP, lineVec) / dot(lineVec, lineVec); // \u53C2\u6570t
|
|
2575
|
+
t = clamp(t, 0.0, 1.0); // \u9650\u5236t\u5728[0, 1]\u8303\u56F4\u5185\uFF0C\u786E\u4FDD\u6700\u77ED\u8DDD\u79BB\u5728\u7EBF\u6BB5AB\u4E0A
|
|
2576
|
+
|
|
2577
|
+
vec3 closestPoint = uMin + t * lineVec; // \u6700\u77ED\u8DDD\u79BB\u70B9\u7684\u4F4D\u7F6E
|
|
2578
|
+
vec3 vecAP = closestPoint - uMin; // \u5411\u91CFAP'
|
|
2579
|
+
float distance = length(vecAP);
|
|
2580
|
+
float maxLen = length(lineVec);
|
|
2581
|
+
|
|
2495
2582
|
vec3 direction = normalize(uDirection);
|
|
2583
|
+
float gradient = dot(normalize(normal), normalize(uDirection));
|
|
2496
2584
|
vec3 currentPosition = position - center;
|
|
2497
|
-
float colorFactor = (dot(direction, currentPosition) / maxValue) * 0.5 + 0.5;
|
|
2585
|
+
// float colorFactor = (dot(direction, currentPosition) / maxValue) * 0.5 + 0.5;
|
|
2586
|
+
float colorFactor = distance / maxLen;
|
|
2498
2587
|
|
|
2499
|
-
vColor = mix(uColor, uGradualColor,
|
|
2588
|
+
vColor = mix(uColor, uGradualColor, 1.0 - t);
|
|
2500
2589
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
2501
2590
|
}
|
|
2502
2591
|
`;
|