diff options
author | Anton Tananaev <anton@traccar.org> | 2022-07-31 17:46:09 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-07-31 17:46:09 -0700 |
commit | 893eb356b6c7c2c435be8b75a312d8e488913dd4 (patch) | |
tree | 3c2f4496c917841acdec8943c9f853924b410097 /modern/src/map/core/useMapStyles.js | |
parent | 194d0502b0c042c0f640cd8ab55da5efb86d14c9 (diff) | |
download | trackermap-web-893eb356b6c7c2c435be8b75a312d8e488913dd4.tar.gz trackermap-web-893eb356b6c7c2c435be8b75a312d8e488913dd4.tar.bz2 trackermap-web-893eb356b6c7c2c435be8b75a312d8e488913dd4.zip |
Configure map zoom limits
Diffstat (limited to 'modern/src/map/core/useMapStyles.js')
-rw-r--r-- | modern/src/map/core/useMapStyles.js | 99 |
1 files changed, 58 insertions, 41 deletions
diff --git a/modern/src/map/core/useMapStyles.js b/modern/src/map/core/useMapStyles.js index 5e32c44d..7ab77ae2 100644 --- a/modern/src/map/core/useMapStyles.js +++ b/modern/src/map/core/useMapStyles.js @@ -2,14 +2,16 @@ import { useSelector } from 'react-redux'; import { useTranslation } from '../../common/components/LocalizationProvider'; import { useAttributePreference } from '../../common/util/preferences'; -const styleCustom = (urls, attribution) => ({ +const styleCustom = ({ tiles, minZoom, maxZoom, attribution }) => ({ version: 8, sources: { custom: { type: 'raster', - tiles: urls, + tiles, attribution, tileSize: 256, + minzoom: minZoom, + maxzoom: maxZoom, }, }, glyphs: 'https://cdn.traccar.com/map/fonts/{fontstack}/{range}.pbf', @@ -41,27 +43,30 @@ export default () => { { id: 'osm', title: t('mapOsm'), - style: styleCustom( - ['https://tile.openstreetmap.org/{z}/{x}/{y}.png'], - '© <a target="_top" rel="noopener" href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', - ), + style: styleCustom({ + tiles: ['https://tile.openstreetmap.org/{z}/{x}/{y}.png'], + maxZoom: 19, + attribution: '© <a target="_top" rel="noopener" href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', + }), available: true, }, { id: 'openTopoMap', title: t('mapOpenTopoMap'), - style: styleCustom( - ['a', 'b', 'c'].map((i) => `https://${i}.tile.opentopomap.org/{z}/{x}/{y}.png`), - ), + style: styleCustom({ + tiles: ['a', 'b', 'c'].map((i) => `https://${i}.tile.opentopomap.org/{z}/{x}/{y}.png`), + maxZoom: 17, + }), available: true, }, { id: 'carto', title: t('mapCarto'), - style: styleCustom( - ['a', 'b', 'c', 'd'].map((i) => `https://${i}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}@2x.png`), - '© <a target="_top" rel="noopener" href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a target="_top" rel="noopener" href="https://carto.com/attribution">CARTO</a>', - ), + style: styleCustom({ + tiles: ['a', 'b', 'c', 'd'].map((i) => `https://${i}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}@2x.png`), + maxZoom: 22, + attribution: '© <a target="_top" rel="noopener" href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a target="_top" rel="noopener" href="https://carto.com/attribution">CARTO</a>', + }), available: true, }, { @@ -81,27 +86,30 @@ export default () => { { id: 'bingRoad', title: t('mapBingRoad'), - style: styleCustom( - [0, 1, 2, 3].map((i) => `https://t${i}.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/{quadkey}?mkt=en-US&it=G,L&shading=hill&og=1885&n=z`), - ), + style: styleCustom({ + tiles: [0, 1, 2, 3].map((i) => `https://t${i}.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/{quadkey}?mkt=en-US&it=G,L&shading=hill&og=1885&n=z`), + maxZoom: 21, + }), available: !!bingMapsKey, attribute: 'bingMapsKey', }, { id: 'bingAerial', title: t('mapBingAerial'), - style: styleCustom( - [0, 1, 2, 3].map((i) => `https://ecn.t${i}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=12327`), - ), + style: styleCustom({ + tiles: [0, 1, 2, 3].map((i) => `https://ecn.t${i}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=12327`), + maxZoom: 19, + }), available: !!bingMapsKey, attribute: 'bingMapsKey', }, { id: 'bingHybrid', title: t('mapBingHybrid'), - style: styleCustom( - [0, 1, 2, 3].map((i) => `https://t${i}.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/{quadkey}?mkt=en-US&it=A,G,L&og=1885&n=z`), - ), + style: styleCustom({ + tiles: [0, 1, 2, 3].map((i) => `https://t${i}.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/{quadkey}?mkt=en-US&it=A,G,L&og=1885&n=z`), + maxZoom: 19, + }), available: !!bingMapsKey, attribute: 'bingMapsKey', }, @@ -122,27 +130,31 @@ export default () => { { id: 'hereHybrid', title: t('mapHereHybrid'), - style: styleCustom( - [1, 2, 3, 4].map((i) => `https://${i}.aerial.maps.ls.hereapi.com/maptile/2.1/maptile/newest/hybrid.day/{z}/{x}/{y}/256/png8?apiKey=${hereKey}`), - ), + style: styleCustom({ + tiles: [1, 2, 3, 4].map((i) => `https://${i}.aerial.maps.ls.hereapi.com/maptile/2.1/maptile/newest/hybrid.day/{z}/{x}/{y}/256/png8?apiKey=${hereKey}`), + maxZoom: 20, + }), available: !!hereKey, attribute: 'hereKey', }, { id: 'hereSatellite', title: t('mapHereSatellite'), - style: styleCustom( - [1, 2, 3, 4].map((i) => `https://${i}.aerial.maps.ls.hereapi.com/maptile/2.1/maptile/newest/satellite.day/{z}/{x}/{y}/256/png8?apiKey=${hereKey}`), - ), + style: styleCustom({ + tiles: [1, 2, 3, 4].map((i) => `https://${i}.aerial.maps.ls.hereapi.com/maptile/2.1/maptile/newest/satellite.day/{z}/{x}/{y}/256/png8?apiKey=${hereKey}`), + maxZoom: 19, + }), available: !!hereKey, attribute: 'hereKey', }, { id: 'autoNavi', title: t('mapAutoNavi'), - style: styleCustom( - [1, 2, 3, 4].map((i) => `https://webrd0${i}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}`), - ), + style: styleCustom({ + tiles: [1, 2, 3, 4].map((i) => `https://webrd0${i}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}`), + minZoom: 3, + maxZoom: 18, + }), available: true, }, { @@ -154,34 +166,39 @@ export default () => { { id: 'mapboxStreets', title: t('mapMapboxStreets'), - style: styleCustom( - [`https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=${mapboxAccessToken}`], - ), + style: styleCustom({ + tiles: [`https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=${mapboxAccessToken}`], + maxZoom: 22, + }), available: !!mapboxAccessToken, attribute: 'mapboxAccessToken', }, { id: 'mapboxOutdoors', title: t('mapMapboxOutdoors'), - style: styleCustom( - [`https://api.mapbox.com/styles/v1/mapbox/outdoors-v11/tiles/{z}/{x}/{y}?access_token=${mapboxAccessToken}`], - ), + style: styleCustom({ + tiles: [`https://api.mapbox.com/styles/v1/mapbox/outdoors-v11/tiles/{z}/{x}/{y}?access_token=${mapboxAccessToken}`], + maxZoom: 22, + }), available: !!mapboxAccessToken, attribute: 'mapboxAccessToken', }, { id: 'mapboxSatelliteStreet', title: t('mapMapboxSatellite'), - style: styleCustom( - [`https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=${mapboxAccessToken}`], - ), + style: styleCustom({ + tiles: [`https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=${mapboxAccessToken}`], + maxZoom: 22, + }), available: !!mapboxAccessToken, attribute: 'mapboxAccessToken', }, { id: 'custom', title: t('mapCustom'), - style: styleCustom([customMapUrl]), + style: styleCustom({ + tiles: [customMapUrl], + }), available: !!customMapUrl, }, ]; |