my-openlayer 2.4.0 → 2.4.2
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/Polygon.js +22 -2
- package/core/VueTemplatePoint.js +7 -4
- package/package.json +1 -1
package/core/Polygon.js
CHANGED
|
@@ -79,9 +79,19 @@ export default class Polygon {
|
|
|
79
79
|
if (mergedOptions.layerName) {
|
|
80
80
|
new MapTools(this.map).removeLayer(mergedOptions.layerName);
|
|
81
81
|
}
|
|
82
|
+
const format = new GeoJSON();
|
|
83
|
+
// 优化:在解析 Feature 时直接注入 layerName,利用解析过程的遍历,避免解析后的二次循环
|
|
84
|
+
if (mergedOptions.layerName) {
|
|
85
|
+
const originalReadFeatureFromObject = format.readFeatureFromObject;
|
|
86
|
+
format.readFeatureFromObject = function (object, options) {
|
|
87
|
+
const feature = originalReadFeatureFromObject.call(this, object, options);
|
|
88
|
+
feature.set('layerName', mergedOptions.layerName, true); // true 表示静默设置,不触发事件
|
|
89
|
+
return feature;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
82
92
|
let features;
|
|
83
93
|
try {
|
|
84
|
-
features =
|
|
94
|
+
features = format.readFeatures(dataJSON, mergedOptions.projectionOptOptions ?? {});
|
|
85
95
|
}
|
|
86
96
|
catch (error) {
|
|
87
97
|
throw new Error(`Failed to parse GeoJSON data: ${error}`);
|
|
@@ -119,9 +129,19 @@ export default class Polygon {
|
|
|
119
129
|
if (mergedOptions.layerName) {
|
|
120
130
|
new MapTools(this.map).removeLayer(mergedOptions.layerName);
|
|
121
131
|
}
|
|
132
|
+
const format = new GeoJSON(mergedOptions.projectionOptOptions ?? {});
|
|
133
|
+
// 优化:在解析 Feature 时直接注入 layerName,利用解析过程的遍历,避免解析后的二次循环
|
|
134
|
+
if (mergedOptions.layerName) {
|
|
135
|
+
const originalReadFeatureFromObject = format.readFeatureFromObject;
|
|
136
|
+
format.readFeatureFromObject = function (object, options) {
|
|
137
|
+
const feature = originalReadFeatureFromObject.call(this, object, options);
|
|
138
|
+
feature.set('layerName', mergedOptions.layerName, true); // true 表示静默设置,不触发事件
|
|
139
|
+
return feature;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
122
142
|
const source = new VectorSource({
|
|
123
143
|
url,
|
|
124
|
-
format
|
|
144
|
+
format
|
|
125
145
|
});
|
|
126
146
|
const layer = new VectorLayer({
|
|
127
147
|
properties: {
|
package/core/VueTemplatePoint.js
CHANGED
|
@@ -37,10 +37,13 @@ function detectVueSync() {
|
|
|
37
37
|
// 如果在Node.js环境中,尝试require
|
|
38
38
|
if (typeof window === 'undefined') {
|
|
39
39
|
try {
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
// 尝试获取 require 函数,避免使用 eval
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
const requireFunc = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : (typeof module !== 'undefined' && module.require ? module.require : undefined);
|
|
43
|
+
if (requireFunc) {
|
|
44
|
+
Vue = requireFunc('vue');
|
|
45
|
+
isVue3 = !!(Vue.version?.startsWith('3') || Vue.createApp);
|
|
46
|
+
}
|
|
44
47
|
}
|
|
45
48
|
catch (e) {
|
|
46
49
|
ErrorHandler.getInstance().warn('Vue not found. Please ensure Vue is installed in your project.');
|