Skip to content

Commit a2646e8

Browse files
committed
[fix]修复ICL1336 ICL1337,ol纽约18万放大canvas显示不全 review by songym
1 parent bbd3de7 commit a2646e8

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

src/openlayers/overlay/graphic/CanvasRenderer.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ export class GraphicCanvasRenderer extends olObject {
4747
CommonUtil.extend(this, opt);
4848
this.highLightStyle = this.layer.highLightStyle;
4949

50-
this.mapWidth = this.size[0];
51-
this.mapHeight = this.size[1];
50+
this.mapWidth = this.size[0] / this.pixelRatio;
51+
this.mapHeight = this.size[1] / this.pixelRatio;
5252
this.width = this.map.getSize()[0];
5353
this.height = this.map.getSize()[1];
54-
5554
this.context = Util.createCanvasContext2D(this.mapWidth, this.mapHeight);
5655
this.context.scale(this.pixelRatio, this.pixelRatio);
5756
this.canvas = this.context.canvas;
@@ -79,7 +78,6 @@ export class GraphicCanvasRenderer extends olObject {
7978
this.height = height;
8079
this.mapWidth = this.mapWidth * xRatio;
8180
this.mapHeight = this.mapHeight * yRatio;
82-
8381
this.canvas.width = this.mapWidth;
8482
this.canvas.height = this.mapHeight;
8583
this.canvas.style.width = this.width + 'px';
@@ -114,18 +112,18 @@ export class GraphicCanvasRenderer extends olObject {
114112
*/
115113
drawGraphics(graphics) {
116114
this.graphics_ = graphics || [];
117-
let mapWidth = this.mapWidth / this.pixelRatio;
118-
let mapHeight = this.mapHeight / this.pixelRatio;
115+
let mapWidth = this.mapWidth;
116+
let mapHeight = this.mapHeight;
119117

120118
let vectorContext = olRender.toContext(this.context, {
121119
size: [mapWidth, mapHeight],
122120
pixelRatio: this.pixelRatio
123121
});
124-
var defaultStyle = this.layer._getDefaultStyle();
122+
let defaultStyle = this.layer._getDefaultStyle();
125123
let me = this,
126124
layer = me.layer,
127125
map = layer.map;
128-
graphics.map(function(graphic) {
126+
graphics.map(function (graphic) {
129127
let style = graphic.getStyle() || defaultStyle;
130128
if (me.selected === graphic) {
131129
let defaultHighLightStyle = style;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { GraphicCanvasRenderer } from '../../../../src/openlayers/overlay/graphic/CanvasRenderer';
2+
import Map from 'ol/Map';
3+
import View from 'ol/View';
4+
5+
var map = new Map({
6+
target: 'map',
7+
view: new View({
8+
center: [116.85, 39.79],
9+
zoom: 0,
10+
projection: 'EPSG:4326'
11+
})
12+
});
13+
describe('openlayers_render', () => {
14+
var render;
15+
it('constructor', () => {
16+
spyOn(map, 'getSize').and.callFake(() => {
17+
return [0, 0];
18+
});
19+
const size = [1920, 1080];
20+
let pixelRatio = 1;
21+
render = new GraphicCanvasRenderer('layer', { size, pixelRatio, map });
22+
expect(render).not.toBeNull();
23+
expect(render.mapWidth).toBe(1920);
24+
expect(render.mapHeight).toBe(1080);
25+
pixelRatio = 1.5;
26+
render = new GraphicCanvasRenderer('layer', { size, pixelRatio, map });
27+
expect(render).not.toBeNull();
28+
expect(render.mapWidth).toBe(1280);
29+
expect(render.mapHeight).toBe(720);
30+
});
31+
});

test/test-main-openlayers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import './openlayers/mapping/WebMapSpec.js';
1515
import './openlayers/overlay/DataFlowSpec.js';
1616
import './openlayers/overlay/graphic/GraphicSpec.js';
1717
import './openlayers/overlay/GraphicSpec.js';
18+
import './openlayers/overlay/graphic/CanvasRendererSpec';
1819

1920
import './openlayers/overlay/GraphSpec.js';
2021
import './openlayers/overlay/HeatMapSpec.js';

0 commit comments

Comments
 (0)