From cbd0b625501760b7779de8ae6e802503130bdd9d Mon Sep 17 00:00:00 2001 From: Speeder Date: Mon, 8 Jan 2024 21:33:24 +0100 Subject: [PATCH] Added an overlay that highlights curves. --- index.html | 3 ++- map/curves.geojson | 3 +++ map/curves.md | 15 +++++++++++++++ res/huroutes.js | 39 +++++++++++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 map/curves.geojson create mode 100644 map/curves.md diff --git a/index.html b/index.html index 8aefa3f..e748fa0 100644 --- a/index.html +++ b/index.html @@ -70,7 +70,8 @@ 'Google Map': 'Google Térkép', 'Google Terrain': 'Google Domborzat', 'Google Satellite': 'Google Műhold', - 'Elevation Shading': 'Domborzat Kiemelés' + 'Elevation Shading': 'Domborzat Kiemelés', + 'Curvature': 'Kanyarívek' }, 'themes': { 'System Theme': 'Rendszer megjelenése', diff --git a/map/curves.geojson b/map/curves.geojson new file mode 100644 index 0000000..40e9810 --- /dev/null +++ b/map/curves.geojson @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b165e4d1985bdc10d37bba0a0890344088fbff2158f577853aba298e3ee4fba +size 4330695 diff --git a/map/curves.md b/map/curves.md new file mode 100644 index 0000000..8c1dedc --- /dev/null +++ b/map/curves.md @@ -0,0 +1,15 @@ +# Data source + +Data source is from: https://roadcurvature.com/. + +Direct download of data is from: https://kml.roadcurvature.com/europe/hungary.c_1000.kmz. + +This data has been converted to geoJson with the tool: https://mygeodata.cloud/converter/kml-to-gpx. + +# License + +RoadCurvature.com is © Adam Franco. + +The Curvature program is © Adam Franco and is open-source software licensed under the Gnu General Public License (GPL) Version 3 or later. + +Curvature output data is © OpenStreetMap Contributors and are open-data provided under the terms of the Open Data Commons Open Database License (ODBL). diff --git a/res/huroutes.js b/res/huroutes.js index 6387650..577f331 100644 --- a/res/huroutes.js +++ b/res/huroutes.js @@ -27,11 +27,19 @@ const huroutes = { }, // Choosable overlay sources supported in the layer selector. All are off by default. 'overlays': { - 'Elevation Shading': L.tileLayer('https://map.turistautak.hu/tiles/shading/{z}/{x}/{y}.png', {attribution:'© turistautak.hu',minZoom:5,maxZoom: 18,zIndex:5,className: 'overlay-dem'}) + 'Elevation Shading': L.tileLayer('https://map.turistautak.hu/tiles/shading/{z}/{x}/{y}.png', {attribution:'© turistautak.hu',minZoom:5,maxZoom: 18,zIndex:5,className: 'overlay-dem'}), + 'Curvature': L.layerGroup(null, {attribution:'Curves: © OpenStreetMap contributors'}) }, // Overlay sources that are always shown and hidden along with specific map tile sources. // The name of the overlay must be the same as the tile layer to which it is bound. - 'tileOverlays': {} + 'tileOverlays': {}, + // Lazy-content overlay data, which is downloaded only when the user first shows it. + // Usage: Create an overlay under 'overlays' with an empty L.layerGroup. Create an + // item in 'lazyOverlays' with the same ID as the layergroup overlay. The value is + // a function that returns the layer that contains the data. + 'lazyOverlays': { + 'Curvature': (layer) => omnivore.geojson('map/curves.geojson', null, layer) + } }, // A list of navigation service providers that can be chosen for the "navigate to" links'. // The default provider used is the first one. @@ -181,7 +189,10 @@ $(document).ready(function() { (localStorage.overlays || '').split('|').forEach(item => { const overlay = overlays[item]; if (overlay) + { overlay.addTo(map); + initLazyOverlay(item, overlay); + } }); const tileOverlay = huroutes.opt.map.tileOverlays[localStorage.mapstyle]; if (tileOverlay) @@ -256,6 +267,8 @@ function initCtrls(tiles, overlays) overlays = overlays ? overlays.split('|') : []; overlays.push(overlay.layer.id); localStorage.overlays = overlays.join('|'); + + initLazyOverlay(overlay.layer.id, overlay.layer); }); map.on('overlayremove', (overlay) => { var overlays = (localStorage.overlays || '').split('|'); @@ -304,6 +317,28 @@ function initCtrls(tiles, overlays) }, true); } +/** + * Initializes data inside of a layer group on demand. + * @param {string} id The overlay identifier. + * @param {object} layerGroup A Leaflet layerGroup object to which the data is added. + */ +function initLazyOverlay(id, layerGroup) +{ + try { + if (layerGroup.getLayers().length == 0) + { + var layer = L.geoJson(null, { + style: { + color: '#BB0', + opacity: 0.9, + weight: 1.5 + } + }); + layerGroup.addLayer(huroutes.opt.map.lazyOverlays[id](layer)); + } + } catch { } +} + /** * Loads route data into the web application. * @param {object} data The huroutes database.