├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
├── html
├── L.Control.Geonames.css
├── L.Control.Geonames.js
├── index.html
├── leaflet-hash.js
├── leaflet-side-by-side.js
├── leaflet.css
├── leaflet.js
├── redacted-note.txt
└── style.css
└── osm-vintage-tile-server.sh
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | buy_me_a_coffee: 3lqho1lkks
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.osm.pbf
2 | .DS_Store
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2022 Martijn van Exel
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OpenStreetMap Vintage Tile Server
2 |
3 | ## We are on Sourcehut
4 | If you are reading this notice on Github, please point your bookmarks and git remotes at the `osm-vintage-tiles` repo [on Sourcehut](https://git.sr.ht/~mvexel/osm-vintage-tiles) instead. This project will not be updated on Github.
5 |
6 | ---
7 |
8 |
9 | ## [Demo server](https://2008.osm.lol/)
10 |
11 | Ever long for the good old days when OSM was formless and void?
12 |
13 | Now you can with a one-liner!
14 |
15 | Well, almost:
16 |
17 | ## Prerequisites
18 |
19 | This script has only been tested on a Linux (Ubuntu 21.10) machine.
20 |
21 | You need [docker](https://docs.docker.com/engine/install/ubuntu/) and [osmium](https://osmcode.org/osmium-tool/manual.html) installed.
22 |
23 | You need an OSM full history planet. You can obtain this from various [OSM planet mirrors](https://wiki.openstreetmap.org/wiki/Planet.osm#Planet.osm_mirrors), or for smaller regions (recommended!) from [Geofabrik](https://download.geofabrik.de/).
24 |
25 | ## Usage
26 |
27 | Call the script with two arguments:
28 | 1. The full path to your history PBF
29 | 2. The 4-digit year you want tiles for
30 |
31 | *With a default Docker installation on Linux, you will need to run the script as root. Never run random things from the internet as root. Don't trust me. Inspect the script and trust it.*
32 |
33 | `./osm-vintage-tile-server.sh /path/to/history.osh.pbf 2008`
34 |
35 | This example will take `/path/to/history.osh.pbf`, create a 2008-01-01 vintage planet, set up a tile server with that data, and expose it at port 8008. (The port will be 6000 + the year you choose.)
36 |
37 | ## Bonus: Side By Side HTML
38 |
39 | 
40 |
41 | To see the tiles from your new vintage server side by side with the live OSM tiles, you can use the HTML + JS included in the `html/` subdirectory. Just change the URL in [this line](https://github.com/mvexel/openstreetmap-vintage-tile-server/blob/main/html/index.html#L43) to point to your own server and load `index.html` in your browser.
42 |
43 | This uses the [leaflet-hash](https://github.com/mlevans/leaflet-hash) and [leaflet-side-by-side](https://github.com/digidem/leaflet-side-by-side) plugins, which are included. Leaflet itself is loaded from a CDN.
44 |
45 | ## Credits
46 |
47 | * [osmium](https://osmcode.org/osmium-tool/) takes care of time-slicing the full history planet. It continues to blow my mind how fast this tool is and how much it can do.
48 | * The actual heavy lifting is done by the [openstreetmap-tile-server Docker image](https://github.com/Overv/openstreetmap-tile-server).
49 |
--------------------------------------------------------------------------------
/html/L.Control.Geonames.css:
--------------------------------------------------------------------------------
1 | .leaflet-top.leaflet-center {
2 | left: 10px;
3 | right: 10px;
4 | }
5 |
6 | .leaflet-geonames-search {
7 | background-color: #FFF;
8 | width: 34px;
9 | max-width: 300px;
10 | box-sizing: border-box;
11 | }
12 |
13 | .leaflet-geonames-search.active {
14 | width: 100%;
15 | }
16 |
17 | .leaflet-geonames-search a {
18 | border-radius: 4px;
19 | position: absolute;
20 | left: 0;
21 | top: 0;
22 | background-color: transparent !important;
23 | border: none !important;
24 | }
25 |
26 | .leaflet-geonames-search form {
27 | width: 100%;
28 | height: 30px;
29 | }
30 |
31 | .leaflet-geonames-search input {
32 | padding: 6px 6px 2px 30px;
33 | margin: 0;
34 | border: none;
35 | display: none;
36 | width: 100%;
37 | font-size: 12pt;
38 | box-sizing: border-box;
39 | -ms-box-sizing: border-box;
40 | }
41 |
42 | .leaflet-geonames-search ul {
43 | display: none;
44 | list-style: none;
45 | padding: 0;
46 | margin: 0;
47 | clear: both;
48 | }
49 |
50 | .leaflet-geonames-search ul li {
51 | padding: 4px 8px;
52 | border-top: 1px solid #DDD;
53 | font-size: 1.1em;
54 | }
55 |
56 | .leaflet-geonames-search ul.hasResults li:hover {
57 | background: #F2F2F2;
58 | cursor: pointer;
59 | }
60 |
61 | .leaflet-geonames-search ul li em {
62 | color: #999;
63 | }
64 |
65 | .leaflet-geonames-search input:focus {
66 | outline: 0;
67 | }
68 |
69 | .leaflet-geonames-search.active input,
70 | .leaflet-geonames-search.active label {
71 | display: inline-block;
72 | }
73 |
74 | .leaflet-geonames-search ul.hasResults,
75 | .leaflet-geonames-search ul.noResults {
76 | display: block;
77 | }
78 |
79 | .leaflet-geonames-search ul.noResults {
80 | color: #999;
81 | font-style: italic;
82 | }
83 |
84 | .leaflet-geonames-icon {
85 | background: transparent no-repeat center center;
86 | /*src: https://material.io/icons/#ic_search*/
87 | background-image: url(data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjMDAwMDAwIiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHdpZHRoPSIyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4gICAgPHBhdGggZD0iTTE1LjUgMTRoLS43OWwtLjI4LS4yN0MxNS40MSAxMi41OSAxNiAxMS4xMSAxNiA5LjUgMTYgNS45MSAxMy4wOSAzIDkuNSAzUzMgNS45MSAzIDkuNSA1LjkxIDE2IDkuNSAxNmMxLjYxIDAgMy4wOS0uNTkgNC4yMy0xLjU3bC4yNy4yOHYuNzlsNSA0Ljk5TDIwLjQ5IDE5bC00Ljk5LTV6bS02IDBDNy4wMSAxNCA1IDExLjk5IDUgOS41UzcuMDEgNSA5LjUgNSAxNCA3LjAxIDE0IDkuNSAxMS45OSAxNCA5LjUgMTR6Ii8+ICAgIDxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZpbGw9Im5vbmUiLz48L3N2Zz4=);
88 | }
89 |
90 | .leaflet-geonames-icon-working {
91 | /*src: https://design.google.com/icons/#ic_autorenew*/
92 | background-image: url(data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjMDAwMDAwIiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHdpZHRoPSIyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4gICAgPHBhdGggZD0iTTEyIDZ2M2w0LTQtNC00djNjLTQuNDIgMC04IDMuNTgtOCA4IDAgMS41Ny40NiAzLjAzIDEuMjQgNC4yNkw2LjcgMTQuOGMtLjQ1LS44My0uNy0xLjc5LS43LTIuOCAwLTMuMzEgMi42OS02IDYtNnptNi43NiAxLjc0TDE3LjMgOS4yYy40NC44NC43IDEuNzkuNyAyLjggMCAzLjMxLTIuNjkgNi02IDZ2LTNsLTQgNCA0IDR2LTNjNC40MiAwIDgtMy41OCA4LTggMC0xLjU3LS40Ni0zLjAzLTEuMjQtNC4yNnoiLz4gICAgPHBhdGggZD0iTTAgMGgyNHYyNEgweiIgZmlsbD0ibm9uZSIvPjwvc3ZnPg==);
93 | animation: spin 2s infinite linear;
94 | }
95 |
96 | @-webkit-keyframes spin {
97 | 0% {
98 | -webkit-transform: rotate(0deg);
99 | transform: rotate(0deg)
100 | }
101 | 100% {
102 | -webkit-transform: rotate(359deg);
103 | transform: rotate(359deg)
104 | }
105 | }
106 |
107 | @keyframes spin {
108 | 0% {
109 | -webkit-transform: rotate(0deg);
110 | transform: rotate(0deg)
111 | }
112 | 100% {
113 | -webkit-transform: rotate(359deg);
114 | transform: rotate(359deg)
115 | }
116 | }
--------------------------------------------------------------------------------
/html/L.Control.Geonames.js:
--------------------------------------------------------------------------------
1 | //See this url for more info about valid adminCodes: http://www.geonames.org/export/geonames-search.html
2 | var ADMIN_CODES = ['country', 'adminCode1', 'adminCode2', 'adminCode3', 'continentCode'];
3 | var BBOX = ['east', 'west', 'north', 'south'];
4 | var POSTALCODE_REGEX_US = /^\d{5}(-\d{4})?$/;
5 |
6 | // from: https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
7 | var POSTALCODE_REGEX_UK = /^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2})$/
8 |
9 | L.Control.Geonames = L.Control.extend({
10 | includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
11 |
12 | _active: false,
13 | _resultsList: null,
14 | _marker: null,
15 | _popup: null,
16 | _hasResults: false,
17 | options: {
18 | //position: 'topcenter', // In addition to standard 4 corner Leaflet control layout, this will position and size from top center.
19 | position: 'topleft',
20 | geonamesSearch: 'https://secure.geonames.org/searchJSON', // Override this if using a proxy to get connection to geonames.
21 | geonamesPostalCodesSearch: 'https://secure.geonames.org/postalCodeSearchJSON', // Override this if using a proxy to get connection to geonames.
22 | username: '', // Geonames account username. Must be provided.
23 | maxresults: 5, // Maximum number of results to display per search.
24 | zoomLevel: null, // Max zoom level to zoom to for location. If null, will use the map's max zoom level.
25 | className: 'leaflet-geonames-icon', // Class for icon.
26 | workingClass: 'leaflet-geonames-icon-working', // Class for search underway.
27 | featureClasses: ['A', 'H', 'L', 'P', 'R', 'T', 'U', 'V'], // Feature classes to search against. See: http://www.geonames.org/export/codes.html.
28 | baseQuery: 'isNameRequired=true', // The core query sent to GeoNames, later combined with other parameters above.
29 | showMarker: true, // Show a marker at the location the selected location.
30 | showPopup: true, // Show a tooltip at the selected location.
31 | adminCodes: {}, // Filter results by the specified admin codes mentioned in `ADMIN_CODES`. Each code can be a string or a function returning a string. `country` can be a comma-separated list of countries.
32 | bbox: {}, // An object in form of {east:..., west:..., north:..., south:...}, specifying the bounding box to limit the results to.
33 | lang: 'en', // Locale of results.
34 | alwaysOpen: false, // If true, search field is always visible.
35 | enablePostalCodes: true, // If true, use postalCodesRegex to test user provided string for a postal code. If matches, then search against postal codes API instead.
36 | postalCodesRegex: POSTALCODE_REGEX_US, // Regex used for testing user provided string for a postal code. If this test fails, the default geonames API is used instead.
37 | title: 'Search by location name or postcode', // Search input title value.
38 | placeholder: 'Enter a location name' // Search input placeholder text.
39 | },
40 | onAdd: function (map) {
41 | if (this.options.position == 'topcenter') {
42 | // construct a top-center location for this widget
43 | // trick from: https://stackoverflow.com/questions/33614912/how-to-locate-leaflet-zoom-control-in-a-desired-position
44 | map._controlCorners.topcenter = L.DomUtil.create('div', 'leaflet-top leaflet-center', map._controlContainer);
45 | }
46 |
47 | this._container = L.DomUtil.create('div', 'leaflet-geonames-search leaflet-bar');
48 |
49 | // keep mouse events from causing map to drag or zoom map
50 | L.DomEvent.disableClickPropagation(this._container);
51 |
52 | var link = this._link = L.DomUtil.create('a', this.options.className, this._container);
53 | link.href = '#';
54 | link.title = this.options.title;
55 |
56 | var form = L.DomUtil.create('form', '', this._container);
57 | L.DomEvent.addListener(form, 'submit', this._search, this);
58 |
59 | var input = this._input = L.DomUtil.create('input', '', form);
60 | input.type = 'search';
61 | input.placeholder = this.options.placeholder;
62 |
63 | this._url = this.options.geonamesSearch;
64 | this._resultsList = L.DomUtil.create('ul', '', this._container);
65 |
66 | L.DomEvent.on(input, 'keyup change search', function (e) {
67 | if (e.type === 'search') {
68 | // When input changes, clear out the results
69 | L.DomUtil.removeClass(this._resultsList, 'hasResults');
70 | L.DomUtil.removeClass(this._resultsList, 'noResults');
71 | this._hasResults = false;
72 | this._resultsList.innerHTML = '';
73 | this.removeMarker();
74 | this.removePopup();
75 | }
76 | }, this);
77 |
78 | L.DomEvent.on(input, 'focus', function () {
79 | if (!this.active) {
80 | this.show();
81 | }
82 | }, this);
83 |
84 | if (this.options.alwaysOpen) {
85 | this._active = true;
86 | L.DomUtil.addClass(this._container, 'active');
87 | L.DomEvent.on(link, 'click', this.show, this);
88 | } else {
89 | // Control button toggles visibility of the search field
90 | L.DomEvent.on(link, 'click', function () {
91 | if (this._active) {
92 | this.hide();
93 | } else {
94 | this.focus();
95 | }
96 | }, this);
97 | }
98 |
99 | map.on('click', this._mapClicked, this);
100 |
101 | return this._container;
102 | },
103 | onRemove: function () {
104 | this._map.off('click', this._mapClicked, this);
105 | },
106 | _mapClicked: function (event) {
107 | // ENTER key raises a click event too; ignore it
108 | if (event.originalEvent instanceof KeyboardEvent) {
109 | return;
110 | }
111 | if (this.options.alwaysOpen) {
112 | this.hideResults();
113 | } else {
114 | this.hide();
115 | }
116 | },
117 | addPoint: function (geoname) {
118 | var that = this
119 | // clear out previous point / popup
120 | this.removeMarker();
121 | this.removePopup();
122 |
123 | var name = this._getNameParts(geoname).join(', ');
124 | var lat = parseFloat(geoname.lat);
125 | var lon = parseFloat(geoname.lng);
126 |
127 | // if (this.options.showMarker || this.options.showPopup) {
128 | var zoomLevel = this.options.zoomLevel || this._map.getMaxZoom();
129 | this._map.setView([lat, lon], zoomLevel, false);
130 | // }
131 |
132 | if (this.options.showMarker) {
133 | this._marker = L.marker([lat, lon]).addTo(this._map);
134 |
135 | if (this.options.showPopup) {
136 | this._marker.bindPopup(name);
137 | this._marker.openPopup()
138 | this._marker.on('popupclose', function() {
139 | that._onPopupClosed()
140 | });
141 | }
142 | } else if (this.options.showPopup) {
143 | this._popup = L.popup()
144 | .setLatLng([lat, lon])
145 | .setContent(name)
146 | .openOn(this._map)
147 | .on('remove', function() {
148 | that._onPopupClosed()
149 | });
150 | }
151 | },
152 | show: function () {
153 | this._active = true;
154 | L.DomUtil.addClass(this._container, 'active');
155 | if (this._hasResults) {
156 | L.DomUtil.addClass(this._resultsList, 'hasResults');
157 | } else {
158 | L.DomUtil.addClass(this._resultsList, 'noResults');
159 | }
160 | },
161 | hide: function () {
162 | this._active = false;
163 | L.DomUtil.removeClass(this._container, 'active');
164 | this.hideResults();
165 | },
166 | hideResults: function () {
167 | L.DomUtil.removeClass(this._resultsList, 'hasResults');
168 | L.DomUtil.removeClass(this._resultsList, 'noResults');
169 | },
170 | focus: function () {
171 | this.show();
172 | this._input.focus();
173 | },
174 | _close: function () {
175 | // Clear search field (if not alwaysOpen, close results list, and
176 | // remove marker
177 | this.hide();
178 | this.removeMarker();
179 | this.removePopup();
180 | },
181 | removeMarker: function () {
182 | if (this._marker != null) {
183 | this._map.removeLayer(this._marker);
184 | this._marker = null;
185 | }
186 | },
187 | removePopup: function () {
188 | if (this._popup != null) {
189 | this._map.closePopup(this._popup);
190 | this._popup = null;
191 | }
192 | },
193 | _onPopupClosed: function () {
194 | this.removeMarker();
195 | this.removePopup();
196 | this._hasResults = false;
197 | this._resultsList.innerHTML = '';
198 | },
199 | _search: function (event) {
200 | L.DomEvent.preventDefault(event);
201 |
202 | L.DomUtil.addClass(this._link, this.options.workingClass);
203 | L.DomUtil.removeClass(this._resultsList, 'noResults');
204 |
205 | //clear results
206 | this._hasResults = false;
207 | this._resultsList.innerHTML = '';
208 |
209 | var i, param, apiURL;
210 | var query = this._input.value;
211 | var searchParams = {
212 | lang: this.options.lang
213 | };
214 | var extraQueryParams = '';
215 |
216 | if (this.options.enablePostalCodes && this.options.postalCodesRegex.test(query)) {
217 | // search against postalCodes API
218 | apiURL = this.options.geonamesPostalCodesSearch;
219 | searchParams.postalcode = query;
220 | searchParams.isReduced = false;
221 |
222 | } else {
223 | // search against default API
224 | apiURL = this.options.geonamesSearch;
225 | searchParams.q = query;
226 |
227 | if (this.options.featureClasses && this.options.featureClasses.length) {
228 | extraQueryParams += '&' + this.options.featureClasses.map(function (fc) {
229 | return 'featureClass=' + fc
230 | }).join('&');
231 | }
232 | }
233 |
234 | // Add adminCodes to query
235 | for (param in this.options.adminCodes) {
236 | // Ignore any admin codes that are not valid
237 | if (ADMIN_CODES.indexOf(param) == -1) continue;
238 |
239 | var paramValue = this.options.adminCodes[param];
240 | searchParams[param] = (typeof paramValue == 'function') ? paramValue() : paramValue;
241 | }
242 |
243 | // Add bbox to query
244 | var bbox = (typeof this.options.bbox == 'function') ? this.options.bbox() : this.options.bbox;
245 | for (i in BBOX) {
246 | // Ignore the bbox if it is not valid
247 | if (!bbox[BBOX[i]]) {
248 | bbox = null;
249 | break;
250 | }
251 | }
252 | if (bbox) {
253 | for (i in BBOX) {
254 | param = BBOX[i];
255 | searchParams[param] = bbox[param];
256 | }
257 | }
258 |
259 | this.fire('search', {
260 | params: searchParams
261 | });
262 |
263 | // parameters excluded from event above
264 | var coreParams = {
265 | username: this.options.username,
266 | maxRows: this.options.maxresults,
267 | style: "LONG"
268 | };
269 |
270 | var url = apiURL + '?' + this._objToQuery(coreParams) + '&' + this._objToQuery(searchParams) + extraQueryParams;
271 | if (this.options.baseQuery) {
272 | url += '&' + this.options.baseQuery;
273 | }
274 |
275 | var origScope = this;
276 | var callbackName = 'geonamesSearchCallback' + new Date().getTime();
277 | this._jsonp(url,
278 | function (response) {
279 | document.body.removeChild(document.getElementById('getJsonP'));
280 | delete window[callbackName];
281 | origScope._processResponse(response);
282 | },
283 | callbackName
284 | );
285 |
286 | },
287 | _objToQuery: function (obj) {
288 | var queryParams = [];
289 | for (var param in obj)
290 | if (obj.hasOwnProperty(param)) {
291 | queryParams.push(encodeURIComponent(param) + "=" + encodeURIComponent(obj[param]));
292 | }
293 | return queryParams.join("&");
294 | },
295 | _jsonp: function (url, callback, callbackName) {
296 | callbackName = callbackName || 'jsonpCallback';
297 | window[callbackName] = callback;
298 |
299 | url += '&callback=' + callbackName;
300 | var script = document.createElement('script');
301 | script.id = 'getJsonP';
302 | script.src = url;
303 | script.async = true;
304 | document.body.appendChild(script);
305 | },
306 | _processResponse: function (response) {
307 | var jsonResponse;
308 | if (typeof response.geonames != 'undefined') {
309 | jsonResponse = response.geonames;
310 | } else if (typeof response.postalCodes != 'undefined') {
311 | jsonResponse = response.postalCodes;
312 | }
313 | L.DomUtil.removeClass(this._link, this.options.workingClass);
314 |
315 | if (jsonResponse.length > 0) {
316 | L.DomUtil.addClass(this._resultsList, 'hasResults');
317 | this._hasResults = true;
318 | var li;
319 | jsonResponse.forEach(function (geoname) {
320 | li = L.DomUtil.create('li', '', this._resultsList);
321 | var nameParts = this._getNameParts(geoname);
322 | var primaryName = nameParts.slice(0, 2).join(', ');
323 | var countryName = (nameParts.length > 2) ? ' ' + nameParts[2] + '' : '';
324 | li.innerHTML = primaryName + countryName;
325 |
326 | L.DomEvent.addListener(li, 'click', function () {
327 | //The user picks a location and it changes the search text to be that location
328 | this._input.value = primaryName;
329 |
330 | if (this.options.alwaysOpen) {
331 | this.hideResults();
332 | } else {
333 | this.hide();
334 | }
335 |
336 | this.fire('select', {
337 | geoname: geoname
338 | });
339 | this.addPoint(geoname);
340 | }, this);
341 | }, this);
342 | } else {
343 | L.DomUtil.addClass(this._resultsList, 'noResults');
344 | li = L.DomUtil.create('li', '', this._resultsList);
345 | li.innerText = 'No results found';
346 | }
347 | },
348 | _getNameParts: function (geoname) {
349 | var extraName;
350 | var parts = [];
351 | if (typeof geoname.name != 'undefined') {
352 | parts.push(geoname.name);
353 | } else if (typeof geoname.postalCode != 'undefined') {
354 | parts.push(geoname.postalCode);
355 | }
356 |
357 | ['adminName1', 'adminName2', 'countryName', 'countryCode'].forEach(function (d) {
358 | extraName = geoname[d];
359 | if (extraName && extraName != '' && extraName != parts[0]) {
360 | parts.push(extraName);
361 | }
362 | }, this);
363 | return parts;
364 | }
365 | });
366 |
367 | L.control.geonames = function (options) {
368 | return new L.Control.Geonames(options);
369 | };
--------------------------------------------------------------------------------
/html/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | OSM Then and Now
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
OSM Then and Now
21 |
Explore OSM how it was in 2008 (left) and compare with how it is now (right). Use the slider
22 | to reveal more of the one or the other. A note about this data Help me keep this website up by supporting me with a few bucks. Thanks!