From 5908309b51c401a6048805c3a68c108a3eb21b1a Mon Sep 17 00:00:00 2001 From: captainpovey Date: Fri, 22 Jun 2018 19:38:45 +0100 Subject: [PATCH] Option to change stroke settings in config.php --- config.default.php | 5 +++++ helpers/config.php | 9 ++++++++- index.php | 5 ++++- js/api_gmaps.js | 6 +++--- js/api_openlayers.js | 2 +- js/api_openlayers3.js | 4 ++-- js/main.js | 7 ++++++- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/config.default.php b/config.default.php index 9a276ab..085d8b7 100755 --- a/config.default.php +++ b/config.default.php @@ -91,4 +91,9 @@ $lang = "en"; $units = "metric"; //$units = "imperial"; +// These need to be copied to config.php +$strokeWeight = 2; +$strokeColor = '#FF0000'; +$strokeOpacity = 1.0; + ?> diff --git a/helpers/config.php b/helpers/config.php index 6e26c74..8df02bc 100644 --- a/helpers/config.php +++ b/helpers/config.php @@ -79,6 +79,10 @@ // units static $units = "metric"; + static $strokeWeight = 2; + static $strokeColor = '#ff0000'; + static $strokeOpacity = 1; + private static $fileLoaded = false; private static $initialized = false; @@ -123,6 +127,9 @@ if (isset($interval)) { self::$interval = (int) $interval; } if (isset($lang)) { self::$lang = $lang; } if (isset($units)) { self::$units = $units; } + if (isset($strokeWeight)) { self::$strokeWeight = $strokeWeight; } + if (isset($strokeColor)) { self::$strokeColor = $strokeColor; } + if (isset($strokeOpacity)) { self::$strokeOpacity = $strokeOpacity; } if (!self::$require_authentication) { // tracks must be public if we don't require authentication @@ -177,4 +184,4 @@ } } -?> \ No newline at end of file +?> diff --git a/index.php b/index.php index a863b41..23f630f 100755 --- a/index.php +++ b/index.php @@ -80,6 +80,9 @@ var admin = isAdmin()) ?>; var auth = 'isAuthenticated()) ? $auth->user->login : "null" ?>'; var pass_regex = ; + var strokeWeight = ; + var strokeColor = ''; + var strokeOpacity = ; isAdmin()): ?> @@ -218,4 +221,4 @@ - \ No newline at end of file + diff --git a/js/api_gmaps.js b/js/api_gmaps.js index c2f504b..a546617 100755 --- a/js/api_gmaps.js +++ b/js/api_gmaps.js @@ -30,9 +30,9 @@ function init() { if (gm_error) { return gm_authFailure(); } google.maps.visualRefresh = true; polyOptions = { - strokeColor: '#FF0000', - strokeOpacity: 1.0, - strokeWeight: 2 + strokeColor: strokeColor, + strokeOpacity: strokeOpacity, + strokeWeight: strokeWeight } mapOptions = { center: new google.maps.LatLng(init_latitude, init_longitude), diff --git a/js/api_openlayers.js b/js/api_openlayers.js index b1c8bcd..bb64c59 100755 --- a/js/api_openlayers.js +++ b/js/api_openlayers.js @@ -95,7 +95,7 @@ function displayTrack(xml, update) { points.push(point); } var lineString = new OpenLayers.Geometry.LineString(points); - var lineStyle = { strokeColor: '#FF0000', strokeOpacity: 1, strokeWidth: 2 }; + var lineStyle = { strokeColor: strokeColor, strokeOpacity: strokeOpacity, strokeWidth: strokeWeight }; var lineFeature = new OpenLayers.Feature.Vector(lineString, null, lineStyle); layerTrack.addFeatures([lineFeature]); map.addLayer(layerTrack); diff --git a/js/api_openlayers3.js b/js/api_openlayers3.js index a51dac8..a03029c 100755 --- a/js/api_openlayers3.js +++ b/js/api_openlayers3.js @@ -73,8 +73,8 @@ function init() { // init layers var lineStyle = new ol.style.Style({ stroke: new ol.style.Stroke({ - color: 'rgba(255, 0, 0, 0.5)', - width: 2 + color: hexToRGBA(strokeColor, strokeOpacity), + width: strokeWeight }) }); layerTrack = new ol.layer.Vector({ diff --git a/js/main.js b/js/main.js index e51c027..b24773b 100755 --- a/js/main.js +++ b/js/main.js @@ -641,8 +641,13 @@ function htmlEncode(s) { .replace(/>/g, '>'); } +// Convert hex string and opacity to an rgba string +function hexToRGBA(hex, opacity) { + return 'rgba(' + (hex = hex.replace('#', '')).match(new RegExp('(.{' + hex.length/3 + '})', 'g')).map(function(l) { return parseInt(hex.length%2 ? l+l : l, 16) }).concat(opacity||1).join(',') + ')'; +} + if (!String.prototype.trim) { String.prototype.trim = function () { return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }; -} \ No newline at end of file +}