Generate layer credits dynamically (#146)

This commit is contained in:
Norbert Renner 2019-04-19 22:00:25 +02:00
parent 692d67dee1
commit bea7af0084
4 changed files with 78 additions and 49 deletions

View file

@ -78,6 +78,10 @@
</div>
<div class="modal-body">
<dl>
<dt data-i18n="credits.brouter">BRouter</dt>
<dd data-i18n="[html]credits.brouter-license">
<a target="_blank" href="http://brouter.de/brouter">BRouter</a> &copy; Arndt Brenschede
</dd>
<dt data-i18n="credits.map-data">Map data</dt>
<dd data-i18n="[html]credits.openstreetmap">
&copy; <a target="_blank" href="https://www.openstreetmap.org/copyright" >OpenStreetMap contributors</a>
@ -86,42 +90,9 @@
<dd data-i18n="[html]credits.nominatim">
Search by <a href="https://wiki.openstreetmap.org/wiki/Nominatim" target="_blank">Nominatim</a>
</dd>
<dt data-i18n="credits.osm-tiles">OpenStreetMap tiles</dt>
<dd data-i18n="[html]credits.osm-license">
<a target="_blank" href="https://www.openstreetmap.org/copyright">openstreetmap.org</a>
under <a target="_blank" href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA 2.0</a>
</dd>
<dt data-i18n="credits.osmde-tiles">OpenStreetMap.de tiles</dt>
<dd>
<a target="_blank" href="https://openstreetmap.de/karte.html">openstreetmap.de</a>
</dd>
<dt data-i18n="credits.opentopomap-tiles">OpenTopoMap tiles</dt>
<dd data-i18n="[html]credits.opentopomap-license">
&copy; <a target="_blank" href="https://opentopomap.org">OpenTopoMap</a>
under <a target="_blank" href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>
<a target="_blank" href="http://viewfinderpanoramas.org">SRTM</a>
</dd>
<dt data-i18n="credits.opencyclemap-outdoors-tiles">OpenCycleMap & Outdoors tiles</dt>
<dd data-i18n="[html]credits.thunderforest-license">
&copy; <a target="_blank" href="https://www.thunderforest.com">Thunderforest</a>
under <a target="_blank" href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA 2.0</a>
</dd>
<dt data-i18n="credits.esri-tiles">Esri World Imagery</dt>
<dd data-i18n="[html]credits.esri-license">
<a target="_blank" href="http://goto.arcgisonline.com/maps/World_Imagery">World Imagery</a>
&copy; <a target="_blank" href="https://www.esri.com/">Esri</a>, sources:
Esri, DigitalGlobe, Earthstar Geographics, CNES/Airbus DS, GeoEye, USDA FSA, USGS, Getmapping, Aerogrid, IGN, IGP, and the GIS User Community
</dd>
<dt data-i18n="credits.cycling-hiking-tiles">Cycling & Hiking tiles</dt>
<dd data-i18n="[html]credits.waymarked-license">
&copy; <a target="_blank" href="https://cycling.waymarkedtrails.org">Waymarked Trails</a>
under <a target="_blank" href="https://creativecommons.org/licenses/by-sa/3.0/de/deed.en">CC-BY-SA 3.0 DE</a>
</dd>
<dt data-i18n="credits.brouter">BRouter</dt>
<dd data-i18n="[html]credits.brouter-license">
<a target="_blank" href="http://brouter.de/brouter">BRouter</a> &copy; Arndt Brenschede
</dd>
</dl>
<h5 data-i18n="credits.map-tiles">Map tiles</h5>
<dl id="credits-maps"></dl>
</div>
</div>
</div>

View file

@ -86,19 +86,27 @@ BR.LayersConfig = L.Class.extend({
var propertyOverrides = {
'standard': {
'name': i18next.t('map.layer.osm'),
'attribution': {
'html': '&copy; <a target="_blank" href="https://www.openstreetmap.org/copyright">openstreetmap.org</a>, <a target="_blank" href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA 2.0</a>'
},
'mapUrl': 'https://www.openstreetmap.org/#map={zoom}/{lat}/{lon}'
},
'OpenTopoMap': {
'name': i18next.t('map.layer.topo'),
'attribution': {
'html': '&copy; <a target="_blank" href="https://opentopomap.org/about#verwendung">OpenTopoMap</a>, <a target="_blank" href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA 3.0</a>; <a target="_blank" href="http://viewfinderpanoramas.org">SRTM</a>'
},
'mapUrl': 'https://opentopomap.org/#map={zoom}/{lat}/{lon}'
},
'Stamen.Terrain': {
'name': i18next.t('map.layer.stamen-terrain'),
'attribution': '&copy; <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>',
'mapUrl': 'http://maps.stamen.com/#terrain/{zoom}/{lat}/{lon}'
},
'Esri.WorldImagery': {
'name': i18next.t('map.layer.esri'),
'nameShort': i18next.t('credits.esri-tiles'),
'attribution': i18next.t('credits.esri-license'),
'mapUrl': 'http://www.arcgis.com/home/item.html?id=10df2279f9684e4a9f6a7f08febac2a9'
},
'wikimedia-map': {
@ -136,6 +144,9 @@ BR.LayersConfig = L.Class.extend({
'osm-mapnik-german_style': {
'name': i18next.t('map.layer.osmde'),
'language_code': 'de',
'attribution': {
'html': '&copy; <a target="_blank" href="https://openstreetmap.de/karte.html">openstreetmap.de</a>'
},
'mapUrl': 'https://www.openstreetmap.de/karte.html?zoom={zoom}&lat={lat}&lon={lon}&layers=B000TF'
},
'osmfr': {
@ -232,16 +243,23 @@ BR.LayersConfig = L.Class.extend({
'HikeBike.HillShading': {
'name': i18next.t('map.layer.hikebike-hillshading'),
'nameShort': i18next.t('map.hikebike-hillshading'),
'attribution': '&copy; <a target="_blank" href="http://hikebikemap.org">hikebikemap.org</a>; SRTM3 v2 (<a target="_blank" href="http://www2.jpl.nasa.gov/srtm/">NASA</a>)',
'mapUrl': 'http://hikebikemap.org/?zoom={zoom}&lat={lat}&lon={lon}&layer=HikeBikeMap'
},
'Waymarked_Trails-Cycling': {
'name': i18next.t('map.layer.cycling'),
'nameShort': i18next.t('map.cycling'),
'attribution': {
'html': '&copy; <a target="_blank" href="https://cycling.waymarkedtrails.org/en/help/legal">waymarkedtrails.org</a>, <a target="_blank" href="https://creativecommons.org/licenses/by-sa/3.0/de/deed.en">CC-BY-SA 3.0 DE</a>'
},
'mapUrl': 'http://cycling.waymarkedtrails.org/#?map={zoom}!{lat}!{lon}'
},
'Waymarked_Trails-Hiking': {
'name': i18next.t('map.layer.hiking'),
'nameShort': i18next.t('map.hiking'),
'attribution': {
'html': '&copy; <a target="_blank" href="https://hiking.waymarkedtrails.org/en/help/legal">waymarkedtrails.org</a>, <a target="_blank" href="https://creativecommons.org/licenses/by-sa/3.0/de/deed.en">CC-BY-SA 3.0 DE</a>'
},
'mapUrl': 'http://hiking.waymarkedtrails.org/#?map={zoom}!{lat}!{lon}'
},
'Waymarked_Trails-MTB': {
@ -382,6 +400,26 @@ BR.LayersConfig = L.Class.extend({
return result;
}
function convertAttributionJosm(props) {
var result = '';
var attr = props.attribution;
if (attr) {
if (attr.html) {
result = attr.html;
} else if (attr.url && attr.text) {
result = '<a href="' + attr.url + '" target="_blank" rel="noopener">' + attr.text + '</a>';
} else if (attr.text) {
result = attr.text;
}
}
if (!result) {
console.warn('No attribution: ' + props.id);
}
return result;
}
var options = {
maxZoom: this._map.getMaxZoom()
@ -389,6 +427,9 @@ BR.LayersConfig = L.Class.extend({
if (props.mapUrl) {
options.mapLink = '<a target="_blank" href="' + props.mapUrl + '">' + (props.nameShort || props.name) + '</a>';
}
if (props.attribution) {
options.attribution = props.attribution;
}
var keyObj = this.getKeyName(url);
if (keyObj && BR.keys[keyObj.name]) {
@ -406,7 +447,7 @@ BR.LayersConfig = L.Class.extend({
} else if (props.dataSource === 'LayersCollection') {
layer = L.tileLayer(url, L.Util.extend(options, {
minZoom: props.minZoom,
maxNativeZoom: props.maxZoom,
maxNativeZoom: props.maxZoom
}));
if (props.subdomains) {
layer.subdomains = props.subdomains;
@ -420,6 +461,7 @@ BR.LayersConfig = L.Class.extend({
minZoom: props.min_zoom,
maxNativeZoom: props.max_zoom,
subdomains: getSubdomains(josmUrl),
attribution: convertAttributionJosm(props)
});
if (props.type && props.type === 'wms') {

View file

@ -29,6 +29,10 @@ BR.Map = {
' &middot; <a href="" data-toggle="modal" data-target="#credits">' + i18next.t('map.copyright') + '</a>' +
' &middot; <a target="_blank" href="http://brouter.de/privacypolicy.html">' + i18next.t('map.privacy') + '</a>');
$('#credits').on('show.bs.modal', function (event) {
BR.Map._renderLayerCredits(layersControl._layers);
});
new L.Control.PermalinkAttribution().addTo(map);
map.attributionControl.setPrefix(false);
@ -44,7 +48,7 @@ BR.Map = {
var recent = new L.tileLayer('https://{s}.tiles.mapbox.com/v4/digitalglobe.nal0g75k/{z}/{x}/{y}.png?access_token=' + BR.keys.digitalGlobe, {
minZoom: 1,
maxZoom: 19,
attribution: i18next.t('credits.digitalglobe-license')
attribution: '&copy; <a href=\"https://www.digitalglobe.com/platforms/mapsapi\">DigitalGlobe</a> (<a href=\"https://bit.ly/mapsapiview\">Terms of Use</a>)'
});
baseLayers[i18next.t('map.layer.digitalglobe')] = recent;
}
@ -89,6 +93,27 @@ BR.Map = {
map: map,
layersControl: layersControl
};
}
},
_renderLayerCredits: function (layers) {
var dl = document.getElementById('credits-maps');
var i, obj, dt, dd, attribution;
L.DomUtil.empty(dl);
for (i = 0; i < layers.length; i++) {
obj = layers[i];
attribution = obj.layer.options.attribution;
if (attribution) {
dt = document.createElement('dt');
dt.innerHTML = obj.name;
dd = document.createElement('dd');
dd.innerHTML = obj.layer.options.attribution;
dl.appendChild(dt);
dl.appendChild(dd);
}
}
}
};

View file

@ -14,21 +14,12 @@
"credits": {
"brouter": "BRouter",
"brouter-license": "<a target=\"_blank\" href=\"http://brouter.de/brouter\">BRouter</a> &copy; Arndt Brenschede",
"cycling-hiking-tiles": "Cycling & Hiking tiles",
"digitalglobe-license": "&copy; <a href=\"https://www.digitalglobe.com/platforms/mapsapi\">DigitalGlobe</a> (<a href=\"https://bit.ly/mapsapiview\">Terms of Use</a>)",
"esri-license": "<a target=\"_blank\" href=\"http://goto.arcgisonline.com/maps/World_Imagery\">World Imagery</a> &copy; <a target=\"_blank\" href=\"https://www.esri.com/\">Esri</a>, sources: Esri, DigitalGlobe, Earthstar Geographics, CNES/Airbus DS, GeoEye, USDA FSA, USGS, Getmapping, Aerogrid, IGN, IGP, and the GIS User Community",
"esri-tiles": "Esri World Imagery",
"map-data": "Map data",
"map-tiles": "Map tiles",
"nominatim": "Search by <a href=\"https://wiki.openstreetmap.org/wiki/Nominatim\" target=\"_blank\" data-i18n=\"credits.nominatim\">Nominatim</a>",
"opencyclemap-outdoors-tiles": "OpenCycleMap & Outdoors tiles",
"openstreetmap": "&copy; <a target=\"_blank\" href=\"https://www.openstreetmap.org/copyright\" >OpenStreetMap contributors</a> under <a target=\"_blank\" href=\"https://opendatacommons.org/licenses/odbl/\" >ODbL</a>",
"opentopomap-license": "&copy; <a target=\"_blank\" href=\"https://opentopomap.org\">OpenTopoMap</a> under <a target=\"_blank\" href=\"https://creativecommons.org/licenses/by-sa/3.0/\">CC-BY-SA</a> <a target=\"_blank\" href=\"http://viewfinderpanoramas.org\">SRTM</a>",
"opentopomap-tiles": "OpenTopoMap tiles",
"osm-license": "<a target=\"_blank\" href=\"https://www.openstreetmap.org/copyright\">openstreetmap.org</a> under <a target=\"_blank\" href=\"https://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA 2.0</a>",
"osm-tiles": "OpenStreetMap tiles",
"osmde-tiles": "OpenStreetMap.de tiles",
"thunderforest-license": "&copy; <a target=\"_blank\" href=\"https://www.thunderforest.com\">Thunderforest</a> under <a target=\"_blank\" href=\"https://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA 2.0</a>",
"waymarked-license": "&copy; <a target=\"_blank\" href=\"https://cycling.waymarkedtrails.org\">Waymarked Trails</a> under <a target=\"_blank\" href=\"https://creativecommons.org/licenses/by-sa/3.0/de/deed.en\">CC-BY-SA 3.0 DE</a>"
"openstreetmap": "&copy; <a target=\"_blank\" href=\"https://www.openstreetmap.org/copyright\" >OpenStreetMap contributors</a> under <a target=\"_blank\" href=\"https://opendatacommons.org/licenses/odbl/\" >ODbL</a>"
},
"footer": {
"ascend": "Ascend (Plain ascend)",