goog.require('ol.Attribution');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.control');
goog.require('ol.control.ScaleLine');
goog.require('ol.layer.Tile');
goog.require('ol.proj');
goog.require('ol.proj.Projection');
goog.require('ol.source.TileWMS');
var projection = new ol.proj.Projection({
code: 'EPSG:21781',
// The extent is used to determine zoom level 0. Recommended values for a
// projection's validity extent can be found at http://epsg.io/.
extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864],
units: 'm'
});
ol.proj.addProjection(projection);
// WGStoCHx, WGStoCHy, CHtoWGSlng and CHtoWGSlat are defined in a script block
// in the html.
ol.proj.addCoordinateTransforms('EPSG:4326', projection,
function(coordinate) {
return [
WGStoCHy(coordinate[1], coordinate[0]),
WGStoCHx(coordinate[1], coordinate[0])
];
},
function(coordinate) {
return [
CHtoWGSlng(coordinate[0], coordinate[1]),
CHtoWGSlat(coordinate[0], coordinate[1])
];
});
var extent = [420000, 30000, 900000, 350000];
var layers = [
new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'http://wms.geo.admin.ch/',
crossOrigin: 'anonymous',
attributions: [new ol.Attribution({
html: '© ' +
'' +
'Pixelmap 1:1000000 / geo.admin.ch'
})],
params: {
'LAYERS': 'ch.swisstopo.pixelkarte-farbe-pk1000.noscale',
'FORMAT': 'image/jpeg'
},
extent: extent,
serverType: 'mapserver'
})
}),
new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'http://wms.geo.admin.ch/',
crossOrigin: 'anonymous',
attributions: [new ol.Attribution({
html: '© ' +
'' +
'National parks / geo.admin.ch'
})],
params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'},
extent: extent,
serverType: 'mapserver'
})
})
];
var map = new ol.Map({
controls: ol.control.defaults().extend([
new ol.control.ScaleLine({
units: 'metric'
})
]),
layers: layers,
renderer: exampleNS.getRendererFromQueryString(),
target: 'map',
view: new ol.View({
projection: projection,
center: ol.proj.transform([8.23, 46.86], 'EPSG:4326', 'EPSG:21781'),
extent: extent,
zoom: 2
})
});