Merge pull request #11563 from MoonE/multi-world-fix-end-world

Fix end world calculation if projection is not symmetric
This commit is contained in:
Andreas Hocevar
2020-09-17 18:19:32 +02:00
committed by GitHub
3 changed files with 70 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,69 @@
import Feature from '../../../src/ol/Feature.js';
import Fill from '../../../src/ol/style/Fill.js';
import Map from '../../../src/ol/Map.js';
import Polygon from '../../../src/ol/geom/Polygon.js';
import Style from '../../../src/ol/style/Style.js';
import VectorLayer from '../../../src/ol/layer/Vector.js';
import VectorSource from '../../../src/ol/source/Vector.js';
import View from '../../../src/ol/View.js';
import {Projection, addCoordinateTransforms} from '../../../src/ol/proj.js';
import {fromEPSG4326, toEPSG4326} from '../../../src/ol/proj/epsg3857.js';
const projection = new Projection({
code: 'custom',
units: 'm',
global: true,
extent: [-40075016.68557849, -20037508.342789244, 0, 20037508.342789244],
});
addCoordinateTransforms(
'EPSG:4326',
projection,
function (coord) {
const converted = fromEPSG4326(coord);
converted[0] -= 20037508.342789244;
return converted;
},
function (coord) {
return toEPSG4326([coord[0] + 20037508.342789244, coord[1]]);
}
);
const feature = new Feature({
geometry: new Polygon([
[
[-20037508.342789244, 20037508.342789244],
[-20037508.342789244, -20037508.342789244],
[-16037508.342789244, -20037508.342789244],
[-16037508.342789244, 20037508.342789244],
[-20037508.342789244, 20037508.342789244],
],
]),
});
new Map({
pixelRatio: 1,
layers: [
new VectorLayer({
renderBuffer: 0,
source: new VectorSource({
features: [feature],
}),
style: new Style({
fill: new Fill({
color: 'black',
}),
}),
}),
],
target: 'map',
view: new View({
projection: projection,
multiWorld: true,
maxResolution: 485254.1017841229,
zoom: 0,
center: [2000000, 0],
}),
});
render();

View File

@@ -224,7 +224,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
const multiWorld = vectorSource.getWrapX() && projection.canWrapX();
const worldWidth = multiWorld ? getWidth(projectionExtent) : null;
const endWorld = multiWorld
? Math.ceil((extent[2] + projectionExtent[2]) / worldWidth)
? Math.ceil((extent[2] - projectionExtent[2]) / worldWidth) + 1
: 1;
let world = multiWorld
? Math.floor((extent[0] - projectionExtent[0]) / worldWidth)