mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 19:16:41 +07:00
providers: initial
This commit is contained in:
parent
b85141046d
commit
552e3effb8
16 changed files with 133 additions and 49 deletions
|
@ -103,6 +103,13 @@ class Component extends React.PureComponent<Props, void> {
|
||||||
<Icon icon="icon-trash-4" />
|
<Icon icon="icon-trash-4" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className={classnames({ active: mode === MODES.TRASH })}
|
||||||
|
onClick={this.props.takeAShot}
|
||||||
|
>
|
||||||
|
<Icon icon="icon-shot-3" />
|
||||||
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
className={classnames('disabled', { active: mode === MODES.LOGO })}
|
className={classnames('disabled', { active: mode === MODES.LOGO })}
|
||||||
>
|
>
|
||||||
|
|
|
@ -2,20 +2,15 @@ import React from 'react';
|
||||||
import { Icon } from '$components/panels/Icon';
|
import { Icon } from '$components/panels/Icon';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
onCancel: Function,
|
||||||
|
onSubmit: Function,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const RendererPanel = ({ onCancel, onSubmit }): Props => (
|
export const RendererPanel = ({ onCancel, onSubmit }: Props) => (
|
||||||
<div
|
<div
|
||||||
className="panel active center"
|
className="panel active center"
|
||||||
style={{ zIndex: 1000 }}
|
style={{ zIndex: 1000 }}
|
||||||
>
|
>
|
||||||
<div className="control-bar control-bar-padded">
|
|
||||||
<button>
|
|
||||||
<Icon icon="icon-logo-3" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="control-sep" />
|
<div className="control-sep" />
|
||||||
|
|
||||||
<div className="control-bar">
|
<div className="control-bar">
|
||||||
|
@ -37,3 +32,11 @@ export const RendererPanel = ({ onCancel, onSubmit }): Props => (
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
<div className="control-bar control-bar-padded">
|
||||||
|
<button>
|
||||||
|
<Icon icon="icon-logo-3" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
*/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { providers } from '$constants/providers';
|
import { DEFAULT_PROVIDER, PROVIDERS } from '$constants/providers';
|
||||||
|
|
||||||
export const CONFIG = {
|
export const CONFIG = {
|
||||||
OSRM_URL: 'http://vault48.org:5000/route/v1',
|
OSRM_URL: 'http://vault48.org:5000/route/v1',
|
||||||
|
@ -9,4 +9,4 @@ export const COLORS = {
|
||||||
PATH_COLOR: ['#ff7700', '#ff3344'],
|
PATH_COLOR: ['#ff7700', '#ff3344'],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PROVIDER = providers.blank;
|
export const PROVIDER = PROVIDERS[DEFAULT_PROVIDER];
|
||||||
|
|
|
@ -7,5 +7,6 @@ export const MODES = {
|
||||||
NONE: 'NONE',
|
NONE: 'NONE',
|
||||||
LOGO: 'LOGO',
|
LOGO: 'LOGO',
|
||||||
SAVE: 'SAVE',
|
SAVE: 'SAVE',
|
||||||
CONFIRM_CANCEL: 'CONFIRM_CANCEL'
|
CONFIRM_CANCEL: 'CONFIRM_CANCEL',
|
||||||
|
PROVIDER: 'PROVIDER',
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,56 @@
|
||||||
// Стили карт
|
// Стили карт
|
||||||
export const providers = {
|
const TILEMAPS = {
|
||||||
'watercolor': 'http://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg',
|
WATERCOLOR: {
|
||||||
'darq': 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
|
name: 'Watercolor',
|
||||||
'dgis': 'https://tile1.maps.2gis.com/tiles?x={x}&y={y}&z={z}&v=1',
|
url: 'http://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg',
|
||||||
'default': 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
range: [1, 4],
|
||||||
'hot': 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
|
},
|
||||||
'blank': 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
|
DGIS: {
|
||||||
'sat': 'http://mt0.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',
|
name: '2gis',
|
||||||
'ymap': 'https://vec03.maps.yandex.net/tiles?l=map&v=17.04.16-0&x={x}&y={y}&z={z}&scale=1&lang=ru_RU',
|
url: 'https://tile1.maps.2gis.com/tiles?x={x}&y={y}&z={z}&v=1',
|
||||||
'ysat': 'https://sat02.maps.yandex.net/tiles?l=sat&v=3.330.0&x={x}&y={y}&z={z}&lang=ru_RU'
|
range: [1, 3],
|
||||||
|
},
|
||||||
|
DEFAULT: {
|
||||||
|
name: 'OpenStreetMap',
|
||||||
|
url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||||
|
range: [1, 4],
|
||||||
|
},
|
||||||
|
DARQ: {
|
||||||
|
name: 'Darq',
|
||||||
|
url: 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
|
||||||
|
range: [1, 4],
|
||||||
|
},
|
||||||
|
BLANK: {
|
||||||
|
name: 'Blanque',
|
||||||
|
url: 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
|
||||||
|
range: [1, 4],
|
||||||
|
},
|
||||||
|
HOT: {
|
||||||
|
name: 'Hot',
|
||||||
|
url: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
|
||||||
|
range: [1, 4],
|
||||||
|
},
|
||||||
|
SAY: {
|
||||||
|
name: 'Google?',
|
||||||
|
url: 'http://mt{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',
|
||||||
|
range: [0, 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],
|
||||||
|
},
|
||||||
|
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],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ENABLED = ['BLANK', 'DEFAULT', 'DGIS'];
|
||||||
|
|
||||||
|
export const DEFAULT_PROVIDER = ENABLED[0];
|
||||||
|
export const PROVIDERS = ENABLED.reduce((obj, provider) => ({
|
||||||
|
...obj,
|
||||||
|
[provider]: TILEMAPS[provider],
|
||||||
|
}), {});
|
||||||
|
|
|
@ -23,10 +23,7 @@ const Component = (props: Props) => (
|
||||||
<UserLocation />
|
<UserLocation />
|
||||||
<UserPanel />
|
<UserPanel />
|
||||||
<EditorPanel />
|
<EditorPanel />
|
||||||
{
|
{ props.renderer_active && <Renderer onClick={props.hideRenderer} /> }
|
||||||
props.renderer_active &&
|
|
||||||
<Renderer onClick={props.hideRenderer} />
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
setRouterPoints,
|
setRouterPoints,
|
||||||
setTitle,
|
setTitle,
|
||||||
} from '$redux/user/actions';
|
} from '$redux/user/actions';
|
||||||
|
import { DEFAULT_PROVIDER, PROVIDERS } from '$constants/providers';
|
||||||
|
|
||||||
export class Editor {
|
export class Editor {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -27,6 +28,7 @@ export class Editor {
|
||||||
this.initialData = {};
|
this.initialData = {};
|
||||||
this.activeSticker = null;
|
this.activeSticker = null;
|
||||||
this.mode = MODES.NONE;
|
this.mode = MODES.NONE;
|
||||||
|
this.provider = PROVIDERS[DEFAULT_PROVIDER];
|
||||||
|
|
||||||
const {
|
const {
|
||||||
triggerOnChange, lockMapClicks, routerMoveStart, changeMode, pushPolyPoints,
|
triggerOnChange, lockMapClicks, routerMoveStart, changeMode, pushPolyPoints,
|
||||||
|
@ -241,7 +243,7 @@ export class Editor {
|
||||||
};
|
};
|
||||||
|
|
||||||
fitDrawing = () => {
|
fitDrawing = () => {
|
||||||
if (this.poly.isEmpty()) return;
|
if (this.poly.isEmpty) return;
|
||||||
|
|
||||||
const bounds = this.poly.poly.getBounds();
|
const bounds = this.poly.poly.getBounds();
|
||||||
if (bounds && Object.values(bounds)) this.map.map.fitBounds(bounds);
|
if (bounds && Object.values(bounds)) this.map.map.fitBounds(bounds);
|
||||||
|
@ -289,7 +291,7 @@ export class Editor {
|
||||||
};
|
};
|
||||||
|
|
||||||
cancelEditing = () => {
|
cancelEditing = () => {
|
||||||
if (this.hasEmptyHistory()) {
|
if (this.hasEmptyHistory) {
|
||||||
this.clearAll();
|
this.clearAll();
|
||||||
this.startEditing();
|
this.startEditing();
|
||||||
} else {
|
} else {
|
||||||
|
@ -307,19 +309,18 @@ export class Editor {
|
||||||
stickers: this.stickers.dumpData(),
|
stickers: this.stickers.dumpData(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// isEmpty = () => {
|
setProvider = provider => {
|
||||||
// const { route, stickers } = this.dumpData();
|
this.provider = provider;
|
||||||
//
|
this.map.setProvider(provider);
|
||||||
// return (route.length > 1 && stickers.length > 0);
|
};
|
||||||
// };
|
|
||||||
|
|
||||||
isEmpty = () => {
|
get isEmpty() {
|
||||||
const { route, stickers } = this.dumpData();
|
const { route, stickers } = this.dumpData();
|
||||||
|
|
||||||
return (!route || route.length < 1) && (!stickers || stickers.length <= 0);
|
return (!route || route.length < 1) && (!stickers || stickers.length <= 0);
|
||||||
};
|
}
|
||||||
|
|
||||||
hasEmptyHistory = () => {
|
get hasEmptyHistory() {
|
||||||
const { route, stickers } = this.initialData;
|
const { route, stickers } = this.initialData;
|
||||||
|
|
||||||
return (!route || route.length < 1) && (!stickers || stickers.length <= 0);
|
return (!route || route.length < 1) && (!stickers || stickers.length <= 0);
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
import { map, tileLayer } from 'leaflet';
|
import { map, tileLayer } from 'leaflet';
|
||||||
// import { Map as map } from 'leaflet/src/map/Map';
|
|
||||||
// import { TileLayer as tileLayer } from 'leaflet/src/layer/tile/TileLayer';
|
|
||||||
|
|
||||||
import 'leaflet/dist/leaflet.css';
|
import 'leaflet/dist/leaflet.css';
|
||||||
import 'leaflet-editable';
|
import 'leaflet-editable';
|
||||||
import { PROVIDER } from '$config';
|
import { PROVIDER } from '$config';
|
||||||
|
import { DEFAULT_PROVIDER, PROVIDERS } from '$constants/providers';
|
||||||
|
|
||||||
export class Map {
|
export class Map {
|
||||||
constructor({ container }) {
|
constructor({ container }) {
|
||||||
this.map = map(container, { editable: true }).setView([55.0153275, 82.9071235], 13);
|
this.map = map(container, { editable: true }).setView([55.0153275, 82.9071235], 13);
|
||||||
|
|
||||||
this.tileLayer = tileLayer(PROVIDER, {
|
this.tileLayer = tileLayer(PROVIDER.url, {
|
||||||
attribution: 'Независимое Велосообщество',
|
attribution: 'Независимое Велосообщество',
|
||||||
maxNativeZoom: 18,
|
maxNativeZoom: 18,
|
||||||
maxZoom: 18,
|
maxZoom: 18,
|
||||||
|
@ -18,4 +16,10 @@ export class Map {
|
||||||
|
|
||||||
this.tileLayer.addTo(this.map);
|
this.tileLayer.addTo(this.map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setProvider = provider => {
|
||||||
|
const { url } = (provider && PROVIDERS[provider] && PROVIDERS[provider]) || PROVIDERS[DEFAULT_PROVIDER];
|
||||||
|
|
||||||
|
this.tileLayer.setUrl(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,5 +161,7 @@ export class Poly {
|
||||||
|
|
||||||
dumpData = () => this.latlngs;
|
dumpData = () => this.latlngs;
|
||||||
|
|
||||||
isEmpty = () => !this.latlngs || Object.values(this.latlngs).length < 0;
|
get isEmpty() {
|
||||||
|
return (!this.latlngs || Object.values(this.latlngs).length <= 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { userSaga } from '$redux/user/sagas';
|
||||||
|
|
||||||
const userPersistConfig = {
|
const userPersistConfig = {
|
||||||
key: 'user',
|
key: 'user',
|
||||||
whitelist: ['user', 'logo'],
|
whitelist: ['user', 'logo', 'provider'],
|
||||||
storage,
|
storage,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,3 +38,4 @@ export const setRenderer = payload => ({ type: ACTIONS.SET_RENDERER, payload });
|
||||||
export const takeAShot = () => ({ type: ACTIONS.TAKE_A_SHOT });
|
export const takeAShot = () => ({ type: ACTIONS.TAKE_A_SHOT });
|
||||||
export const cropAShot = payload => ({ type: ACTIONS.CROP_A_SHOT, ...payload });
|
export const cropAShot = payload => ({ type: ACTIONS.CROP_A_SHOT, ...payload });
|
||||||
|
|
||||||
|
export const setProvider = provider => ({ type: ACTIONS.SET_PROVIDER, provider });
|
||||||
|
|
|
@ -36,4 +36,6 @@ export const ACTIONS = {
|
||||||
SET_RENDERER: 'SET_RENDERER',
|
SET_RENDERER: 'SET_RENDERER',
|
||||||
TAKE_A_SHOT: 'TAKE_A_SHOT',
|
TAKE_A_SHOT: 'TAKE_A_SHOT',
|
||||||
CROP_A_SHOT: 'CROP_A_SHOT',
|
CROP_A_SHOT: 'CROP_A_SHOT',
|
||||||
|
|
||||||
|
SET_PROVIDER: 'SET_PROVIDER',
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { DEFAULT_USER } from '$constants/auth';
|
||||||
import { MODES } from '$constants/modes';
|
import { MODES } from '$constants/modes';
|
||||||
import { DEFAULT_LOGO } from '$constants/logos';
|
import { DEFAULT_LOGO } from '$constants/logos';
|
||||||
import { TIPS } from '$constants/tips';
|
import { TIPS } from '$constants/tips';
|
||||||
|
import { DEFAULT_PROVIDER } from '$constants/providers';
|
||||||
|
|
||||||
const getEstimated = distance => {
|
const getEstimated = distance => {
|
||||||
const time = (distance && (distance / 15)) || 0;
|
const time = (distance && (distance / 15)) || 0;
|
||||||
|
@ -70,6 +71,8 @@ const setRenderer = (state, { payload }) => ({
|
||||||
renderer: { ...state.renderer, ...payload }
|
renderer: { ...state.renderer, ...payload }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const setProvider = (state, { provider }) => ({ ...state, provider });
|
||||||
|
|
||||||
const HANDLERS = {
|
const HANDLERS = {
|
||||||
[ACTIONS.SET_USER]: setUser,
|
[ACTIONS.SET_USER]: setUser,
|
||||||
[ACTIONS.SET_EDITING]: setEditing,
|
[ACTIONS.SET_EDITING]: setEditing,
|
||||||
|
@ -91,6 +94,8 @@ const HANDLERS = {
|
||||||
[ACTIONS.SHOW_RENDERER]: showRenderer,
|
[ACTIONS.SHOW_RENDERER]: showRenderer,
|
||||||
[ACTIONS.HIDE_RENDERER]: hideRenderer,
|
[ACTIONS.HIDE_RENDERER]: hideRenderer,
|
||||||
[ACTIONS.SET_RENDERER]: setRenderer,
|
[ACTIONS.SET_RENDERER]: setRenderer,
|
||||||
|
|
||||||
|
[ACTIONS.SET_PROVIDER]: setProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const INITIAL_STATE = {
|
export const INITIAL_STATE = {
|
||||||
|
@ -105,6 +110,7 @@ export const INITIAL_STATE = {
|
||||||
title: '',
|
title: '',
|
||||||
address: '',
|
address: '',
|
||||||
changed: false,
|
changed: false,
|
||||||
|
provider: DEFAULT_PROVIDER,
|
||||||
|
|
||||||
save_error: '',
|
save_error: '',
|
||||||
save_finished: false,
|
save_finished: false,
|
||||||
|
|
|
@ -27,6 +27,7 @@ import {
|
||||||
imageFetcher
|
imageFetcher
|
||||||
} from '$utils/renderer';
|
} from '$utils/renderer';
|
||||||
import { LOGOS } from '$constants/logos';
|
import { LOGOS } from '$constants/logos';
|
||||||
|
import { DEFAULT_PROVIDER } from '$constants/providers';
|
||||||
|
|
||||||
const getUser = state => (state.user.user);
|
const getUser = state => (state.user.user);
|
||||||
const getState = state => (state.user);
|
const getState = state => (state.user);
|
||||||
|
@ -46,11 +47,12 @@ function* generateGuestSaga() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function* startEmptyEditorSaga() {
|
function* startEmptyEditorSaga() {
|
||||||
const { id, random_url } = yield select(getUser);
|
const { id, random_url, provider = DEFAULT_PROVIDER } = yield select(getUser);
|
||||||
|
|
||||||
pushPath(`/${random_url}/edit`);
|
pushPath(`/${random_url}/edit`);
|
||||||
|
|
||||||
editor.owner = id;
|
editor.owner = id;
|
||||||
|
editor.setProvider(provider);
|
||||||
editor.startEditing();
|
editor.startEditing();
|
||||||
|
|
||||||
yield put(setChanged(false));
|
yield put(setChanged(false));
|
||||||
|
@ -78,7 +80,7 @@ function* stopEditingSaga() {
|
||||||
|
|
||||||
yield put(setChanged(false));
|
yield put(setChanged(false));
|
||||||
|
|
||||||
yield put(setEditing(editor.hasEmptyHistory())); // don't close editor if no previous map
|
yield put(setEditing(editor.hasEmptyHistory)); // don't close editor if no previous map
|
||||||
}
|
}
|
||||||
|
|
||||||
function* mapInitSaga() {
|
function* mapInitSaga() {
|
||||||
|
@ -193,9 +195,7 @@ function* clearSaga({ type }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function* sendSaveRequestSaga({ title, address, force }) {
|
function* sendSaveRequestSaga({ title, address, force }) {
|
||||||
if (editor.isEmpty()) {
|
if (editor.isEmpty) return yield put(setSaveError(TIPS.SAVE_EMPTY));
|
||||||
return yield put(setSaveError(TIPS.SAVE_EMPTY));
|
|
||||||
}
|
|
||||||
|
|
||||||
const { route, stickers } = editor.dumpData();
|
const { route, stickers } = editor.dumpData();
|
||||||
const { id, token } = yield select(getUser);
|
const { id, token } = yield select(getUser);
|
||||||
|
@ -239,6 +239,7 @@ function* getRenderData() {
|
||||||
|
|
||||||
const images = yield fetchImages(ctx, geometry);
|
const images = yield fetchImages(ctx, geometry);
|
||||||
yield composeImages({ geometry, images, ctx });
|
yield composeImages({ geometry, images, ctx });
|
||||||
|
|
||||||
yield composePoly({ points, ctx });
|
yield composePoly({ points, ctx });
|
||||||
|
|
||||||
return yield canvas.toDataURL('image/jpeg');
|
return yield canvas.toDataURL('image/jpeg');
|
||||||
|
@ -254,7 +255,6 @@ function* takeAShotSaga() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function* getCropData({
|
function* getCropData({
|
||||||
x, y, width, height
|
x, y, width, height
|
||||||
}) {
|
}) {
|
||||||
|
@ -285,6 +285,10 @@ function* cropAShotSaga(params) {
|
||||||
return yield put(hideRenderer());
|
return yield put(hideRenderer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setProviderSaga({ provider }) {
|
||||||
|
editor.setProvider(provider);
|
||||||
|
}
|
||||||
|
|
||||||
export function* userSaga() {
|
export function* userSaga() {
|
||||||
// ASYNCHRONOUS!!! :-)
|
// ASYNCHRONOUS!!! :-)
|
||||||
|
|
||||||
|
@ -311,4 +315,6 @@ export function* userSaga() {
|
||||||
yield takeLatest(ACTIONS.SET_SAVE_SUCCESS, setSaveSuccessSaga);
|
yield takeLatest(ACTIONS.SET_SAVE_SUCCESS, setSaveSuccessSaga);
|
||||||
yield takeLatest(ACTIONS.TAKE_A_SHOT, takeAShotSaga);
|
yield takeLatest(ACTIONS.TAKE_A_SHOT, takeAShotSaga);
|
||||||
yield takeLatest(ACTIONS.CROP_A_SHOT, cropAShotSaga);
|
yield takeLatest(ACTIONS.CROP_A_SHOT, cropAShotSaga);
|
||||||
|
|
||||||
|
yield takeEvery(ACTIONS.SET_PROVIDER, setProviderSaga);
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
&.single {
|
&.single {
|
||||||
border-radius: 3px;
|
border-radius: @panel_radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { editor } from '$modules/Editor';
|
import { editor } from '$modules/Editor';
|
||||||
import { COLORS, CONFIG } from '$config';
|
import { COLORS, CONFIG } from '$config';
|
||||||
import saveAs from 'file-saver';
|
import saveAs from 'file-saver';
|
||||||
|
import { DEFAULT_PROVIDER, PROVIDERS } from '$constants/providers';
|
||||||
|
|
||||||
const latLngToTile = latlng => {
|
const latLngToTile = latlng => {
|
||||||
const { map } = editor.map;
|
const { map } = editor.map;
|
||||||
|
@ -64,7 +65,14 @@ export const getPolyPlacement = () => (
|
||||||
: editor.poly.poly.getLatLngs().map((latlng) => ({ ...editor.map.map.latLngToContainerPoint(latlng) }))
|
: editor.poly.poly.getLatLngs().map((latlng) => ({ ...editor.map.map.latLngToContainerPoint(latlng) }))
|
||||||
);
|
);
|
||||||
|
|
||||||
const getImageSource = ({ x, y, zoom }) => (`http://b.basemaps.cartocdn.com/light_all/${zoom}/${x}/${y}.png`);
|
const replaceProviderUrl = (provider, { x, y, zoom }) => {
|
||||||
|
const { url, range } = (PROVIDERS[editor.provider] || PROVIDERS[DEFAULT_PROVIDER]);
|
||||||
|
const random = (range && range.length >= 2) ? Math.round((Math.random() * (range[1] - range[0])) + range[0]) : 1;
|
||||||
|
|
||||||
|
return url.replace('{x}', x).replace('{y}', y).replace('{z}', zoom).replace('{s}', random);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getImageSource = coords => replaceProviderUrl(editor.provider, coords);
|
||||||
|
|
||||||
export const imageFetcher = source => new Promise((resolve, reject) => {
|
export const imageFetcher = source => new Promise((resolve, reject) => {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
|
@ -108,6 +116,8 @@ export const composeImages = ({ images, geometry, ctx }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const composePoly = ({ points, ctx }) => {
|
export const composePoly = ({ points, ctx }) => {
|
||||||
|
if (editor.poly.isEmpty) return;
|
||||||
|
|
||||||
let minX = points[0].x;
|
let minX = points[0].x;
|
||||||
let maxX = points[0].x;
|
let maxX = points[0].x;
|
||||||
let minY = points[0].y;
|
let minY = points[0].y;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue