my-openlayer 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/core/VueTemplatePoint.js +38 -24
- package/package.json +1 -1
- package/types.d.ts +1 -1
package/core/VueTemplatePoint.js
CHANGED
|
@@ -24,38 +24,30 @@ async function detectAndImportVue() {
|
|
|
24
24
|
Vue = null;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
//
|
|
27
|
+
// 浏览器环境的Vue检测
|
|
28
28
|
function detectVueSync() {
|
|
29
29
|
try {
|
|
30
|
-
//
|
|
30
|
+
// 从全局对象获取Vue(仅浏览器环境)
|
|
31
31
|
if (typeof window !== 'undefined' && window.Vue) {
|
|
32
32
|
Vue = window.Vue;
|
|
33
33
|
isVue3 = !!(Vue.version?.startsWith('3') || Vue.createApp);
|
|
34
|
-
return;
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// 使用eval来避免TypeScript编译时的require检查
|
|
40
|
-
const requireFunc = eval('require');
|
|
41
|
-
Vue = requireFunc('vue');
|
|
42
|
-
isVue3 = !!(Vue.version?.startsWith('3') || Vue.createApp);
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
console.warn('Vue not found. Please ensure Vue is installed in your project.');
|
|
46
|
-
Vue = null;
|
|
47
|
-
}
|
|
35
|
+
else {
|
|
36
|
+
console.warn('Vue not found in global scope. Please ensure Vue is loaded before this library.');
|
|
37
|
+
Vue = null;
|
|
48
38
|
}
|
|
49
39
|
}
|
|
50
40
|
catch (e) {
|
|
51
41
|
console.warn('Failed to detect Vue:', e);
|
|
42
|
+
Vue = null;
|
|
52
43
|
}
|
|
53
44
|
}
|
|
54
45
|
// 初始化Vue导入
|
|
55
46
|
detectVueSync();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
// 注意:不在模块顶层调用异步函数,避免模块变成异步的
|
|
48
|
+
// if (!Vue) {
|
|
49
|
+
// detectAndImportVue();
|
|
50
|
+
// }
|
|
59
51
|
/**
|
|
60
52
|
* Vue模板点位管理类
|
|
61
53
|
* 用于在地图上添加和管理Vue组件覆盖物
|
|
@@ -177,18 +169,31 @@ class VueTemplatePointInstanceImpl {
|
|
|
177
169
|
this.validateConstructorParams(map, options);
|
|
178
170
|
// 创建DOM元素
|
|
179
171
|
this.dom = this.createDomElement();
|
|
180
|
-
// 创建Vue应用实例
|
|
181
|
-
this.createVueApp();
|
|
182
172
|
// 创建覆盖层
|
|
183
173
|
this.anchor = this.createOverlay();
|
|
184
174
|
// 添加到地图
|
|
185
175
|
this.map.addOverlay(this.anchor);
|
|
176
|
+
// 异步创建Vue应用实例
|
|
177
|
+
this.initializeVueApp();
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
this.handleError('Failed to create Vue template point', error, { map, options });
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 异步初始化Vue应用
|
|
186
|
+
* @private
|
|
187
|
+
*/
|
|
188
|
+
async initializeVueApp() {
|
|
189
|
+
try {
|
|
190
|
+
await this.createVueApp();
|
|
186
191
|
// 设置初始状态
|
|
187
192
|
this.state = VueTemplatePointState.MOUNTED;
|
|
188
193
|
this.setVisible(this.options.visible ?? true);
|
|
189
194
|
}
|
|
190
195
|
catch (error) {
|
|
191
|
-
this.handleError('Failed to
|
|
196
|
+
this.handleError('Failed to initialize Vue app', error);
|
|
192
197
|
throw error;
|
|
193
198
|
}
|
|
194
199
|
}
|
|
@@ -251,8 +256,17 @@ class VueTemplatePointInstanceImpl {
|
|
|
251
256
|
* 创建Vue应用实例
|
|
252
257
|
* @private
|
|
253
258
|
*/
|
|
254
|
-
createVueApp() {
|
|
259
|
+
async createVueApp() {
|
|
255
260
|
const { Template, props } = this.options;
|
|
261
|
+
// 如果Vue不可用,尝试异步导入
|
|
262
|
+
if (!Vue) {
|
|
263
|
+
try {
|
|
264
|
+
await detectAndImportVue();
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
throw new Error('Vue is not available. Please ensure Vue is installed in your project.');
|
|
268
|
+
}
|
|
269
|
+
}
|
|
256
270
|
if (!Vue) {
|
|
257
271
|
throw new Error('Vue is not available. Please ensure Vue is installed in your project.');
|
|
258
272
|
}
|
|
@@ -359,7 +373,7 @@ class VueTemplatePointInstanceImpl {
|
|
|
359
373
|
* @param newProps 新的属性对象
|
|
360
374
|
* @throws 当操作失败时抛出错误
|
|
361
375
|
*/
|
|
362
|
-
updateProps(newProps) {
|
|
376
|
+
async updateProps(newProps) {
|
|
363
377
|
if (this.state === VueTemplatePointState.DESTROYED) {
|
|
364
378
|
throw new Error('Cannot update props on destroyed DOM point');
|
|
365
379
|
}
|
|
@@ -367,7 +381,7 @@ class VueTemplatePointInstanceImpl {
|
|
|
367
381
|
// 重新创建Vue应用实例
|
|
368
382
|
this.destroyVueApp();
|
|
369
383
|
this.options.props = { ...this.options.props, ...newProps };
|
|
370
|
-
this.createVueApp();
|
|
384
|
+
await this.createVueApp();
|
|
371
385
|
}
|
|
372
386
|
catch (error) {
|
|
373
387
|
this.handleError('Failed to update props', error, { newProps });
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -290,7 +290,7 @@ export interface VueTemplatePointInstance {
|
|
|
290
290
|
options: VueTemplatePointOptions;
|
|
291
291
|
setVisible(visible: boolean): void;
|
|
292
292
|
updatePosition(lgtd: number, lttd: number): void;
|
|
293
|
-
updateProps(newProps: Record<string, any>): void
|
|
293
|
+
updateProps(newProps: Record<string, any>): Promise<void>;
|
|
294
294
|
setStyle(styles: Partial<CSSStyleDeclaration>): void;
|
|
295
295
|
addClass(className: string): void;
|
|
296
296
|
removeClass(className: string): void;
|