Skip to content

Commit 8ab0ddd

Browse files
committed
【fix】修复classic mapv 热力图浏览器缩放比例不为100%偏移的问题,修复webmap加载wmts可能的报错问题 review by luox zhaoq
1 parent 983166f commit 8ab0ddd

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

src/classic/overlay/MapVLayer.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class MapVLayer extends SuperMap.Layer {
5252
if (options) {
5353
SuperMap.Util.extend(this, options);
5454
}
55+
5556
//MapV图要求使用canvas绘制,判断是否支持
5657
this.canvas = document.createElement('canvas');
5758
if (!this.canvas.getContext) {
@@ -67,7 +68,7 @@ export class MapVLayer extends SuperMap.Layer {
6768
this.canvasContext = this.canvas.getContext(context);
6869
var global$2 = typeof window === 'undefined' ? {} : window;
6970
var devicePixelRatio = this.devicePixelRatio = global$2.devicePixelRatio || 1;
70-
if (context == '2d') {
71+
if (context === '2d') {
7172
this.canvasContext.scale(devicePixelRatio, devicePixelRatio);
7273
}
7374
this.attribution =
@@ -162,6 +163,7 @@ export class MapVLayer extends SuperMap.Layer {
162163
setMap(map) {
163164
super.setMap(map);
164165
this.renderer = new MapVRenderer(map, this, this.dataSet, this.options);
166+
this.renderer.devicePixelRatio = this.devicePixelRatio;
165167
if (!this.supported) {
166168
this.map.removeLayer(this);
167169
} else {
@@ -192,8 +194,14 @@ export class MapVLayer extends SuperMap.Layer {
192194
var size = this.map.getSize();
193195
this.div.style.width = parseInt(size.w) + 'px';
194196
this.div.style.height = parseInt(size.h) + 'px';
195-
this.canvas.width = parseInt(size.w);
196-
this.canvas.height = parseInt(size.h);
197+
if (this.options.draw === 'heatmap') {
198+
this.canvas.width = parseInt(size.w) * this.devicePixelRatio;
199+
this.canvas.height = parseInt(size.h) * this.devicePixelRatio;
200+
} else {
201+
this.canvas.width = parseInt(size.w);
202+
this.canvas.height = parseInt(size.h);
203+
}
204+
197205
this.canvas.style.width = this.div.style.width;
198206
this.canvas.style.height = this.div.style.height;
199207
this.maxWidth = size.w;

src/classic/overlay/mapv/MapVRenderer.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export class MapVRenderer extends MapVBaseLayer {
4242
*/
4343
clickEvent(e) {
4444
var pixel = e.xy;
45-
super.clickEvent(pixel, e);
45+
var devicePixelRatio = this.devicePixelRatio || 1;
46+
super.clickEvent({ x: pixel.x / devicePixelRatio, y: pixel.y / devicePixelRatio }, e);
4647
}
4748

4849
/**
@@ -64,10 +65,10 @@ export class MapVRenderer extends MapVBaseLayer {
6465

6566
if (this.options.methods) {
6667
if (this.options.methods.click) {
67-
map.events.on({'click': this.clickEvent});
68+
map.events.on({ click: this.clickEvent });
6869
}
6970
if (this.options.methods.mousemove) {
70-
map.events.on({'mousemove': this.mousemoveEvent});
71+
map.events.on({ mousemove: this.mousemoveEvent });
7172
}
7273
}
7374
}
@@ -81,10 +82,10 @@ export class MapVRenderer extends MapVBaseLayer {
8182

8283
if (this.options.methods) {
8384
if (this.options.methods.click) {
84-
map.events.un({'click': this.clickEvent});
85+
map.events.un({ click: this.clickEvent });
8586
}
8687
if (this.options.methods.mousemove) {
87-
map.events.un({'mousemove': this.mousemoveEvent});
88+
map.events.un({ mousemove: this.mousemoveEvent });
8889
}
8990
}
9091
}
@@ -109,7 +110,7 @@ export class MapVRenderer extends MapVBaseLayer {
109110
_data = data.get();
110111
}
111112
this.dataSet.add(_data);
112-
this.update({options: options});
113+
this.update({ options: options });
113114
}
114115

115116
/**
@@ -125,7 +126,7 @@ export class MapVRenderer extends MapVBaseLayer {
125126
}
126127
this.dataSet = this.dataSet || new DataSet();
127128
this.dataSet.set(_data);
128-
this.update({options: options});
129+
this.update({ options: options });
129130
}
130131

131132
/**
@@ -147,11 +148,11 @@ export class MapVRenderer extends MapVBaseLayer {
147148
}
148149
var newData = this.dataSet.get({
149150
filter: function (data) {
150-
return (filter != null && typeof filter === "function") ? !filter(data) : true;
151+
return filter != null && typeof filter === 'function' ? !filter(data) : true;
151152
}
152153
});
153154
this.dataSet.set(newData);
154-
this.update({options: null});
155+
this.update({ options: null });
155156
}
156157

157158
/**
@@ -160,7 +161,7 @@ export class MapVRenderer extends MapVBaseLayer {
160161
*/
161162
clearData() {
162163
this.dataSet && this.dataSet.clear();
163-
this.update({options: null});
164+
this.update({ options: null });
164165
}
165166

166167
/**
@@ -178,15 +179,24 @@ export class MapVRenderer extends MapVBaseLayer {
178179
* @deprecated
179180
*/
180181
transferToMercator() {
181-
if (this.options.coordType && ["bd09mc", "coordinates_mercator"].indexOf(this.options.coordType) > -1) {
182+
if (this.options.coordType && ['bd09mc', 'coordinates_mercator'].indexOf(this.options.coordType) > -1) {
182183
var data = this.dataSet.get();
183-
data = this.dataSet.transferCoordinate(data, function (coordinates) {
184-
var pixel = SuperMap.Projection.transform({
185-
x: coordinates[0],
186-
y: coordinates[1]
187-
}, "EPSG:3857", "EPSG:4326");
188-
return [pixel.x, pixel.y];
189-
}, 'coordinates', 'coordinates');
184+
data = this.dataSet.transferCoordinate(
185+
data,
186+
function (coordinates) {
187+
var pixel = SuperMap.Projection.transform(
188+
{
189+
x: coordinates[0],
190+
y: coordinates[1]
191+
},
192+
'EPSG:3857',
193+
'EPSG:4326'
194+
);
195+
return [pixel.x, pixel.y];
196+
},
197+
'coordinates',
198+
'coordinates'
199+
);
190200
this.dataSet._set(data);
191201
}
192202
}
@@ -226,15 +236,18 @@ export class MapVRenderer extends MapVBaseLayer {
226236
context.clear(context.COLOR_BUFFER_BIT);
227237
}
228238

229-
if (self.options.minZoom && map.getZoom() < self.options.minZoom || self.options.maxZoom && map.getZoom() > self.options.maxZoom) {
239+
if (
240+
(self.options.minZoom && map.getZoom() < self.options.minZoom) ||
241+
(self.options.maxZoom && map.getZoom() > self.options.maxZoom)
242+
) {
230243
return;
231244
}
232245
var layer = self.canvasLayer;
246+
233247
var dataGetOptions = {
234248
fromColumn: 'coordinates',
235249
transferCoordinate: function (coordinate) {
236-
// var coord = layer.transferToMapLatLng({lon: coordinate[0], lat: coordinate[1]});
237-
var coord = {lon: coordinate[0], lat: coordinate[1]};
250+
var coord = { lon: coordinate[0], lat: coordinate[1] };
238251
var worldPoint = map.getViewPortPxFromLonLat(coord);
239252
return [worldPoint.x, worldPoint.y];
240253
}
@@ -243,8 +256,8 @@ export class MapVRenderer extends MapVBaseLayer {
243256
if (time !== undefined) {
244257
dataGetOptions.filter = function (item) {
245258
var trails = animationOptions.trails || 10;
246-
return (time && item.time > (time - trails) && item.time < time);
247-
}
259+
return time && item.time > time - trails && item.time < time;
260+
};
248261
}
249262

250263
var data = self.dataSet.get(dataGetOptions);
@@ -276,9 +289,7 @@ export class MapVRenderer extends MapVBaseLayer {
276289
self.options.updateCallback && self.options.updateCallback(time);
277290
}
278291

279-
280292
init(options) {
281-
282293
var self = this;
283294

284295
self.options = options;
@@ -299,8 +310,8 @@ export class MapVRenderer extends MapVBaseLayer {
299310
* @description 添加动画事件。
300311
*/
301312
addAnimatorEvent() {
302-
this.map.events.on({'movestart': this.animatorMovestartEvent.bind(this)});
303-
this.map.events.on({'moveend': this.animatorMoveendEvent.bind(this)});
313+
this.map.events.on({ movestart: this.animatorMovestartEvent.bind(this) });
314+
this.map.events.on({ moveend: this.animatorMoveendEvent.bind(this) });
304315
}
305316

306317
/**
@@ -328,7 +339,6 @@ export class MapVRenderer extends MapVBaseLayer {
328339
this.map.removeLayer(this.canvasLayer);
329340
}
330341

331-
332342
/**
333343
* @function MapvRenderer.prototype.draw
334344
* @description 渲染绘制。

src/openlayers/mapping/WebMap.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,18 @@ export class WebMap extends Observable {
14201420
}
14211421
let name = layerInfo.name, extent;
14221422
if (layerBounds) {
1423+
if (layerBounds[0] < -180) {
1424+
layerBounds[0] = -180;
1425+
}
1426+
if (layerBounds[1] < -90) {
1427+
layerBounds[1] = -90;
1428+
}
1429+
if (layerBounds[2] > 180) {
1430+
layerBounds[2] = 180;
1431+
}
1432+
if (layerBounds[3] > 90) {
1433+
layerBounds[3] = 90;
1434+
}
14231435
extent = olProj.transformExtent(layerBounds, 'EPSG:4326', that.baseProjection);
14241436
} else {
14251437
extent = olProj.get(that.baseProjection).getExtent()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy