]> git.openstreetmap.org Git - nominatim-ui.git/commitdiff
split configuration into hardcoded default and optional config.js
authormarc tobias <mtmail@gmx.net>
Fri, 19 Jun 2020 04:29:09 +0000 (06:29 +0200)
committermarc tobias <mtmail@gmx.net>
Fri, 19 Jun 2020 04:29:09 +0000 (06:29 +0200)
.gitignore
dist/assets/js/nominatim-ui.js
dist/config.example.js [new file with mode: 0644]
dist/config.js [deleted file]
src/assets/js/base.js
src/assets/js/searchpage.js
src/config.example.js [new file with mode: 0644]
src/config.js [deleted file]

index 9daa8247da451dcfc3b04d199e1cd71b8fffe3c6..434259e837d6ec824a5e709ffb22784a9dae3c65 100644 (file)
@@ -1,2 +1,3 @@
 .DS_Store
+dist/config.js
 node_modules
index ac6e97b18979df8ad9df6a19aeb27a4a8a157b06..c597643fc804858acb26475c08b8af8040b41791 100644 (file)
@@ -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: '<a href="https://osm.org/copyright">OpenStreetMap contributors</a>'
+};
 
 // *********************************************************
 // 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 (file)
index 0000000..bfddf7f
--- /dev/null
@@ -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'] = '<a href="https://osm.org/copyright">OpenStreetMap contributors</a>';
+
+// 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 (file)
index b0c17d0..0000000
+++ /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": ""
-};
index 27f93af7c0c6851073cc8fa4162118ae28645bb0..c7ae6f922772a36237b00c53066405b539cee635 100644 (file)
@@ -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: '<a href="https://osm.org/copyright">OpenStreetMap contributors</a>'
+};
 
 // *********************************************************
 // 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) {
index 5a6c584811e00fd752c57ad504eb07f224329bbb..1061712a6cf0afe8ca9f82f34905cf6cd4d31cb3 100755 (executable)
@@ -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 (file)
index 0000000..bfddf7f
--- /dev/null
@@ -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'] = '<a href="https://osm.org/copyright">OpenStreetMap contributors</a>';
+
+// 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 (file)
index b0c17d0..0000000
+++ /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": ""
-};