From f695e7586420364987aaae322cbb95ce0db15ab5 Mon Sep 17 00:00:00 2001 From: marc tobias Date: Fri, 19 Jun 2020 06:29:09 +0200 Subject: [PATCH] split configuration into hardcoded default and optional config.js --- .gitignore | 1 + dist/assets/js/nominatim-ui.js | 24 ++++++++++++++++++++++-- dist/config.example.js | 28 ++++++++++++++++++++++++++++ dist/config.js | 11 ----------- src/assets/js/base.js | 22 +++++++++++++++++++++- src/assets/js/searchpage.js | 2 +- src/config.example.js | 28 ++++++++++++++++++++++++++++ src/config.js | 11 ----------- 8 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 dist/config.example.js delete mode 100644 dist/config.js create mode 100644 src/config.example.js delete mode 100644 src/config.js diff --git a/.gitignore b/.gitignore index 9daa824..434259e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store +dist/config.js node_modules diff --git a/dist/assets/js/nominatim-ui.js b/dist/assets/js/nominatim-ui.js index ac6e97b..c597643 100644 --- a/dist/assets/js/nominatim-ui.js +++ b/dist/assets/js/nominatim-ui.js @@ -3,13 +3,33 @@ var map; var last_click_latlng; +// ********************************************************* +// DEFAULTS +// ********************************************************* + +var Nominatim_Config_Defaults = { + Nominatim_API_Endpoint: 'http://localhost/nominatim/', + Images_Base_Url: '/mapicons/', + Search_AreaPolygons: 1, + Reverse_Default_Search_Zoom: 18, + Map_Default_Lat: 20.0, + Map_Default_Lon: 0.0, + Map_Default_Zoom: 2, + Map_Tile_URL: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png', + Map_Tile_Attribution: 'OpenStreetMap contributors' +}; // ********************************************************* // HELPERS // ********************************************************* + function get_config_value(str, default_val) { - return (typeof Nominatim_Config[str] !== 'undefined' ? Nominatim_Config[str] : default_val); + var value = ((typeof Nominatim_Config !== 'undefined') + && (typeof Nominatim_Config[str] !== 'undefined')) + ? Nominatim_Config[str] + : Nominatim_Config_Defaults[str]; + return (typeof value !== 'undefined' ? value : default_val); } function parse_and_normalize_geojson_string(part) { @@ -642,7 +662,7 @@ jQuery(document).ready(function () { context = { sQuery: api_request_params.q, sViewBox: search_params.get('viewbox'), - env: Nominatim_Config + env: {} }; if (api_request_params.street || api_request_params.city || api_request_params.county diff --git a/dist/config.example.js b/dist/config.example.js new file mode 100644 index 0000000..bfddf7f --- /dev/null +++ b/dist/config.example.js @@ -0,0 +1,28 @@ +// The app loads an optional file config.js +// +// You can use this file as base for config.js (just copy or rename it), all +// keys are optional. + +var Nominatim_Config = []; + +// Where Nominatim API runs. Remember to add port if needed and trailing slash. +// Nominatim_Config['Nominatim_API_Endpoint'] = 'http://localhost/nominatim/'; +Nominatim_Config['Nominatim_API_Endpoint'] = 'https://nominatim.openstreetmap.org/'; + +// Nominatim_Config['Images_Base_Url'] = '/mapicons/'; + +// If the API should return polygons to be displayed on the map +// Nominatim_Config['Search_AreaPolygons'] = 1; +// Nominatim_Config['Reverse_Default_Search_Zoom'] = 18; + +// ---- MAP ---- +// For what {x}, {y} etc stand for see +// https://leafletjs.com/reference-1.6.0.html#tilelayer +// Nominatim_Config['Map_Tile_URL'] = 'https://{s}.tile.osm.org/{z}/{x}/{y}.png'; + +// Can be text or HTML. To hide set to '' +// Nominatim_Config['Map_Tile_Attribution'] = 'OpenStreetMap contributors'; + +// Nominatim_Config['Map_Default_Lat'] = 20.0; +// Nominatim_Config['Map_Default_Lon'] = 0.0; +// Nominatim_Config['Map_Default_Zoom'] = 2; diff --git a/dist/config.js b/dist/config.js deleted file mode 100644 index b0c17d0..0000000 --- a/dist/config.js +++ /dev/null @@ -1,11 +0,0 @@ -var Nominatim_Config = { - "Nominatim_API_Endpoint": 'http://localhost:8089/nominatim/', - "Images_Base_Url": '/mapicons/', - "Search_AreaPolygons": 1, - "Reverse_Default_Search_Zoom": 18, - "Map_Default_Lat": 20.0, - "Map_Default_Lon": 0.0, - "Map_Default_Zoom": 2, - "Map_Tile_URL": "https://{s}.tile.osm.org/{z}/{x}/{y}.png", - "Map_Tile_Attribution": "" -}; diff --git a/src/assets/js/base.js b/src/assets/js/base.js index 27f93af..c7ae6f9 100644 --- a/src/assets/js/base.js +++ b/src/assets/js/base.js @@ -3,13 +3,33 @@ var map; var last_click_latlng; +// ********************************************************* +// DEFAULTS +// ********************************************************* + +var Nominatim_Config_Defaults = { + Nominatim_API_Endpoint: 'http://localhost/nominatim/', + Images_Base_Url: '/mapicons/', + Search_AreaPolygons: 1, + Reverse_Default_Search_Zoom: 18, + Map_Default_Lat: 20.0, + Map_Default_Lon: 0.0, + Map_Default_Zoom: 2, + Map_Tile_URL: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png', + Map_Tile_Attribution: 'OpenStreetMap contributors' +}; // ********************************************************* // HELPERS // ********************************************************* + function get_config_value(str, default_val) { - return (typeof Nominatim_Config[str] !== 'undefined' ? Nominatim_Config[str] : default_val); + var value = ((typeof Nominatim_Config !== 'undefined') + && (typeof Nominatim_Config[str] !== 'undefined')) + ? Nominatim_Config[str] + : Nominatim_Config_Defaults[str]; + return (typeof value !== 'undefined' ? value : default_val); } function parse_and_normalize_geojson_string(part) { diff --git a/src/assets/js/searchpage.js b/src/assets/js/searchpage.js index 5a6c584..1061712 100755 --- a/src/assets/js/searchpage.js +++ b/src/assets/js/searchpage.js @@ -404,7 +404,7 @@ jQuery(document).ready(function () { context = { sQuery: api_request_params.q, sViewBox: search_params.get('viewbox'), - env: Nominatim_Config + env: {} }; if (api_request_params.street || api_request_params.city || api_request_params.county diff --git a/src/config.example.js b/src/config.example.js new file mode 100644 index 0000000..bfddf7f --- /dev/null +++ b/src/config.example.js @@ -0,0 +1,28 @@ +// The app loads an optional file config.js +// +// You can use this file as base for config.js (just copy or rename it), all +// keys are optional. + +var Nominatim_Config = []; + +// Where Nominatim API runs. Remember to add port if needed and trailing slash. +// Nominatim_Config['Nominatim_API_Endpoint'] = 'http://localhost/nominatim/'; +Nominatim_Config['Nominatim_API_Endpoint'] = 'https://nominatim.openstreetmap.org/'; + +// Nominatim_Config['Images_Base_Url'] = '/mapicons/'; + +// If the API should return polygons to be displayed on the map +// Nominatim_Config['Search_AreaPolygons'] = 1; +// Nominatim_Config['Reverse_Default_Search_Zoom'] = 18; + +// ---- MAP ---- +// For what {x}, {y} etc stand for see +// https://leafletjs.com/reference-1.6.0.html#tilelayer +// Nominatim_Config['Map_Tile_URL'] = 'https://{s}.tile.osm.org/{z}/{x}/{y}.png'; + +// Can be text or HTML. To hide set to '' +// Nominatim_Config['Map_Tile_Attribution'] = 'OpenStreetMap contributors'; + +// Nominatim_Config['Map_Default_Lat'] = 20.0; +// Nominatim_Config['Map_Default_Lon'] = 0.0; +// Nominatim_Config['Map_Default_Zoom'] = 2; diff --git a/src/config.js b/src/config.js deleted file mode 100644 index b0c17d0..0000000 --- a/src/config.js +++ /dev/null @@ -1,11 +0,0 @@ -var Nominatim_Config = { - "Nominatim_API_Endpoint": 'http://localhost:8089/nominatim/', - "Images_Base_Url": '/mapicons/', - "Search_AreaPolygons": 1, - "Reverse_Default_Search_Zoom": 18, - "Map_Default_Lat": 20.0, - "Map_Default_Lon": 0.0, - "Map_Default_Zoom": 2, - "Map_Tile_URL": "https://{s}.tile.osm.org/{z}/{x}/{y}.png", - "Map_Tile_Attribution": "" -}; -- 2.39.5