From: mtmail Date: Fri, 19 Jun 2020 05:32:26 +0000 (+0200) Subject: Merge pull request #15 from mtmail/master X-Git-Url: https://git.openstreetmap.org/nominatim-ui.git/commitdiff_plain/6beafb16431a1cf87ad160ab50b07db31971d873?hp=19f626c2a6f4bb6b1b86c640b49a37c6faa1eb3e Merge pull request #15 from mtmail/master version 1.1 --- 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/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..11154aa --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,8 @@ +# CHANGES + +* version 1.1 - 2020-06-19 + + * Configuration now optional with example file. + * New CONTRIBUTE.md documentation. + +* version 1.0 - November 2019 during a hackweekend at Linuxhotel diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md new file mode 100644 index 0000000..de818e8 --- /dev/null +++ b/CONTRIBUTE.md @@ -0,0 +1,53 @@ +# Developing Nominatim-UI + +## Background + +The user interface used to be included in the geocoder. Thus the +first version avoid being a redesign and still uses some of the +same configuration values. For simplicity it's not a single +page application (SPA) written in a framework though it could +be in the future if complexity grows. + +Uses [jQuery](https://jquery.com/) for browser DOM interaction, +[handlebar](http://handlebarsjs.com/) templates to build pages, +[leaflet](https://leafletjs.com/) for map interaction, +[bootstrap](https://getbootstrap.com/) for layout styling. + + +## Building the frontend + +* Install dependencies + + ``` + yarn install + ``` + +* After you change files in `src` directory run + + ``` + yarn build + ``` + +* Start a webserver on port 8000 to preview changes + + ``` + yarn start + ``` + +* Run code style check + + ``` + yarn lint + ``` + +## Prepare a release + +1. Update version number in `package.json` file + +2. Update `CHANGES.md` file + +3. Commit your changes: `git add... `, `git commit ...`, `git push ...` etc + +4. Tag release: `git tag THE_VERSION_NUMBER`, `git push --tags` + +5. Upload release \ No newline at end of file diff --git a/README.md b/README.md index 2acb5ba..bd1748b 100644 --- a/README.md +++ b/README.md @@ -1,56 +1,45 @@ # Nominatim-UI Debugging user interface for [Nominatim](https://nominatim.org/) -([source](https://github.com/openstreetmap/Nominatim/)) geocoder. +([source](https://github.com/osm-search/Nominatim/)) geocoder. The frontend runs standalone as website and will requests data from a separate Nominatim API (either on the same server or remote). -Uses [jQuery](https://jquery.com/) for browser DOM interaction, -[handlebar](http://handlebarsjs.com/) templates to build pages, -[leaflet](https://leafletjs.com/) for map interaction, -[bootstrap](https://getbootstrap.com/) for layout styling. - - -## Background - -The user interface used to be included in the geocoder. Thus the -first version avoid being a redesign and still uses some of the -same configuration values. For simplicity it's not a single -page application (SPA) written in a framework though it could -be if complexity grows. +For technical details see [CONTRIBUTING.md]() file. +![Screenshot](screenshot.png) ## Starting the frontend -You can open the `dist` directory in your browser. +* You can open the `dist` directory in your browser. -You can run `yarn start` to start a simple HTTP webserver and open -[http://localhost:8000/]() in your browser. +* If you have python installed (part of the Nominatim server installation): -Or start another webserver ([Big list of http static server one-liners](https://gist.github.com/willurd/5720255)). + 1. `cd dist` + 2. start webserver `python3 -m http.server 8765` + 3. open [http://localhost:8765/]() in your browser +* Start a webserver using ([Big list of http static server one-liners](https://gist.github.com/willurd/5720255)) or configure Apache, nginx or other webservers to serve the `dist` directory. -## Configuration -In `dist/config.js` you will find configuration options. The first -you want to doublecheck is the `Nominatim_API_Endpoint` URL. - - -## Building the frontend +## Configuration -* Install dependencies +Create a `dist/config.js` file, you can use `dist/config.example.js` as basis (just copy it). All settings are optional. Usually you want to set the `Nominatim_API_Endpoint` value at least. - ``` - yarn install - ``` +Defaults: -* After you change files in `src` directory +| setting | default | +|---|---| +| `Nominatim_API_Endpoint` | http://localhost/nominatim/ (port 80) | +| `Images_Base_Url` | images in [mapicons]() | +| `Search_AreaPolygons` | yes, print boundaries of search results on map | +| `Reverse_Default_Search_Zoom` | 18 (house-number level) | +| `Map_Default_Lat`, `Map_Default_Lon`, `Map_Default_Zoom` | display whole world | +| `Map_Tile_URL` | load from openstreetmap.org | +| `Map_Tile_Attribution` | [OpenStreetMap](https://openstreetmap.org/copyright) obviously | - ``` - yarn build - ``` ## License -The source code is available under a GPLv2 license. +The source code is available under a [GPLv2 license](LICENSE). diff --git a/dist/assets/js/nominatim-ui.js b/dist/assets/js/nominatim-ui.js index ac6e97b..05019aa 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) { @@ -633,7 +653,7 @@ jQuery(document).ready(function () { state: search_params.get('state'), country: search_params.get('country'), postalcode: search_params.get('postalcode'), - polygon_geojson: search_params.get('polygon_geojson') ? 1 : 0, + polygon_geojson: get_config_value('Search_AreaPolygons', false) ? 1 : 0, viewbox: search_params.get('viewbox'), exclude_place_ids: search_params.get('exclude_place_ids'), format: 'jsonv2' @@ -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..cf4df52 --- /dev/null +++ b/dist/config.example.js @@ -0,0 +1,27 @@ +// 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['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/dist/search.html b/dist/search.html index b3e2b03..afb6c33 100644 --- a/dist/search.html +++ b/dist/search.html @@ -178,9 +178,6 @@
- {{#if env.Search_AreaPolygons}} - - {{/if}}
- {{#if env.Search_AreaPolygons}} - - {{/if}}
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..5455f8e 100755 --- a/src/assets/js/searchpage.js +++ b/src/assets/js/searchpage.js @@ -395,7 +395,7 @@ jQuery(document).ready(function () { state: search_params.get('state'), country: search_params.get('country'), postalcode: search_params.get('postalcode'), - polygon_geojson: search_params.get('polygon_geojson') ? 1 : 0, + polygon_geojson: get_config_value('Search_AreaPolygons', false) ? 1 : 0, viewbox: search_params.get('viewbox'), exclude_place_ids: search_params.get('exclude_place_ids'), format: 'jsonv2' @@ -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..cf4df52 --- /dev/null +++ b/src/config.example.js @@ -0,0 +1,27 @@ +// 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['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": "" -}; diff --git a/src/templates/searchpage.hbs b/src/templates/searchpage.hbs index ae13597..7451398 100644 --- a/src/templates/searchpage.hbs +++ b/src/templates/searchpage.hbs @@ -59,9 +59,6 @@
- {{#if env.Search_AreaPolygons}} - - {{/if}}