From 2dbf091c950606c6f7f852fa2b7a9a71b6496433 Mon Sep 17 00:00:00 2001 From: tsmgeek Date: Thu, 17 Aug 2017 22:56:51 +0100 Subject: optimise ifthenelse & foreach loops --- web/app/view/map/BaseMap.js | 225 +++++++++++++++++++++++--------------------- 1 file changed, 117 insertions(+), 108 deletions(-) (limited to 'web/app/view/map/BaseMap.js') diff --git a/web/app/view/map/BaseMap.js b/web/app/view/map/BaseMap.js index c4297f68..c1873161 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: [ - '© OpenStreetMap ' + - 'contributors, © CARTO' + 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: [ + '© OpenStreetMap ' + + 'contributors, © CARTO' + ] + }) + ] + }) + }); + 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: '© Baidu' + }) ] - }), - attributions: [ - new ol.Attribution({ - html: '© Baidu' - }) - ] - }) - }); - } 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: '© Yandex' - }) - ] - }) - }); - } 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: '© Yandex' - }) - ] - }) - }); - } 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: '© Yandex' + }) + ] + }) + }); + 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: '© Yandex' + }) + ] + }) + }); + break; + default: + layer = new ol.layer.Tile({ + source: new ol.source.OSM({}) + }); } lat = Traccar.app.getPreference('latitude', Traccar.Style.mapDefaultLat); -- cgit v1.2.3 From 7e2fb28b558f404442bec67a7551e75fc90ff100 Mon Sep 17 00:00:00 2001 From: tsmgeek Date: Tue, 22 Aug 2017 00:26:01 +0100 Subject: Fix typos --- web/app/AttributeFormatter.js | 40 +--------------------------------------- web/app/GeofenceConverter.js | 5 ----- web/app/view/map/BaseMap.js | 40 +++------------------------------------- 3 files changed, 4 insertions(+), 81 deletions(-) (limited to 'web/app/view/map/BaseMap.js') diff --git a/web/app/AttributeFormatter.js b/web/app/AttributeFormatter.js index 7ccf84b4..957992da 100644 --- a/web/app/AttributeFormatter.js +++ b/web/app/AttributeFormatter.js @@ -188,7 +188,6 @@ Ext.define('Traccar.AttributeFormatter', { getAttributeFormatter: function (key) { var dataType = Ext.getStore('PositionAttributes').getAttributeDataType(key); -<<<<<<< HEAD switch (dataType) { case 'distance': @@ -209,36 +208,13 @@ Ext.define('Traccar.AttributeFormatter', { return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterPerHourAbbreviation); default: return this.defaultFormatter; -======= - if (!dataType) { - return this.defaultFormatter; - } else if (dataType === 'distance') { - return this.distanceFormatter; - } else if (dataType === 'speed') { - return this.speedFormatter; - } else if (dataType === 'driverUniqueId') { - return this.driverUniqueIdFormatter; - } else if (dataType === 'voltage') { - return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedVoltAbbreviation); - } else if (dataType === 'percentage') { - return this.numberFormatterFactory(Traccar.Style.numberPrecision, '%'); - } else if (dataType === 'temperature') { - return this.numberFormatterFactory(Traccar.Style.numberPrecision, '°C'); - } else if (dataType === 'volume') { - return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterAbbreviation); - } else if (dataType === 'consumption') { - return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterPerHourAbbreviation); - } else { - return this.defaultFormatter; ->>>>>>> e0bb9b92d07176677b3043530660af3bc30774d7 } }, getAttributeConverter: function (key) { var dataType = Ext.getStore('PositionAttributes').getAttributeDataType(key); -<<<<<<< HEAD - switch (dataType){ + switch (dataType) { case 'distance': return this.distanceConverter; case 'speed': @@ -247,20 +223,6 @@ Ext.define('Traccar.AttributeFormatter', { return function (value) { return value; }; -======= - if (!dataType) { - return function (value) { - return value; - }; - } else if (dataType === 'distance') { - return this.distanceConverter; - } else if (dataType === 'speed') { - return this.speedConverter; - } else { - return function (value) { - return value; - }; ->>>>>>> e0bb9b92d07176677b3043530660af3bc30774d7 } } }); diff --git a/web/app/GeofenceConverter.js b/web/app/GeofenceConverter.js index d3d562e7..4891e7b1 100644 --- a/web/app/GeofenceConverter.js +++ b/web/app/GeofenceConverter.js @@ -19,13 +19,8 @@ Ext.define('Traccar.GeofenceConverter', { singleton: true, wktToGeometry: function (mapView, wkt) { -<<<<<<< HEAD - var geometry, projection, resolutionAtEquator, pointResolution, resolutionFactor, points = [], center, radius, - content, i, lat, lon, coordinates; -======= var geometry, projection, resolutionAtEquator, pointResolution, resolutionFactor, points = [], center, radius, content, i, lat, lon, coordinates; ->>>>>>> e0bb9b92d07176677b3043530660af3bc30774d7 if (wkt.lastIndexOf('POLYGON', 0) === 0) { content = wkt.match(/\([^()]+\)/); if (content !== null) { diff --git a/web/app/view/map/BaseMap.js b/web/app/view/map/BaseMap.js index cac5a596..c6eb5b48 100644 --- a/web/app/view/map/BaseMap.js +++ b/web/app/view/map/BaseMap.js @@ -101,13 +101,13 @@ Ext.define('Traccar.view.map.BaseMap', { index = index < 0 ? index + urlsLength : index; if (x < 0) { - x = 'M' + (-x); + x = 'M' + -x; } if (y < 0) { - y = 'M' + (-y); + 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); + .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'), @@ -117,45 +117,11 @@ Ext.define('Traccar.view.map.BaseMap', { 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0.5 ] -<<<<<<< HEAD }), attributions: [ new ol.Attribution({ html: '© Baidu' }) -======= - }) - ] - }) - }); - } 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 ->>>>>>> e0bb9b92d07176677b3043530660af3bc30774d7 ] }) }); -- cgit v1.2.3