Use TopoJSON for smaller files

This commit is contained in:
Norbert Renner 2021-01-22 11:50:27 +01:00
parent dc8302479e
commit 3037fb8f17
8 changed files with 64 additions and 24 deletions

View file

@ -79,7 +79,7 @@ var paths = {
'layers/config/geometry.js', 'layers/config/geometry.js',
], ],
layersConfigDestName: 'layersConf.js', layersConfigDestName: 'layersConf.js',
boundaries: 'resources/boundaries/*.geojson', boundaries: ['resources/boundaries/*.geojson', 'resources/boundaries/*.topo.json'],
zip: ['dist/**', 'index.html', 'config.template.js', 'keys.template.js'], zip: ['dist/**', 'index.html', 'config.template.js', 'keys.template.js'],
dest: 'dist', dest: 'dist',
destName: 'brouter-web', destName: 'brouter-web',

View file

@ -30,6 +30,38 @@ BR.Util = {
return new Error(msg); return new Error(msg);
}, },
getJson: function (url, context, cb) {
BR.Util.get(url, function (err, data) {
if (err) {
BR.message.showError('Error getting ' + context + ': ' + err);
return cb(err);
}
try {
var json = JSON.parse(data);
cb(null, json);
} catch (err) {
BR.message.showError('Error parsing ' + context + ': ' + err);
console.error(err);
cb(err);
}
});
},
getGeoJson: function (url, context, cb) {
BR.Util.getJson(url, context, function (err, data) {
if (err) return cb(err);
var geoJson = data;
if (data && data.type && data.type === 'Topology') {
var key = Object.keys(data.objects)[0];
geoJson = topojson.feature(data, data.objects[key]);
}
cb(null, geoJson);
});
},
// check if localStorage is available, especially for catching SecurityError // check if localStorage is available, especially for catching SecurityError
// when cookie settings are blocking access (Chrome, Pale Moon, older Firefox) // when cookie settings are blocking access (Chrome, Pale Moon, older Firefox)
// //

View file

@ -7,7 +7,7 @@ BR.CircleGoArea = L.Control.extend({
options: { options: {
radius: 1000, // in meters radius: 1000, // in meters
stateRules: false, stateRules: false,
statesUrl: BR.conf.statesUrl || 'dist/boundaries/germany-states.geojson', statesUrl: BR.conf.statesUrl || 'dist/boundaries/germany-states.topo.json',
overpassBaseUrl: BR.conf.overpassBaseUrl || 'https://overpass-api.de/api/interpreter?data=', overpassBaseUrl: BR.conf.overpassBaseUrl || 'https://overpass-api.de/api/interpreter?data=',
shortcut: { shortcut: {
draw: { draw: {
@ -276,28 +276,21 @@ BR.CircleGoArea = L.Control.extend({
}, },
_loadStates: function (cb) { _loadStates: function (cb) {
BR.Util.get( BR.Util.getGeoJson(
this.options.statesUrl, this.options.statesUrl,
'states',
L.bind(function (err, data) { L.bind(function (err, data) {
if (err) { // TODO spinner aus?, mit ringgo parameter testen
BR.message.showError('Error getting states: ' + err); if (err) return;
return;
}
try { this.states = data;
this.states = JSON.parse(data);
// debugging // debugging
//this._logStates(this.states); //this._logStates(this.states);
//this._addStatesLayer(this.states); //this._addStatesLayer(this.states);
this.fire('states:loaded'); this.fire('states:loaded');
cb();
cb();
} catch (err) {
BR.message.showError('Error parsing states: ' + err);
console.error(err);
}
}, this) }, this)
); );
}, },

View file

@ -74,6 +74,7 @@
"mapbbcode": "MapBBCode/mapbbcode#v1.2.0", "mapbbcode": "MapBBCode/mapbbcode#v1.2.0",
"osmtogeojson": "^3.0.0-beta.4", "osmtogeojson": "^3.0.0-beta.4",
"promise-polyfill": "^8.2.0", "promise-polyfill": "^8.2.0",
"topojson-client": "^3.1.0",
"url-search-params": "~0.5.0", "url-search-params": "~0.5.0",
"whatwg-fetch": "^3.5.0" "whatwg-fetch": "^3.5.0"
}, },

View file

@ -1,11 +1,25 @@
# boundaries # boundaries
## germany-states.geojson Downloaded from https://osm-boundaries.com.
TopoJSON (https://github.com/topojson/topojson) used to convert to topology, simplify and reduce precision:
`npm install -g topojson`
## germany-states
Currently only containing states that do not use the municipality boundary for the Corona 15 km allowed zone rule. Currently only containing states that do not use the municipality boundary for the Corona 15 km allowed zone rule.
Downloaded from https://osm-boundaries.com with:
``` ```
curl --remote-name --remote-header-name --location --max-redirs -1 "https://osm-boundaries.com/Download/Submit?apiKey=YOUR_API_KEY&db=osm20201109&osmIds=-28322,-62771,-62372,-62467,-62607,-62422,-62782,-62504&includeAllTags&simplify=0.0001" curl --remote-name --remote-header-name --location --max-redirs -1 "https://osm-boundaries.com/Download/Submit?apiKey=YOUR_API_KEY&db=osm20201109&osmIds=-28322,-62771,-62372,-62467,-62607,-62422,-62782,-62504&includeAllTags"
geo2topo germany-states.geojson | toposimplify -s 3e-12 | topoquantize 1e6 > germany-states.topo.json
```
## countries
```
curl --remote-name --remote-header-name --location --max-redirs -1 "https://osm-boundaries.com/Download/Submit?apiKey=YOUR_API_KEY&db=osm20201109&osmIds=-51477,-1403916"
geo2topo countries.geojson | toposimplify -s 3e-12 | topoquantize 1e6 > countries.topo.json
``` ```

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -8173,7 +8173,7 @@ toidentifier@1.0.0:
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553" resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw== integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
topojson-client@3: topojson-client@3, topojson-client@^3.1.0:
version "3.1.0" version "3.1.0"
resolved "https://registry.yarnpkg.com/topojson-client/-/topojson-client-3.1.0.tgz#22e8b1ed08a2b922feeb4af6f53b6ef09a467b99" resolved "https://registry.yarnpkg.com/topojson-client/-/topojson-client-3.1.0.tgz#22e8b1ed08a2b922feeb4af6f53b6ef09a467b99"
integrity sha512-605uxS6bcYxGXw9qi62XyrV6Q3xwbndjachmNxu8HWTtVPxZfEJN9fd/SZS1Q54Sn2y0TMyMxFj/cJINqGHrKw== integrity sha512-605uxS6bcYxGXw9qi62XyrV6Q3xwbndjachmNxu8HWTtVPxZfEJN9fd/SZS1Q54Sn2y0TMyMxFj/cJINqGHrKw==