diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-08-22 14:11:55 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-22 14:11:55 +1200 |
commit | 0401e755936df29af9eeb129f8cc99e3b151f05c (patch) | |
tree | 1fa898c25d4fb3695c34f1e96507e61b6d3da7b8 /web/app/view/map/BaseMap.js | |
parent | e0bb9b92d07176677b3043530660af3bc30774d7 (diff) | |
parent | 7e2fb28b558f404442bec67a7551e75fc90ff100 (diff) | |
download | trackermap-web-0401e755936df29af9eeb129f8cc99e3b151f05c.tar.gz trackermap-web-0401e755936df29af9eeb129f8cc99e3b151f05c.tar.bz2 trackermap-web-0401e755936df29af9eeb129f8cc99e3b151f05c.zip |
Merge pull request #553 from tsmgeek/optimise-ifs
Optimise ifs and loops
Diffstat (limited to 'web/app/view/map/BaseMap.js')
-rw-r--r-- | web/app/view/map/BaseMap.js | 225 |
1 files changed, 117 insertions, 108 deletions
diff --git a/web/app/view/map/BaseMap.js b/web/app/view/map/BaseMap.js index 91f37841..c6eb5b48 100644 --- a/web/app/view/map/BaseMap.js +++ b/web/app/view/map/BaseMap.js @@ -37,116 +37,125 @@ Ext.define('Traccar.view.map.BaseMap', { type = Traccar.app.getPreference('map', null); bingKey = server.get('bingKey'); - if (type === 'custom') { - layer = new ol.layer.Tile({ - source: new ol.source.XYZ({ - url: server.get('mapUrl'), - attributions: [ - new ol.Attribution({ - html: '' - }) - ] - }) - }); - } else if (type === 'bingRoad') { - layer = new ol.layer.Tile({ - source: new ol.source.BingMaps({ - key: bingKey, - imagerySet: 'Road' - }) - }); - } else if (type === 'bingAerial') { - layer = new ol.layer.Tile({ - source: new ol.source.BingMaps({ - key: bingKey, - imagerySet: 'Aerial' - }) - }); - } else if (type === 'bingHybrid') { - layer = new ol.layer.Tile({ - source: new ol.source.BingMaps({ - key: bingKey, - imagerySet: 'AerialWithLabels' - }) - }); - } else if (type === 'carto') { - layer = new ol.layer.Tile({ - source: new ol.source.XYZ({ - url: 'https://cartodb-basemaps-{a-d}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', - attributions: [ - new ol.Attribution({ - html: [ - '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> ' + - 'contributors, © <a href="https://carto.com/attributions">CARTO</a>' + switch (type) { + case 'custom': + layer = new ol.layer.Tile({ + source: new ol.source.XYZ({ + url: server.get('mapUrl'), + attributions: [ + new ol.Attribution({ + html: '' + }) + ] + }) + }); + break; + case 'bingRoad': + layer = new ol.layer.Tile({ + source: new ol.source.BingMaps({ + key: bingKey, + imagerySet: 'Road' + }) + }); + break; + case 'bingAerial': + layer = new ol.layer.Tile({ + source: new ol.source.BingMaps({ + key: bingKey, + imagerySet: 'Aerial' + }) + }); + break; + case 'bingHybrid': + layer = new ol.layer.Tile({ + source: new ol.source.BingMaps({ + key: bingKey, + imagerySet: 'AerialWithLabels' + }) + }); + break; + case 'carto': + layer = new ol.layer.Tile({ + source: new ol.source.XYZ({ + url: 'https://cartodb-basemaps-{a-d}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', + attributions: [ + new ol.Attribution({ + html: [ + '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> ' + + 'contributors, © <a href="https://carto.com/attributions">CARTO</a>' + ] + }) + ] + }) + }); + break; + case 'baidu': + layer = new ol.layer.Tile({ + source: new ol.source.XYZ({ + projection: 'BD-MC', + tileUrlFunction: function (tileCoord) { + var urlsLength = 5, z = tileCoord[0], x = tileCoord[1], y = tileCoord[2], hash, index; + + hash = (x << z) + y; + index = hash % urlsLength; + index = index < 0 ? index + urlsLength : index; + + if (x < 0) { + x = 'M' + -x; + } + if (y < 0) { + y = 'M' + -y; + } + return 'http://online{}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl' + .replace('{}', index).replace('{x}', x).replace('{y}', y).replace('{z}', z); + }, + tileGrid: new ol.tilegrid.TileGrid({ + extent: ol.proj.transformExtent([-180, -74, 180, 74], 'EPSG:4326', 'BD-MC'), + origin: [0, 0], + minZoom: 3, + resolutions: [ + 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, + 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0.5 ] - }) - ] - }) - }); - } else if (type === 'baidu') { - layer = new ol.layer.Tile({ - source: new ol.source.XYZ({ - projection: 'BD-MC', - tileUrlFunction: function (tileCoord) { - var urlsLength = 5, z = tileCoord[0], x = tileCoord[1], y = tileCoord[2], hash, index; - - hash = (x << z) + y; - index = hash % urlsLength; - index = index < 0 ? index + urlsLength : index; - - if (x < 0) { - x = 'M' + -x; - } - if (y < 0) { - y = 'M' + -y; - } - return 'http://online{}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl' - .replace('{}', index).replace('{x}', x).replace('{y}', y).replace('{z}', z); - }, - tileGrid: new ol.tilegrid.TileGrid({ - extent: ol.proj.transformExtent([-180, -74, 180, 74], 'EPSG:4326', 'BD-MC'), - origin: [0, 0], - minZoom: 3, - resolutions: [ - 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, - 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0.5 + }), + attributions: [ + new ol.Attribution({ + html: '© <a href="http://map.baidu.com/">Baidu</a>' + }) ] - }), - attributions: [ - new ol.Attribution({ - html: '© <a href="http://map.baidu.com/">Baidu</a>' - }) - ] - }) - }); - } else if (type === 'yandexMap') { - layer = new ol.layer.Tile({ - source: new ol.source.XYZ({ - url: 'https://vec0{1-4}.maps.yandex.net/tiles?l=map&x={x}&y={y}&z={z}', - projection: 'EPSG:3395', - attributions: [ - new ol.Attribution({ - html: '© <a href="https://yandex.com/maps/">Yandex</a>' - }) - ] - }) - }); - } else if (type === 'yandexSat') { - layer = new ol.layer.Tile({ - source: new ol.source.XYZ({ - url: 'https://sat0{1-4}.maps.yandex.net/tiles?l=sat&x={x}&y={y}&z={z}', - projection: 'EPSG:3395', - attributions: [ - new ol.Attribution({ - html: '© <a href="https://yandex.com/maps/">Yandex</a>' - }) - ] - }) - }); - } else { - layer = new ol.layer.Tile({ - source: new ol.source.OSM({}) - }); + }) + }); + break; + case 'yandexMap': + layer = new ol.layer.Tile({ + source: new ol.source.XYZ({ + url: 'https://vec0{1-4}.maps.yandex.net/tiles?l=map&x={x}&y={y}&z={z}', + projection: 'EPSG:3395', + attributions: [ + new ol.Attribution({ + html: '© <a href="https://yandex.com/maps/">Yandex</a>' + }) + ] + }) + }); + break; + case 'yandexSat': + layer = new ol.layer.Tile({ + source: new ol.source.XYZ({ + url: 'https://sat0{1-4}.maps.yandex.net/tiles?l=sat&x={x}&y={y}&z={z}', + projection: 'EPSG:3395', + attributions: [ + new ol.Attribution({ + html: '© <a href="https://yandex.com/maps/">Yandex</a>' + }) + ] + }) + }); + break; + default: + layer = new ol.layer.Tile({ + source: new ol.source.OSM({}) + }); } lat = Traccar.app.getPreference('latitude', Traccar.Style.mapDefaultLat); |