mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-26 23:43:46 +00: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:
60711
data/imagery.json
60711
data/imagery.json
File diff suppressed because one or more lines are too long
@@ -32,6 +32,16 @@ var blacklist = {
|
||||
'OSM_Inspector-Routing': true,
|
||||
'OSM_Inspector-Tagging': true
|
||||
};
|
||||
var supportedWMSProjections = [
|
||||
'EPSG:3857',
|
||||
'EPSG:900913', // EPSG:3857 alternatives codes
|
||||
'EPSG:3587',
|
||||
'EPSG:54004',
|
||||
'EPSG:41001',
|
||||
'EPSG:102113',
|
||||
'EPSG:102100',
|
||||
'EPSG:3785'
|
||||
];
|
||||
|
||||
var whitelist = [
|
||||
// Add custom sources here if needed.
|
||||
@@ -39,8 +49,15 @@ var whitelist = [
|
||||
|
||||
|
||||
sources.concat(whitelist).forEach(function(source) {
|
||||
if (source.type !== 'tms' && source.type !== 'bing') return;
|
||||
if (source.type !== 'tms' && source.type !== 'wms' && source.type !== 'bing') return;
|
||||
if (source.id in blacklist) return;
|
||||
var supportedProjection = source.available_projections &&
|
||||
supportedWMSProjections.find(function(supportedProjection) {
|
||||
return source.available_projections.some(function(projection) {
|
||||
return supportedProjection === projection;
|
||||
})
|
||||
});
|
||||
if (source.type === 'wms' && supportedProjection === undefined) return;
|
||||
|
||||
var im = {
|
||||
id: source.id,
|
||||
@@ -49,6 +66,10 @@ sources.concat(whitelist).forEach(function(source) {
|
||||
template: source.url
|
||||
};
|
||||
|
||||
if (source.type === 'wms') {
|
||||
im.projection = supportedProjection;
|
||||
}
|
||||
|
||||
var startDate, endDate, isValid;
|
||||
|
||||
if (source.end_date) {
|
||||
|
||||
@@ -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