my-openlayer 1.0.7 → 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.
@@ -44,9 +44,10 @@ function detectVueSync() {
44
44
  }
45
45
  // 初始化Vue导入
46
46
  detectVueSync();
47
- if (!Vue) {
48
- detectAndImportVue();
49
- }
47
+ // 注意:不在模块顶层调用异步函数,避免模块变成异步的
48
+ // if (!Vue) {
49
+ // detectAndImportVue();
50
+ // }
50
51
  /**
51
52
  * Vue模板点位管理类
52
53
  * 用于在地图上添加和管理Vue组件覆盖物
@@ -168,18 +169,31 @@ class VueTemplatePointInstanceImpl {
168
169
  this.validateConstructorParams(map, options);
169
170
  // 创建DOM元素
170
171
  this.dom = this.createDomElement();
171
- // 创建Vue应用实例
172
- this.createVueApp();
173
172
  // 创建覆盖层
174
173
  this.anchor = this.createOverlay();
175
174
  // 添加到地图
176
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();
177
191
  // 设置初始状态
178
192
  this.state = VueTemplatePointState.MOUNTED;
179
193
  this.setVisible(this.options.visible ?? true);
180
194
  }
181
195
  catch (error) {
182
- this.handleError('Failed to create Vue template point', error, { map, options });
196
+ this.handleError('Failed to initialize Vue app', error);
183
197
  throw error;
184
198
  }
185
199
  }
@@ -242,8 +256,17 @@ class VueTemplatePointInstanceImpl {
242
256
  * 创建Vue应用实例
243
257
  * @private
244
258
  */
245
- createVueApp() {
259
+ async createVueApp() {
246
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
+ }
247
270
  if (!Vue) {
248
271
  throw new Error('Vue is not available. Please ensure Vue is installed in your project.');
249
272
  }
@@ -350,7 +373,7 @@ class VueTemplatePointInstanceImpl {
350
373
  * @param newProps 新的属性对象
351
374
  * @throws 当操作失败时抛出错误
352
375
  */
353
- updateProps(newProps) {
376
+ async updateProps(newProps) {
354
377
  if (this.state === VueTemplatePointState.DESTROYED) {
355
378
  throw new Error('Cannot update props on destroyed DOM point');
356
379
  }
@@ -358,7 +381,7 @@ class VueTemplatePointInstanceImpl {
358
381
  // 重新创建Vue应用实例
359
382
  this.destroyVueApp();
360
383
  this.options.props = { ...this.options.props, ...newProps };
361
- this.createVueApp();
384
+ await this.createVueApp();
362
385
  }
363
386
  catch (error) {
364
387
  this.handleError('Failed to update props', error, { newProps });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "1.0.7",
4
+ "version": "1.0.8",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
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;