Example of a localized OpenStreetMap map with a custom tile server and a custom attribution.
The base layer is OpenCycleMap with an overlay from OpenSeaMap. The OpenSeaMap tile server does not support CORS headers.
<!DOCTYPE html>
<html>
<head>
<title>Localized OpenStreetMap example</title>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.9.0/css/ol.css" type="text/css">
<script src="http://openlayers.org/en/v3.9.0/build/ol.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
</div>
<script>
// tiles.openseamap.org does not set CORS headers, so we have to disable
// crossOrigin and we cannot use WebGL.
var openCycleMapLayer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
new ol.Attribution({
html: 'All maps © ' +
'<a href="http://www.opencyclemap.org/">OpenCycleMap</a>'
}),
ol.source.OSM.ATTRIBUTION
],
url: 'http://{a-c}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png'
})
});
var openSeaMapLayer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
new ol.Attribution({
html: 'All maps © ' +
'<a href="http://www.openseamap.org/">OpenSeaMap</a>'
}),
ol.source.OSM.ATTRIBUTION
],
crossOrigin: null,
url: 'http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png'
})
});
var map = new ol.Map({
layers: [
openCycleMapLayer,
openSeaMapLayer
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}),
view: new ol.View({
maxZoom: 18,
center: [-244780.24508882355, 5986452.183179816],
zoom: 15
})
});
</script>
</body>
</html>