Skip to content

Commit 2872fa1

Browse files
committed
优化mvpv在浏览器缩放时的显示
1 parent 81366eb commit 2872fa1

File tree

9 files changed

+1553
-1472
lines changed

9 files changed

+1553
-1472
lines changed

dist/iclient9-leaflet.js

Lines changed: 733 additions & 721 deletions
Large diffs are not rendered by default.

dist/iclient9-leaflet.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/iclient9-mapboxgl.js

Lines changed: 765 additions & 728 deletions
Large diffs are not rendered by default.

dist/iclient9-mapboxgl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/leaflet/overlay/MapVLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export var MapVLayer = L.Layer.extend({
197197
var global$2 = typeof window === 'undefined' ? {} : window;
198198
var devicePixelRatio = this.devicePixelRatio = global$2.devicePixelRatio;
199199
if (this.mapVOptions.context == '2d') {
200-
canvas.getContext(this.mapVOptions.context).scale(devicePixelRatio, devicePixelRatio);
200+
canvas.getContext('2d').scale(devicePixelRatio, devicePixelRatio);
201201
}
202202
return canvas;
203203
},

src/leaflet/overlay/mapv/MapVRenderer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class MapVRenderer extends BaseLayer {
4646
*/
4747
clickEvent(e) {
4848
var offset = this.map.containerPointToLayerPoint([0, 0]);
49-
var devicePixelRatio = this.devicePixelRatio = window.devicePixelRatio;
49+
var devicePixelRatio = this.devicePixelRatio = this.canvasLayer.devicePixelRatio = window.devicePixelRatio;
5050
var pixel = e.layerPoint;
5151
super.clickEvent(L.point((pixel.x - offset.x) / devicePixelRatio, (pixel.y - offset.y) / devicePixelRatio), e);
5252
}
@@ -183,7 +183,9 @@ export class MapVRenderer extends BaseLayer {
183183
*/
184184
clearData() {
185185
this.dataSet && this.dataSet.clear();
186-
this.update({options: null});
186+
this.update({
187+
options: null
188+
});
187189
}
188190

189191
_canvasUpdate(time) {
@@ -300,8 +302,7 @@ export class MapVRenderer extends BaseLayer {
300302
this.initAnimator();
301303
}
302304

303-
addAnimatorEvent() {
304-
}
305+
addAnimatorEvent() {}
305306

306307
/**
307308
* @function L.supermap.MapVRenderer.prototype.moveStartEvent

src/mapboxgl/overlay/MapvLayer.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import mapboxgl from 'mapbox-gl';
22
import '../core/Base';
3-
import {MapvRenderer} from "./mapv/MapvRenderer";
3+
import {
4+
MapvRenderer
5+
} from "./mapv/MapvRenderer";
46

57
/**
68
* @class mapboxgl.supermap.MapvLayer
@@ -119,8 +121,8 @@ export class MapvLayer {
119121
canvas.style.left = 0 + "px";
120122
var global$2 = typeof window === 'undefined' ? {} : window;
121123
var devicePixelRatio = this.devicePixelRatio = global$2.devicePixelRatio;
122-
canvas.width = parseInt(this.map.getCanvas().style.width)*devicePixelRatio;
123-
canvas.height = parseInt(this.map.getCanvas().style.height)*devicePixelRatio;
124+
canvas.width = parseInt(this.map.getCanvas().style.width) * devicePixelRatio;
125+
canvas.height = parseInt(this.map.getCanvas().style.height) * devicePixelRatio;
124126
if (this.mapVOptions.context == '2d') {
125127
canvas.getContext(this.mapVOptions.context).scale(devicePixelRatio, devicePixelRatio);
126128
}
@@ -154,6 +156,14 @@ export class MapvLayer {
154156
nextLayer.parentNode.appendChild(layer);
155157
}
156158
}
159+
/**
160+
* @function mapboxgl.supermap.MapvLayer.prototype.setZIndex
161+
* @description 设置canvas层级
162+
* @param {number} zIndex - canvas层级
163+
*/
164+
setZIndex(z) {
165+
this.canvas.style.zIndex = z;
166+
}
157167

158168
}
159169

src/mapboxgl/overlay/mapv/MapvRenderer.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {baiduMapLayer} from "mapv";
1+
import {
2+
baiduMapLayer
3+
} from "mapv";
24
import mapboxgl from 'mapbox-gl';
35

46
var BaseLayer = baiduMapLayer ? baiduMapLayer.__proto__ : Function;
@@ -118,7 +120,9 @@ export class MapvRenderer extends BaseLayer {
118120
_data = data.get();
119121
}
120122
this.dataSet.add(_data);
121-
this.update({options: options});
123+
this.update({
124+
options: options
125+
});
122126
}
123127

124128
/**
@@ -137,7 +141,9 @@ export class MapvRenderer extends BaseLayer {
137141
if (_data != undefined) {
138142
this.dataSet.set(_data);
139143
}
140-
super.update({options: update.options});
144+
super.update({
145+
options: update.options
146+
});
141147
}
142148

143149
/**
@@ -163,7 +169,9 @@ export class MapvRenderer extends BaseLayer {
163169
}
164170
});
165171
this.dataSet.set(newData);
166-
this.update({options: null});
172+
this.update({
173+
options: null
174+
});
167175
}
168176

169177
/**
@@ -172,7 +180,9 @@ export class MapvRenderer extends BaseLayer {
172180
*/
173181
clearData() {
174182
this.dataSet && this.dataSet.clear();
175-
this.update({options: null});
183+
this.update({
184+
options: null
185+
});
176186
}
177187

178188
/**
@@ -185,7 +195,9 @@ export class MapvRenderer extends BaseLayer {
185195
if (dataSet && dataSet.get) {
186196
this.dataSet.set(dataSet.get());
187197
}
188-
this.update({options: options});
198+
this.update({
199+
options: options
200+
});
189201
}
190202

191203
_canvasUpdate(time) {
@@ -237,7 +249,7 @@ export class MapvRenderer extends BaseLayer {
237249
var centerPx = map.project(center);
238250
var dataGetOptions = {
239251
transferCoordinate: function (coordinate) {
240-
if (map.transform.rotationMatrix) {
252+
if (map.transform.rotationMatrix || self.context === '2d') {
241253
var worldPoint = map.project((new mapboxgl.LngLat(coordinate[0], coordinate[1])));
242254
return [worldPoint.x, worldPoint.y];
243255
}
@@ -310,9 +322,11 @@ export class MapvRenderer extends BaseLayer {
310322
canvas.style.left = 0 + "px";
311323
var global$2 = typeof window === 'undefined' ? {} : window;
312324
var devicePixelRatio = this.canvasLayer.devicePixelRatio = global$2.devicePixelRatio;
313-
canvas.width = parseInt(this.map.getCanvas().style.width)*devicePixelRatio;
314-
canvas.height = parseInt(this.map.getCanvas().style.height)*devicePixelRatio;
315-
325+
canvas.width = parseInt(this.map.getCanvas().style.width) * devicePixelRatio;
326+
canvas.height = parseInt(this.map.getCanvas().style.height) * devicePixelRatio;
327+
if (this.canvasLayer.mapVOptions.context == '2d') {
328+
canvas.getContext('2d').scale(devicePixelRatio, devicePixelRatio);
329+
}
316330
canvas.style.width = this.map.getCanvas().style.width;
317331
canvas.style.height = this.map.getCanvas().style.height;
318332
}
@@ -394,7 +408,7 @@ export class MapvRenderer extends BaseLayer {
394408
* @description 清除环境
395409
*/
396410
clear(context) {
397-
context && context.clearRect && context.clearRect(0, 0, context.canvas.width, context.canvas.height);
411+
context && context.clearRect && context.clearRect(0, 0, parseInt(this.map.getCanvas().style.width), parseInt(this.map.getCanvas().style.height));
398412
}
399413

400414
/**

src/openlayers/overlay/mapv/MapvCanvasLayer.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export class MapvCanvasLayer {
3434
canvas.className = "mapvClass";
3535
var global$2 = typeof window === 'undefined' ? {} : window;
3636
var devicePixelRatio = me.devicePixelRatio = global$2.devicePixelRatio;
37-
canvas.width = me.width;
38-
canvas.height = me.height;
37+
canvas.width = parseInt(me.width) * devicePixelRatio;
38+
canvas.height = parseInt(me.height) * devicePixelRatio;
3939
if (me.context == '2d') {
4040
canvas.getContext(me.context).scale(devicePixelRatio, devicePixelRatio);
4141
}
@@ -60,6 +60,13 @@ export class MapvCanvasLayer {
6060
resize(mapWidth, mapHeight) {
6161
this.canvas.width = mapWidth;
6262
this.canvas.height = mapHeight;
63+
var global$2 = typeof window === 'undefined' ? {} : window;
64+
var devicePixelRatio = this.devicePixelRatio = global$2.devicePixelRatio;
65+
this.canvas.width = parseInt(this.width) * devicePixelRatio;
66+
this.canvas.height = parseInt(this.height) * devicePixelRatio;
67+
if (this.context == '2d') {
68+
this.canvas.getContext('2d').scale(devicePixelRatio, devicePixelRatio);
69+
}
6370
this.canvas.style.width = mapWidth + "px";
6471
this.canvas.style.height = mapHeight + "px";
6572
}

0 commit comments

Comments
 (0)