huweili-cesium 1.2.23 → 1.2.25

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.
Files changed (3) hide show
  1. package/index.vue +5 -2
  2. package/js/basis.js +28 -6
  3. package/package.json +1 -1
package/index.vue CHANGED
@@ -28,7 +28,7 @@ const {
28
28
 
29
29
  const mapStore = useMapStore()
30
30
  const { on: onEvent, off: offEvent } = useEventBus()
31
- const emit = defineEmits(['onload'])
31
+ const emit = defineEmits(['onload', 'rightClick', 'leftClick'])
32
32
  const props = defineProps({
33
33
  options: {
34
34
  type: Object,
@@ -239,7 +239,10 @@ const initCesium = async () => {
239
239
  })
240
240
  }
241
241
 
242
- mouseController(map, props.mapId) // 初始化鼠标控制器
242
+ mouseController(map, props.mapId, {
243
+ onRightClick: (position) => emit('rightClick', position),
244
+ onLeftClick: (event) => emit('leftClick', event),
245
+ }) // 初始化鼠标控制器
243
246
 
244
247
  mapStore.setMapInfo(
245
248
  'center',
package/js/basis.js CHANGED
@@ -120,7 +120,7 @@ export function basicConfig() {
120
120
  * 处理地图上的鼠标事件,包括点击、拖动、缩放等、
121
121
  * @param map - 地图实例
122
122
  */
123
- const mouseController = (map, _mapId) => {
123
+ const mouseController = (map, _mapId, callbacks = {}) => {
124
124
  // 添加右键点击事件监听
125
125
  map.screenSpaceEventHandler.setInputAction((click) => {
126
126
  // 获取点击位置的笛卡尔坐标
@@ -132,12 +132,17 @@ export function basicConfig() {
132
132
  const lng = Cesium.Math.toDegrees(cartographic.longitude);
133
133
  const lat = Cesium.Math.toDegrees(cartographic.latitude);
134
134
  const height = cartographic.height;
135
-
136
- console.log('点击位置:', {
135
+ const position = {
137
136
  lng: Number(lng),
138
137
  lat: Number(lat),
139
- height: Number(height)
140
- });
138
+ height: Number(height),
139
+ mapId: _mapId,
140
+ screenPosition: click.position,
141
+ cartesian,
142
+ };
143
+
144
+ console.log('点击位置:', position);
145
+ callbacks.onRightClick?.(position);
141
146
 
142
147
  // 弹出alert显示坐标信息
143
148
  // alert(`点击位置坐标:\n经度:${Number(lng).toFixed(6)}\n纬度:${Number(lat).toFixed(6)}\n高度:${Number(height).toFixed(2)}米`);
@@ -145,8 +150,25 @@ export function basicConfig() {
145
150
  }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
146
151
 
147
152
  // 添加左键点击事件,用于隐藏弹窗
148
- map.screenSpaceEventHandler.setInputAction(() => {
153
+ map.screenSpaceEventHandler.setInputAction((click) => {
149
154
  console.log('左键点击事件触发')
155
+ const cartesian = map.camera.pickEllipsoid(click.position, map.scene.globe.ellipsoid);
156
+ if (cartesian) {
157
+ const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
158
+ const lng = Cesium.Math.toDegrees(cartographic.longitude);
159
+ const lat = Cesium.Math.toDegrees(cartographic.latitude);
160
+ const height = cartographic.height;
161
+ callbacks.onLeftClick?.({
162
+ mapId: _mapId,
163
+ screenPosition: click.position,
164
+ lng: Number(lng),
165
+ lat: Number(lat),
166
+ height: Number(height),
167
+ cartesian,
168
+ });
169
+ } else {
170
+ callbacks.onLeftClick?.({ mapId: _mapId, screenPosition: click.position });
171
+ }
150
172
  }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
151
173
  }
152
174
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huweili-cesium",
3
- "version": "1.2.23",
3
+ "version": "1.2.25",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",