my-openlayer 1.0.7 → 1.0.9
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/Point.d.ts +2 -1
- package/core/Point.js +4 -1
- package/core/VueTemplatePoint.d.ts +1 -0
- package/core/VueTemplatePoint.js +22 -52
- package/package.json +1 -1
package/core/Point.d.ts
CHANGED
|
@@ -79,11 +79,12 @@ export default class Point {
|
|
|
79
79
|
* 添加vue组件为点位
|
|
80
80
|
* @param pointDataList 点位信息列表
|
|
81
81
|
* @param template vue组件模板
|
|
82
|
-
* @param
|
|
82
|
+
* @param options 选项,包含Vue实例
|
|
83
83
|
* @returns 返回控制对象,包含显示、隐藏、移除方法
|
|
84
84
|
* @throws 当参数无效时抛出错误
|
|
85
85
|
*/
|
|
86
86
|
addVueTemplatePoint(pointDataList: PointData[], template: any, options?: {
|
|
87
|
+
Vue?: any;
|
|
87
88
|
positioning?: 'bottom-left' | 'bottom-center' | 'bottom-right' | 'center-left' | 'center-center' | 'center-right' | 'top-left' | 'top-center' | 'top-right';
|
|
88
89
|
stopEvent?: boolean;
|
|
89
90
|
}): {
|
package/core/Point.js
CHANGED
|
@@ -321,7 +321,7 @@ export default class Point {
|
|
|
321
321
|
* 添加vue组件为点位
|
|
322
322
|
* @param pointDataList 点位信息列表
|
|
323
323
|
* @param template vue组件模板
|
|
324
|
-
* @param
|
|
324
|
+
* @param options 选项,包含Vue实例
|
|
325
325
|
* @returns 返回控制对象,包含显示、隐藏、移除方法
|
|
326
326
|
* @throws 当参数无效时抛出错误
|
|
327
327
|
*/
|
|
@@ -332,6 +332,9 @@ export default class Point {
|
|
|
332
332
|
if (!template) {
|
|
333
333
|
throw new Error('Vue template is required');
|
|
334
334
|
}
|
|
335
|
+
if (!options?.Vue) {
|
|
336
|
+
throw new Error('Vue instance is required in options');
|
|
337
|
+
}
|
|
335
338
|
try {
|
|
336
339
|
const vueTemplatePoint = new VueTemplatePoint(this.map);
|
|
337
340
|
return vueTemplatePoint.addVueTemplatePoint(pointDataList, template, options);
|
|
@@ -21,6 +21,7 @@ export default class VueTemplatePoint {
|
|
|
21
21
|
* @returns 点位控制器
|
|
22
22
|
*/
|
|
23
23
|
addVueTemplatePoint(pointDataList: any[], template: any, options?: {
|
|
24
|
+
Vue?: any;
|
|
24
25
|
positioning?: 'bottom-left' | 'bottom-center' | 'bottom-right' | 'center-left' | 'center-center' | 'center-right' | 'top-left' | 'top-center' | 'top-right';
|
|
25
26
|
stopEvent?: boolean;
|
|
26
27
|
}): {
|
package/core/VueTemplatePoint.js
CHANGED
|
@@ -2,50 +2,13 @@ import Overlay from 'ol/Overlay';
|
|
|
2
2
|
import { VueTemplatePointState } from '../types';
|
|
3
3
|
import { ErrorHandler, ErrorType } from '../utils/ErrorHandler';
|
|
4
4
|
import { ValidationUtils } from '../utils/ValidationUtils';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const vueModule = await import('vue');
|
|
13
|
-
Vue = vueModule.default || vueModule;
|
|
14
|
-
// 检测Vue版本
|
|
15
|
-
if (Vue && (Vue.version?.startsWith('3') || Vue.createApp)) {
|
|
16
|
-
isVue3 = true;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
isVue3 = false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
console.warn('Vue not found. Please ensure Vue is installed in your project.');
|
|
24
|
-
Vue = null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
// 浏览器环境的Vue检测
|
|
28
|
-
function detectVueSync() {
|
|
29
|
-
try {
|
|
30
|
-
// 从全局对象获取Vue(仅浏览器环境)
|
|
31
|
-
if (typeof window !== 'undefined' && window.Vue) {
|
|
32
|
-
Vue = window.Vue;
|
|
33
|
-
isVue3 = !!(Vue.version?.startsWith('3') || Vue.createApp);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
console.warn('Vue not found in global scope. Please ensure Vue is loaded before this library.');
|
|
37
|
-
Vue = null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
console.warn('Failed to detect Vue:', e);
|
|
42
|
-
Vue = null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// 初始化Vue导入
|
|
46
|
-
detectVueSync();
|
|
47
|
-
if (!Vue) {
|
|
48
|
-
detectAndImportVue();
|
|
5
|
+
/**
|
|
6
|
+
* 检测Vue版本
|
|
7
|
+
* @param Vue Vue实例
|
|
8
|
+
* @returns 是否为Vue3
|
|
9
|
+
*/
|
|
10
|
+
function isVue3(Vue) {
|
|
11
|
+
return !!(Vue && (Vue.version?.startsWith('3') || Vue.createApp));
|
|
49
12
|
}
|
|
50
13
|
/**
|
|
51
14
|
* Vue模板点位管理类
|
|
@@ -76,7 +39,12 @@ export default class VueTemplatePoint {
|
|
|
76
39
|
if (!template) {
|
|
77
40
|
throw new Error('Vue template is required');
|
|
78
41
|
}
|
|
42
|
+
if (!options?.Vue) {
|
|
43
|
+
throw new Error('Vue instance is required in options');
|
|
44
|
+
}
|
|
79
45
|
try {
|
|
46
|
+
const Vue = options.Vue;
|
|
47
|
+
const vueIsVue3 = isVue3(Vue);
|
|
80
48
|
const instances = [];
|
|
81
49
|
pointDataList.forEach((pointData) => {
|
|
82
50
|
if (!ValidationUtils.validateLngLat(pointData.lgtd, pointData.lttd)) {
|
|
@@ -95,7 +63,7 @@ export default class VueTemplatePoint {
|
|
|
95
63
|
positioning: options?.positioning,
|
|
96
64
|
stopEvent: options?.stopEvent,
|
|
97
65
|
};
|
|
98
|
-
const instance = new VueTemplatePointInstanceImpl(this.map, pointOptions, this.errorHandler);
|
|
66
|
+
const instance = new VueTemplatePointInstanceImpl(this.map, pointOptions, this.errorHandler, Vue, vueIsVue3);
|
|
99
67
|
instances.push(instance);
|
|
100
68
|
this.vuePoints.set(instance.id, instance);
|
|
101
69
|
});
|
|
@@ -155,11 +123,13 @@ export default class VueTemplatePoint {
|
|
|
155
123
|
* @internal
|
|
156
124
|
*/
|
|
157
125
|
class VueTemplatePointInstanceImpl {
|
|
158
|
-
constructor(map, options, errorHandler) {
|
|
126
|
+
constructor(map, options, errorHandler, Vue, isVue3) {
|
|
159
127
|
this.app = null;
|
|
160
128
|
this.state = VueTemplatePointState.CREATED;
|
|
161
129
|
this.map = map;
|
|
162
130
|
this.errorHandler = errorHandler;
|
|
131
|
+
this.Vue = Vue;
|
|
132
|
+
this.isVue3 = isVue3;
|
|
163
133
|
this.options = this.mergeDefaultOptions(options);
|
|
164
134
|
this.id = this.generateUniqueId();
|
|
165
135
|
this.position = [this.options.lgtd, this.options.lttd];
|
|
@@ -244,13 +214,13 @@ class VueTemplatePointInstanceImpl {
|
|
|
244
214
|
*/
|
|
245
215
|
createVueApp() {
|
|
246
216
|
const { Template, props } = this.options;
|
|
247
|
-
if (!Vue) {
|
|
248
|
-
throw new Error('Vue is not available. Please ensure Vue is
|
|
217
|
+
if (!this.Vue) {
|
|
218
|
+
throw new Error('Vue is not available. Please ensure Vue instance is provided.');
|
|
249
219
|
}
|
|
250
220
|
try {
|
|
251
|
-
if (isVue3) {
|
|
221
|
+
if (this.isVue3) {
|
|
252
222
|
// Vue 3
|
|
253
|
-
this.app = Vue.createApp({
|
|
223
|
+
this.app = this.Vue.createApp({
|
|
254
224
|
...Template,
|
|
255
225
|
props: props || {}
|
|
256
226
|
});
|
|
@@ -258,7 +228,7 @@ class VueTemplatePointInstanceImpl {
|
|
|
258
228
|
}
|
|
259
229
|
else {
|
|
260
230
|
// Vue 2
|
|
261
|
-
this.app = new Vue({
|
|
231
|
+
this.app = new this.Vue({
|
|
262
232
|
el: this.dom,
|
|
263
233
|
render: (h) => h(Template, { props: props || {} })
|
|
264
234
|
});
|
|
@@ -425,7 +395,7 @@ class VueTemplatePointInstanceImpl {
|
|
|
425
395
|
destroyVueApp() {
|
|
426
396
|
if (this.app) {
|
|
427
397
|
try {
|
|
428
|
-
if (isVue3) {
|
|
398
|
+
if (this.isVue3) {
|
|
429
399
|
// Vue 3: 使用 unmount
|
|
430
400
|
this.app.unmount();
|
|
431
401
|
}
|