providers: complete?

This commit is contained in:
muerwre 2018-11-29 13:36:31 +07:00
parent 552e3effb8
commit b6bd300e1b
14 changed files with 150 additions and 29 deletions

View file

@ -1,56 +1,66 @@
// Стили карт
import { editor } from '$modules/Editor';
const TILEMAPS = {
WATERCOLOR: {
name: 'Watercolor',
url: 'http://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg',
range: [1, 4],
range: [1, 2, 3, 4],
},
DGIS: {
name: '2gis',
url: 'https://tile1.maps.2gis.com/tiles?x={x}&y={y}&z={z}&v=1',
range: [1, 3],
range: [1, 2, 3],
},
DEFAULT: {
name: 'OpenStreetMap',
url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
range: [1, 4],
range: ['a', 'b', 'c'],
},
DARQ: {
name: 'Darq',
url: 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
range: [1, 4],
range: [1, 2, 3, 4],
},
BLANK: {
name: 'Blanque',
url: 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
range: [1, 4],
range: [1, 2, 3, 4],
},
HOT: {
name: 'Hot',
url: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
range: [1, 4],
range: ['a', 'b', 'c'],
},
SAY: {
name: 'Google?',
SAT: {
name: 'Google Sattelite',
url: 'http://mt{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',
range: [0, 3],
range: [0, 1, 2, 3],
},
YMAP: {
name: 'Yandex',
url: 'https://vec0{s}.maps.yandex.net/tiles?l=map&v=17.04.16-0&x={x}&y={y}&z={z}&scale=1&lang=ru_RU',
range: [1, 4],
range: [1, 2, 3, 4],
},
YSAT: {
name: 'YandexSat',
url: 'https://sat0{s}.maps.yandex.net/tiles?l=sat&v=3.330.0&x={x}&y={y}&z={z}&lang=ru_RU',
range: [1, 4],
range: [1, 2, 3, 4],
},
};
const ENABLED = ['BLANK', 'DEFAULT', 'DGIS'];
const ENABLED = ['BLANK', 'DEFAULT', 'DGIS', 'HOT'];
export const DEFAULT_PROVIDER = ENABLED[0];
export const PROVIDERS = ENABLED.reduce((obj, provider) => ({
...obj,
[provider]: TILEMAPS[provider],
}), {});
export const replaceProviderUrl = (provider, { x, y, zoom }) => {
console.log('got provider', provider);
const { url, range } = (PROVIDERS[provider] || PROVIDERS[DEFAULT_PROVIDER]);
const random = (range && range.length >= 2) ? range[Math.round((Math.random() * (range.length - 1)))] : 1;
return url.replace('{x}', x).replace('{y}', y).replace('{z}', zoom).replace('{s}', random);
};