mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 08:17:30 +02:00
Merge pull request #4814 from openstreetmap/wms-tiles
Load WMS tiles if EPSG:3857 (or equivalent) is supported by source
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import _clone from 'lodash-es/clone';
|
||||
import _some from 'lodash-es/some';
|
||||
|
||||
import { geoArea as d3_geoArea } from 'd3-geo';
|
||||
import {
|
||||
geoArea as d3_geoArea,
|
||||
geoMercatorRaw as d3_geoMercatorRaw
|
||||
} from 'd3-geo';
|
||||
|
||||
import { t } from '../util/locale';
|
||||
import { geoExtent, geoPolygonIntersectsPolygon } from '../geo';
|
||||
@@ -29,6 +32,17 @@ function vintageRange(vintage) {
|
||||
return s;
|
||||
}
|
||||
|
||||
function getEPSG3857XY(x, y, z) {
|
||||
var zoomSize = Math.pow(2, z);
|
||||
var lon = x / zoomSize * Math.PI * 2 - Math.PI;
|
||||
var lat = Math.atan(Math.sinh(Math.PI * (1 - 2 * y / zoomSize)));
|
||||
var mercCoords = d3_geoMercatorRaw(lon, lat);
|
||||
return {
|
||||
x: 20037508.34 / Math.PI * mercCoords[0],
|
||||
y: 20037508.34 / Math.PI * mercCoords[1]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function rendererBackgroundSource(data) {
|
||||
var source = _clone(data);
|
||||
@@ -93,6 +107,15 @@ export function rendererBackgroundSource(data) {
|
||||
|
||||
|
||||
source.url = function(coord) {
|
||||
if (this.type === 'wms') {
|
||||
var minXmaxY = getEPSG3857XY(coord[0], coord[1], coord[2]);
|
||||
var maxXminY = getEPSG3857XY(coord[0]+1, coord[1]+1, coord[2]);
|
||||
return template
|
||||
.replace('{width}', 256)
|
||||
.replace('{height}', 256)
|
||||
.replace('{proj}', this.projection)
|
||||
.replace('{bbox}', minXmaxY.x + ',' + maxXminY.y + ',' + maxXminY.x + ',' + minXmaxY.y);
|
||||
}
|
||||
return template
|
||||
.replace('{x}', coord[0])
|
||||
.replace('{y}', coord[1])
|
||||
|
||||
Reference in New Issue
Block a user