Transform the layer extent when a user projection is set

This commit is contained in:
Tim Schaub
2019-09-23 15:31:41 +02:00
parent 6525906a70
commit 54d3af40dd
9 changed files with 127 additions and 17 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -0,0 +1,34 @@
import Map from '../../../src/ol/Map.js';
import View from '../../../src/ol/View.js';
import Static from '../../../src/ol/source/ImageStatic.js';
import {
get as getProjection,
transformExtent,
useGeographic
} from '../../../src/ol/proj.js';
import ImageLayer from '../../../src/ol/layer/Image.js';
useGeographic();
const center = [-122.416667, 37.783333];
const extent = [-123.1, 37.1, -122.1, 37.9];
new Map({
pixelRatio: 1,
target: 'map',
layers: [new ImageLayer({
source: new Static({
url: '/data/tiles/osm/5/5/12.png',
imageExtent: transformExtent([-123, 37, -122, 38], 'EPSG:4326', 'EPSG:3857'),
projection: getProjection('EPSG:3857')
}),
extent
})],
view: new View({
center,
zoom: 8,
rotation: Math.PI / 4
})
});
render();

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@@ -0,0 +1,41 @@
/**
* Tile layers get clipped to their extent.
*/
import Map from '../../../src/ol/Map.js';
import View from '../../../src/ol/View.js';
import TileLayer from '../../../src/ol/layer/Tile.js';
import XYZ from '../../../src/ol/source/XYZ.js';
import {useGeographic} from '../../../src/ol/proj.js';
useGeographic();
const center = [7, 50];
const extent = [2, 47, 10, 53];
new Map({
target: 'map',
view: new View({
center: center,
zoom: 3
}),
layers: [
new TileLayer({
source: new XYZ({
url: '/data/tiles/satellite/{z}/{x}/{y}.jpg',
maxZoom: 3
}),
extent: extent
}),
new TileLayer({
source: new XYZ({
url: '/data/tiles/stamen-labels/{z}/{x}/{y}.png',
minZoom: 3,
maxZoom: 5
}),
extent: extent
})
]
});
render();

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,27 @@
import Map from '../../../src/ol/Map.js';
import View from '../../../src/ol/View.js';
import GeoJSON from '../../../src/ol/format/GeoJSON.js';
import VectorLayer from '../../../src/ol/layer/Vector.js';
import VectorSource from '../../../src/ol/source/Vector.js';
import {useGeographic} from '../../../src/ol/proj.js';
useGeographic();
new Map({
target: 'map',
view: new View({
center: [0, 0],
zoom: 1
}),
layers: [
new VectorLayer({
extent: [-50, -45, 50, 45],
source: new VectorSource({
url: '/data/countries.json',
format: new GeoJSON()
})
})
]
});
render();