Setting Copyrights Explicitly
In the following sample, the copyright of the TileLayer
is set explicitly. For simple applications with only one layer, this approach may be sufficient.
The Copyright information is requested from the xRuntime service. Its response has the following structure:
{
basemap : ["PTV Group", "HERE", "AND"],
featureLayers : [
{
themeId : "PTV_TruckAttributes",
copyright : ["HERE", "PTV Group"]
},
{
themeId : "PTV_TrafficIncidents",
copyright : ["TomTom", "PTV Group"]
},
...
]
}
You can now compile the list of applicable copyrights and set it as attribution of the TileLayer
.
Important: To fully comply with PTV's legal requirements a copyright sign and the current year have to be added as shown in this sample.
var map = new L.Map('map', { center: [49.61, 6.125], zoom: 13 });
// Determine the copyright with a request to xRuntime.
function determineCopyright() {
var urlPath = xServerUrl + '/services/rest/XRuntime/dataInformation';
$.ajax(urlPath).always(function(response){
if (response) {
addTileLayers(response.mapDescription.copyright);
}
});
};
determineCopyright();
// Add tile layers with the url pattern.
function addTileLayers(copyright) {
// for basemap + PTV_TrafficIncidents, combine the copyrights
var trafficAttributions = copyright.featureLayers.find( function(el){ return el.themeId === 'PTV_TrafficIncidents' }).copyright;
trafficAttributions = [].concat.apply( copyright.basemap, trafficAttributions );
trafficAttributions = trafficAttributions.filter( function(item, pos) { return trafficAttributions.indexOf(item) == pos });
// prepend copyright sign and current year
var copyrightSignAndYear = '© ' + new Date().getFullYear();
var baseMapAttribution = copyrightSignAndYear + ' ' + copyright.basemap.join(", ");
var trafficAttribution = copyrightSignAndYear + ' ' + trafficAttributions.join(", ");
var basemapUrl = xServerUrl + '/services/rest/XMap/tile/{z}/{x}/{y}';
var trafficIncidentsUrl = basemapUrl + '?storedProfile=silkysand&layers=labels,transport,background,PTV_TrafficIncidents';
var baselayers = {
// for a simple tile layer with the default map, only the basemap copyright is necessary.
'basemap': new L.TileLayer(basemapUrl, { minZoom: 1, maxZoom: 19, attribution: baseMapAttribution}).addTo(map),
'TrafficIncidents': new L.TileLayer(trafficIncidentsUrl, { minZoom: 3, maxZoom: 18, attribution: trafficAttribution, noWrap: true })
};
// add layers to control.layers to show the collection of available layers
L.control.layers(baselayers, null, { collapsed: false }).addTo(map);
}