huweili-cesium 1.2.29 → 1.2.31
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/js/basis.js +31 -3
- package/js/clickHandler.js +44 -14
- package/package.json +1 -1
package/js/basis.js
CHANGED
|
@@ -126,8 +126,17 @@ export function basicConfig() {
|
|
|
126
126
|
e.preventDefault();
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
+
// 获取现有的事件处理器(如果有)
|
|
130
|
+
const existingLeftClickHandler = map.screenSpaceEventHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
131
|
+
const existingRightClickHandler = map.screenSpaceEventHandler.getInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
132
|
+
|
|
129
133
|
// 添加右键点击事件监听
|
|
130
134
|
map.screenSpaceEventHandler.setInputAction((click) => {
|
|
135
|
+
// 先调用已有的处理器(如果有)
|
|
136
|
+
if (existingRightClickHandler) {
|
|
137
|
+
existingRightClickHandler(click);
|
|
138
|
+
}
|
|
139
|
+
|
|
131
140
|
// 获取点击位置的笛卡尔坐标
|
|
132
141
|
const cartesian = map.camera.pickEllipsoid(click.position, map.scene.globe.ellipsoid);
|
|
133
142
|
if (cartesian) {
|
|
@@ -145,12 +154,23 @@ export function basicConfig() {
|
|
|
145
154
|
cartesian,
|
|
146
155
|
};
|
|
147
156
|
|
|
148
|
-
console.log('
|
|
157
|
+
console.log('右键点击位置:', position);
|
|
158
|
+
callbacks.onRightClick?.(position);
|
|
159
|
+
} else {
|
|
160
|
+
callbacks.onRightClick?.({
|
|
161
|
+
mapId: _mapId,
|
|
162
|
+
screenPosition: click.position,
|
|
163
|
+
});
|
|
149
164
|
}
|
|
150
165
|
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
151
166
|
|
|
152
167
|
// 添加左键点击事件,用于隐藏弹窗
|
|
153
168
|
map.screenSpaceEventHandler.setInputAction((click) => {
|
|
169
|
+
// 先调用已有的处理器(如果有)
|
|
170
|
+
if (existingLeftClickHandler) {
|
|
171
|
+
existingLeftClickHandler(click);
|
|
172
|
+
}
|
|
173
|
+
|
|
154
174
|
// 获取点击位置的笛卡尔坐标
|
|
155
175
|
const cartesian = map.camera.pickEllipsoid(click.position, map.scene.globe.ellipsoid);
|
|
156
176
|
if (cartesian) {
|
|
@@ -160,7 +180,7 @@ export function basicConfig() {
|
|
|
160
180
|
const lat = Cesium.Math.toDegrees(cartographic.latitude);
|
|
161
181
|
const height = cartographic.height;
|
|
162
182
|
|
|
163
|
-
console.log('
|
|
183
|
+
console.log('左键点击位置:', {
|
|
164
184
|
lng: Number(lng),
|
|
165
185
|
lat: Number(lat),
|
|
166
186
|
height: Number(height)
|
|
@@ -168,7 +188,15 @@ export function basicConfig() {
|
|
|
168
188
|
callbacks.onLeftClick?.({
|
|
169
189
|
lng: Number(lng),
|
|
170
190
|
lat: Number(lat),
|
|
171
|
-
height: Number(height)
|
|
191
|
+
height: Number(height),
|
|
192
|
+
mapId: _mapId,
|
|
193
|
+
screenPosition: click.position,
|
|
194
|
+
cartesian,
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
callbacks.onLeftClick?.({
|
|
198
|
+
mapId: _mapId,
|
|
199
|
+
screenPosition: click.position,
|
|
172
200
|
});
|
|
173
201
|
}
|
|
174
202
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
package/js/clickHandler.js
CHANGED
|
@@ -218,17 +218,40 @@ export class ClickHandler {
|
|
|
218
218
|
*/
|
|
219
219
|
ensureMapHandler(map, mapId) {
|
|
220
220
|
if (!this.handlers.has(mapId) && map) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
handler
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
handler.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
221
|
+
// 使用地图自带的 screenSpaceEventHandler 而不是创建新的
|
|
222
|
+
// 这样可以避免与 basis.js 中的 mouseController 冲突
|
|
223
|
+
const handler = map.screenSpaceEventHandler
|
|
224
|
+
|
|
225
|
+
// 获取已有的事件处理器(如果有)
|
|
226
|
+
const existingLeftClickHandler = handler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
227
|
+
const existingRightClickHandler = handler.getInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
228
|
+
|
|
229
|
+
// 存储需要清理的事件回调引用
|
|
230
|
+
const cleanupCallbacks = {
|
|
231
|
+
leftClick: null,
|
|
232
|
+
rightClick: null
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
cleanupCallbacks.leftClick = (click) => {
|
|
236
|
+
// 先调用已有的处理器(如果有)
|
|
237
|
+
if (existingLeftClickHandler) {
|
|
238
|
+
existingLeftClickHandler(click);
|
|
239
|
+
}
|
|
240
|
+
this.handleClick(map, mapId, click, 'left');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
cleanupCallbacks.rightClick = (click) => {
|
|
244
|
+
// 先调用已有的处理器(如果有)
|
|
245
|
+
if (existingRightClickHandler) {
|
|
246
|
+
existingRightClickHandler(click);
|
|
247
|
+
}
|
|
248
|
+
this.handleClick(map, mapId, click, 'right');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
handler.setInputAction(cleanupCallbacks.leftClick, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
252
|
+
handler.setInputAction(cleanupCallbacks.rightClick, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
253
|
+
|
|
254
|
+
this.handlers.set(mapId, { handler, cleanupCallbacks });
|
|
232
255
|
}
|
|
233
256
|
}
|
|
234
257
|
|
|
@@ -280,9 +303,16 @@ export class ClickHandler {
|
|
|
280
303
|
}
|
|
281
304
|
})
|
|
282
305
|
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
285
|
-
|
|
306
|
+
const handlerData = this.handlers.get(mapId)
|
|
307
|
+
if (handlerData) {
|
|
308
|
+
// 只移除我们添加的事件监听器,不要销毁 map.screenSpaceEventHandler
|
|
309
|
+
const { handler, cleanupCallbacks } = handlerData
|
|
310
|
+
if (cleanupCallbacks.leftClick) {
|
|
311
|
+
handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
|
312
|
+
}
|
|
313
|
+
if (cleanupCallbacks.rightClick) {
|
|
314
|
+
handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK)
|
|
315
|
+
}
|
|
286
316
|
this.handlers.delete(mapId)
|
|
287
317
|
}
|
|
288
318
|
}
|