cd-mapgis 1.0.20 → 1.0.21
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/package.json +1 -1
- package/src/MapRender.js +11 -457
- package/src/MapView.js +13 -1
- package/src/index.d.ts +2 -1
package/package.json
CHANGED
package/src/MapRender.js
CHANGED
|
@@ -1,459 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
let Map, View, TileLayer, XYZ, fromLonLat, toLonLat, Feature, Point, VectorLayer, VectorSource, Style, Circle, Fill, Stroke, Text, Icon;
|
|
3
|
-
|
|
4
|
-
// 地图实例和标记图层
|
|
5
|
-
let map = null;
|
|
6
|
-
let markerLayer = null;
|
|
7
|
-
let markers = []; // 存储所有添加的标记
|
|
1
|
+
import Index from './index.js';
|
|
8
2
|
|
|
9
3
|
export default {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
methods: {
|
|
21
|
-
// 动态加载 OpenLayers 模块
|
|
22
|
-
async loadOpenLayers() {
|
|
23
|
-
try {
|
|
24
|
-
|
|
25
|
-
// 导入核心模块
|
|
26
|
-
const mapDefault = await import('ol/Map.js');
|
|
27
|
-
const viewDefault = await import('ol/View.js');
|
|
28
|
-
const layerDefault = await import('ol/layer/Tile.js');
|
|
29
|
-
const sourceDefault = await import('ol/source/XYZ.js');
|
|
30
|
-
const projDefault = await import('ol/proj.js');
|
|
31
|
-
|
|
32
|
-
// 导入要素和矢量相关模块
|
|
33
|
-
const featureDefault = await import('ol/Feature.js');
|
|
34
|
-
const geomDefault = await import('ol/geom/Point.js');
|
|
35
|
-
const layerVectorDefault = await import('ol/layer/Vector.js');
|
|
36
|
-
const sourceVectorDefault = await import('ol/source/Vector.js');
|
|
37
|
-
|
|
38
|
-
// 导入样式相关模块
|
|
39
|
-
const styleDefault = await import('ol/style/Style.js');
|
|
40
|
-
const circleDefault = await import('ol/style/Circle.js');
|
|
41
|
-
const fillDefault = await import('ol/style/Fill.js');
|
|
42
|
-
const strokeDefault = await import('ol/style/Stroke.js'); // 添加缺失的Stroke导入
|
|
43
|
-
const textDefault = await import('ol/style/Text.js'); // 添加缺失的Text导入
|
|
44
|
-
const iconDefault = await import('ol/style/Icon.js'); // 添加Icon导入
|
|
45
|
-
|
|
46
|
-
// 赋值默认导出
|
|
47
|
-
Map = mapDefault.default;
|
|
48
|
-
View = viewDefault.default;
|
|
49
|
-
TileLayer = layerDefault.default;
|
|
50
|
-
XYZ = sourceDefault.default;
|
|
51
|
-
fromLonLat = projDefault.fromLonLat; // 修复fromLonLat的导入方式
|
|
52
|
-
toLonLat = projDefault.toLonLat; // 添加toLonLat导入
|
|
53
|
-
|
|
54
|
-
Feature = featureDefault.default;
|
|
55
|
-
Point = geomDefault.default;
|
|
56
|
-
VectorLayer = layerVectorDefault.default;
|
|
57
|
-
VectorSource = sourceVectorDefault.default;
|
|
58
|
-
|
|
59
|
-
Style = styleDefault.default;
|
|
60
|
-
Circle = circleDefault.default;
|
|
61
|
-
Fill = fillDefault.default;
|
|
62
|
-
Stroke = strokeDefault.default;
|
|
63
|
-
Text = textDefault.default;
|
|
64
|
-
Icon = iconDefault.default;
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error('Failed to load OpenLayers:', error);
|
|
67
|
-
// 移除备用加载方案,直接抛出错误让上层处理
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
// 初始化地图
|
|
73
|
-
initMap() {
|
|
74
|
-
const container = document.getElementById('olMap');
|
|
75
|
-
if (!container) {
|
|
76
|
-
console.error('Map container not found');
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
// 创建天地图底图
|
|
82
|
-
const tdtBaseLayer = new TileLayer({
|
|
83
|
-
source: new XYZ({
|
|
84
|
-
url: `http://t{0-7}.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${this.mapConfig.tdtKey}`,
|
|
85
|
-
projection: 'EPSG:3857',
|
|
86
|
-
crossOrigin: 'anonymous'
|
|
87
|
-
}),
|
|
88
|
-
visible: true
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// 创建天地图注记层
|
|
92
|
-
const tdtLabelLayer = new TileLayer({
|
|
93
|
-
source: new XYZ({
|
|
94
|
-
url: `http://t{0-7}.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${this.mapConfig.tdtKey}`,
|
|
95
|
-
projection: 'EPSG:3857',
|
|
96
|
-
crossOrigin: 'anonymous'
|
|
97
|
-
}),
|
|
98
|
-
visible: true
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// 初始化地图实例
|
|
102
|
-
map = new Map({
|
|
103
|
-
target: container,
|
|
104
|
-
layers: [tdtBaseLayer, tdtLabelLayer],
|
|
105
|
-
view: new View({
|
|
106
|
-
center: fromLonLat(this.mapConfig.center || [116.3974, 39.9093]),
|
|
107
|
-
zoom: this.mapConfig.zoom || 10,
|
|
108
|
-
minZoom: 3,
|
|
109
|
-
maxZoom: 18,
|
|
110
|
-
enableRotation: false
|
|
111
|
-
}),
|
|
112
|
-
controls: []
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// 监听地图视图变化,使用bind确保this上下文正确
|
|
116
|
-
map.getView().on('change:center', this.handleViewChange.bind(this));
|
|
117
|
-
map.getView().on('change:resolution', this.handleViewChange.bind(this));
|
|
118
|
-
|
|
119
|
-
// 地图初始化完成,通过方法调用通知Vue组件
|
|
120
|
-
|
|
121
|
-
// 通知Vue组件地图初始化完成
|
|
122
|
-
try {
|
|
123
|
-
if (this.$ownerInstance && typeof this.$ownerInstance.callMethod === 'function') {
|
|
124
|
-
this.$ownerInstance.callMethod('onMapInitialized');
|
|
125
|
-
} else if (this.ownerInstance && typeof this.ownerInstance.callMethod === 'function') {
|
|
126
|
-
this.ownerInstance.callMethod('onMapInitialized');
|
|
127
|
-
}
|
|
128
|
-
} catch (error) {
|
|
129
|
-
console.error('Failed to notify map initialization:', error);
|
|
130
|
-
}
|
|
131
|
-
} catch (error) {
|
|
132
|
-
console.error('Map initialization failed:', error);
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
// 处理视图变化
|
|
137
|
-
handleViewChange() {
|
|
138
|
-
if (!map) {
|
|
139
|
-
console.warn('Map not initialized in handleViewChange');
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const view = map.getView();
|
|
144
|
-
if (!view) {
|
|
145
|
-
console.warn('Map view not available');
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const center = toLonLat(view.getCenter());
|
|
150
|
-
const zoom = view.getZoom();
|
|
151
|
-
|
|
152
|
-
// 确保center和zoom都有有效值
|
|
153
|
-
if (!center || zoom === undefined) {
|
|
154
|
-
console.warn('Invalid center or zoom values');
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
// 确保center数组中的所有元素都是数字类型
|
|
160
|
-
const numericCenter = center.map(coord => typeof coord === 'string' ? parseFloat(coord) : coord);
|
|
161
|
-
|
|
162
|
-
// 首先尝试使用$ownerInstance(标准方式)
|
|
163
|
-
if (this.$ownerInstance && typeof this.$ownerInstance.callMethod === 'function') {
|
|
164
|
-
this.$ownerInstance.callMethod('onMapMove', {
|
|
165
|
-
center: numericCenter,
|
|
166
|
-
zoom: zoom
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
// 兼容旧版本的ownerInstance
|
|
170
|
-
else if (this.ownerInstance && typeof this.ownerInstance.callMethod === 'function') {
|
|
171
|
-
this.ownerInstance.callMethod('onMapMove', {
|
|
172
|
-
center: numericCenter,
|
|
173
|
-
zoom: zoom
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
// 如果都不可用,添加额外的日志信息
|
|
177
|
-
else {
|
|
178
|
-
console.warn('No valid owner instance found for calling onMapMove');
|
|
179
|
-
}
|
|
180
|
-
} catch (error) {
|
|
181
|
-
// 记录详细错误信息以便调试
|
|
182
|
-
console.error('Failed to call onMapMove:', error);
|
|
183
|
-
console.error('Error stack:', error.stack);
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
// 处理属性变化(从 Vue 组件传递过来的配置更新)
|
|
188
|
-
onPropChange(newValue, oldValue) {
|
|
189
|
-
this.mapConfig = newValue;
|
|
190
|
-
if (map && newValue.center && newValue.zoom !== undefined) {
|
|
191
|
-
const view = map.getView();
|
|
192
|
-
|
|
193
|
-
view.animate({
|
|
194
|
-
center: fromLonLat(newValue.center),
|
|
195
|
-
zoom: newValue.zoom,
|
|
196
|
-
duration: 500
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// 处理标记数据变化,添加完整的变更比较逻辑
|
|
201
|
-
if (map && newValue.markers) {
|
|
202
|
-
// 确保标记图层存在
|
|
203
|
-
if (!markerLayer && VectorLayer && VectorSource) {
|
|
204
|
-
markerLayer = new VectorLayer({
|
|
205
|
-
source: new VectorSource(),
|
|
206
|
-
zIndex: 100
|
|
207
|
-
});
|
|
208
|
-
map.addLayer(markerLayer);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// 只有当标记数据确实发生变化时才处理
|
|
212
|
-
const markersChanged = !oldValue ||
|
|
213
|
-
!oldValue.markers ||
|
|
214
|
-
JSON.stringify(newValue.markers) !== JSON.stringify(oldValue.markers);
|
|
215
|
-
|
|
216
|
-
if (markersChanged && Array.isArray(newValue.markers)) {
|
|
217
|
-
// 先清除现有标记
|
|
218
|
-
this.clearMarkers();
|
|
219
|
-
// 添加所有新标记
|
|
220
|
-
newValue.markers.forEach(markerData => {
|
|
221
|
-
if (markerData.coordinates && markerData.coordinates.length === 2) {
|
|
222
|
-
this.addMarker(markerData.coordinates, {
|
|
223
|
-
label: markerData.label,
|
|
224
|
-
fillColor: markerData.fillColor,
|
|
225
|
-
strokeColor: markerData.strokeColor,
|
|
226
|
-
radius: markerData.radius || 6,
|
|
227
|
-
iconSrc: markerData.iconSrc,
|
|
228
|
-
iconScale:markerData.iconScale,
|
|
229
|
-
iconAnchor:markerData.iconAnchor
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
|
|
237
|
-
// 公开方法:设置地图中心
|
|
238
|
-
setCenter(center) {
|
|
239
|
-
if (map && center) {
|
|
240
|
-
const view = map.getView();
|
|
241
|
-
view.setCenter(fromLonLat(center));
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
// 公开方法:设置缩放级别
|
|
245
|
-
setZoom(zoom) {
|
|
246
|
-
if (map && zoom !== undefined) {
|
|
247
|
-
const view = map.getView();
|
|
248
|
-
view.setZoom(zoom);
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
// 公开方法:添加标记点
|
|
252
|
-
addMarker(lonLat, properties = {}) {
|
|
253
|
-
// 参数处理:支持两种调用方式
|
|
254
|
-
// 1. addMarker(lon, lat, label) - 单独参数
|
|
255
|
-
// 2. addMarker([lon, lat], {label: '...'}) - 数组和属性对象
|
|
256
|
-
|
|
257
|
-
let coordinates;
|
|
258
|
-
let props = {};
|
|
259
|
-
|
|
260
|
-
coordinates = lonLat;
|
|
261
|
-
props = properties || {};
|
|
262
|
-
|
|
263
|
-
try {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
// 创建点几何对象
|
|
267
|
-
const point = new Point(fromLonLat(coordinates));
|
|
268
|
-
|
|
269
|
-
// 创建要素
|
|
270
|
-
const marker = new Feature({
|
|
271
|
-
geometry: point
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
// 设置要素属性
|
|
275
|
-
marker.setProperties(props);
|
|
276
|
-
|
|
277
|
-
// 应用样式
|
|
278
|
-
let styles = [];
|
|
279
|
-
|
|
280
|
-
// 基础点样式
|
|
281
|
-
if(props.iconSrc && Icon){
|
|
282
|
-
try {
|
|
283
|
-
// 验证图标路径是否为相对路径
|
|
284
|
-
let iconPath = props.iconSrc;
|
|
285
|
-
console.log('iconScale',props.iconScale);
|
|
286
|
-
// 调试信息:验证图标路径和配置
|
|
287
|
-
const iconConfig = {
|
|
288
|
-
src: iconPath,
|
|
289
|
-
anchor: props.iconAnchor || [0.5, 1], // 默认锚点在底部中心
|
|
290
|
-
scale: props.iconScale || 1,
|
|
291
|
-
crossOrigin: 'anonymous',
|
|
292
|
-
// 添加额外的配置以优化显示
|
|
293
|
-
anchorXUnits: 'fraction',
|
|
294
|
-
anchorYUnits: 'fraction',
|
|
295
|
-
// 添加图标加载重试和超时处理
|
|
296
|
-
imgSize: props.iconSize || undefined // 如果知道尺寸可以直接指定以提高性能
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
console.log('Icon configuration:', iconConfig);
|
|
300
|
-
|
|
301
|
-
// 创建图标样式
|
|
302
|
-
const icon = new Icon(iconConfig);
|
|
303
|
-
|
|
304
|
-
// 添加图片加载状态监听
|
|
305
|
-
icon.getImage().onload = function() {
|
|
306
|
-
console.log('Icon image loaded successfully:', iconPath);
|
|
307
|
-
// 图片加载成功后触发地图更新
|
|
308
|
-
if (map) {
|
|
309
|
-
map.render();
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
icon.getImage().onerror = function(error) {
|
|
314
|
-
console.error('Failed to load icon image:', iconPath);
|
|
315
|
-
// 尝试使用默认样式作为回退
|
|
316
|
-
if (Circle && Fill && Stroke) {
|
|
317
|
-
const fallbackStyle = new Style({
|
|
318
|
-
image: new Circle({
|
|
319
|
-
radius: 8,
|
|
320
|
-
fill: new Fill({ color: 'rgba(255, 0, 0, 0.8)' }),
|
|
321
|
-
stroke: new Stroke({ color: '#ff0000', width: 2 })
|
|
322
|
-
})
|
|
323
|
-
});
|
|
324
|
-
marker.setStyle(fallbackStyle);
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const pointStyle = new Style({
|
|
329
|
-
image: icon
|
|
330
|
-
});
|
|
331
|
-
styles.push(pointStyle);
|
|
332
|
-
console.log('Icon style created and applied');
|
|
333
|
-
} catch (error) {
|
|
334
|
-
console.error('Error creating icon style:', error);
|
|
335
|
-
}
|
|
336
|
-
} else if (Circle && Fill && Stroke) {
|
|
337
|
-
// 如果没有提供图标,则使用默认的圆形标记
|
|
338
|
-
styles.push(new Style({
|
|
339
|
-
image: new Circle({
|
|
340
|
-
radius: props.radius || 8,
|
|
341
|
-
fill: new Fill({
|
|
342
|
-
color: props.fillColor || 'rgba(255, 0, 0, 0.5)'
|
|
343
|
-
}),
|
|
344
|
-
stroke: new Stroke({
|
|
345
|
-
color: props.strokeColor || '#ff0000',
|
|
346
|
-
width: props.strokeWidth || 2
|
|
347
|
-
})
|
|
348
|
-
})
|
|
349
|
-
}));
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// 添加文本标签
|
|
353
|
-
if (props.label && Text) {
|
|
354
|
-
styles.push(new Style({
|
|
355
|
-
text: new Text({
|
|
356
|
-
text: props.label,
|
|
357
|
-
font: '12px Arial',
|
|
358
|
-
fill: new Fill({ color: props.labelColor || '#000' }),
|
|
359
|
-
stroke: new Stroke({ color: props.labelStrokeColor || '#fff', width: 2 }),
|
|
360
|
-
offsetY: props.labelOffsetY || -20
|
|
361
|
-
})
|
|
362
|
-
}));
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// 应用样式到要素
|
|
366
|
-
if (styles.length > 0) {
|
|
367
|
-
marker.setStyle(styles);
|
|
368
|
-
console.log('Styles applied to marker:', styles.length);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// 如果标记图层存在,将标记添加到图层
|
|
372
|
-
if (markerLayer && markerLayer.getSource()) {
|
|
373
|
-
const source = markerLayer.getSource();
|
|
374
|
-
source.addFeature(marker);
|
|
375
|
-
console.log('Marker added to layer source');
|
|
376
|
-
|
|
377
|
-
// 调试:检查图层中的要素数量
|
|
378
|
-
const featureCount = source.getFeatures().length;
|
|
379
|
-
console.log('Current features in marker layer:', featureCount);
|
|
380
|
-
|
|
381
|
-
// 保存标记引用
|
|
382
|
-
markers.push(marker);
|
|
383
|
-
} else {
|
|
384
|
-
console.error('Marker layer or its source is not available');
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// 可选:如果需要,将地图视图移动到标记位置
|
|
388
|
-
if (props.fitToView) {
|
|
389
|
-
map.getView().fit(marker.getGeometry().getExtent(), {
|
|
390
|
-
padding: [50, 50, 50, 50],
|
|
391
|
-
duration: 500
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return marker; // 返回添加的标记,以便进一步操作
|
|
396
|
-
} catch (error) {
|
|
397
|
-
console.error('Failed to add marker:', error);
|
|
398
|
-
return null;
|
|
399
|
-
}
|
|
400
|
-
},
|
|
401
|
-
|
|
402
|
-
// 处理标记数据更新的专用方法
|
|
403
|
-
processMarkers(markersData) {
|
|
404
|
-
|
|
405
|
-
// 先清除现有标记
|
|
406
|
-
this.clearMarkers();
|
|
407
|
-
|
|
408
|
-
// 添加所有新标记
|
|
409
|
-
if (markersData && Array.isArray(markersData)) {
|
|
410
|
-
markersData.forEach(marker => {
|
|
411
|
-
if (marker.coordinates && marker.coordinates.length === 2) {
|
|
412
|
-
this.addMarker(marker.coordinates, {
|
|
413
|
-
label: marker.label || '标记',
|
|
414
|
-
fillColor: marker.fillColor,
|
|
415
|
-
strokeColor: marker.strokeColor,
|
|
416
|
-
radius: marker.radius
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
},
|
|
422
|
-
|
|
423
|
-
// 公开方法:清除所有标记
|
|
424
|
-
clearMarkers() {
|
|
425
|
-
try {
|
|
426
|
-
if (markerLayer && markerLayer.getSource()) {
|
|
427
|
-
markerLayer.getSource().clear();
|
|
428
|
-
markers = [];
|
|
429
|
-
} else {
|
|
430
|
-
console.warn('No marker layer to clear');
|
|
431
|
-
}
|
|
432
|
-
} catch (error) {
|
|
433
|
-
console.error('Failed to clear markers:', error);
|
|
434
|
-
}
|
|
435
|
-
},
|
|
436
|
-
|
|
437
|
-
// 公开方法:将EPSG:3857投影坐标转换为经纬度坐标
|
|
438
|
-
transformToLonLat(coord3857) {
|
|
439
|
-
if (!toLonLat || !Array.isArray(coord3857) || coord3857.length !== 2) {
|
|
440
|
-
console.error('Invalid parameters or toLonLat not available');
|
|
441
|
-
return null;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
// 确保坐标是数字类型
|
|
445
|
-
const numericCoord = coord3857.map(coord => typeof coord === 'string' ? parseFloat(coord) : coord);
|
|
446
|
-
|
|
447
|
-
// 转换为经纬度
|
|
448
|
-
return toLonLat(numericCoord);
|
|
449
|
-
}
|
|
450
|
-
},
|
|
451
|
-
|
|
452
|
-
// 清理资源
|
|
453
|
-
beforeDestroy() {
|
|
454
|
-
if (map) {
|
|
455
|
-
map.setTarget(null);
|
|
456
|
-
map = null;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
};
|
|
4
|
+
data() {
|
|
5
|
+
return {
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
methods: {
|
|
9
|
+
getCls() {
|
|
10
|
+
return Index;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/MapView.js
CHANGED
|
@@ -7,7 +7,7 @@ import Fill from 'ol/style/Fill.js';
|
|
|
7
7
|
import VectorLayer from 'ol/layer/Vector.js';
|
|
8
8
|
import View from 'ol/View.js';
|
|
9
9
|
import Map from 'ol/Map.js';
|
|
10
|
-
|
|
10
|
+
import { fromLonLat } from 'ol/proj.js';
|
|
11
11
|
/**
|
|
12
12
|
* ol地图显示
|
|
13
13
|
*/
|
|
@@ -139,4 +139,16 @@ export default class MapView {
|
|
|
139
139
|
var newMaxY = centerY + newHeight / 2;
|
|
140
140
|
return [newMinX, newMinY, newMaxX, newMaxY];
|
|
141
141
|
}
|
|
142
|
+
setCenter(center,useAnimation){
|
|
143
|
+
if(useAnimation){
|
|
144
|
+
this.map.getView().animate({
|
|
145
|
+
center: fromLonLat(center)
|
|
146
|
+
});
|
|
147
|
+
}else{
|
|
148
|
+
this.map.getView().setCenter(center);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
setZoom(zoom){
|
|
152
|
+
this.map.getView().setZoom(zoom);
|
|
153
|
+
}
|
|
142
154
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ declare module 'cd-mapgis' {
|
|
|
5
5
|
viewOnTemplayer(p: any): void;
|
|
6
6
|
clearTemplayer(): void;
|
|
7
7
|
expandExtent(): void;
|
|
8
|
+
setCenter(center: [number, number], useAnimation?: boolean): void;
|
|
9
|
+
setZoom(zoom: number): void;
|
|
8
10
|
}
|
|
9
|
-
export * as MapRender from './MapRender.js';
|
|
10
11
|
export class OM {
|
|
11
12
|
static map: any;
|
|
12
13
|
static view: any;
|