UNPKG

2.29 kBJavaScriptView Raw
1goog.require('ol.Map');
2goog.require('ol.View');
3goog.require('ol.control');
4goog.require('ol.control.ScaleLine');
5goog.require('ol.layer.Image');
6goog.require('ol.proj');
7goog.require('ol.proj.Projection');
8goog.require('ol.source.ImageWMS');
9
10
11// Transparent Proj4js support:
12//
13// EPSG:21781 is known to Proj4js because its definition was loaded in the html.
14// Now when we create an ol.proj.Projection instance with the 'EPSG:21781' code,
15// OpenLayers will pick up parameters like units and transform functions from
16// Proj4js.
17//
18// Note that we are setting the projection's extent here, which is used to
19// determine the view resolution for zoom level 0. Recommended values for a
20// projection's validity extent can be found at https://epsg.io/.
21//
22// If you use Proj4js only to transform coordinates, you don't even need to
23// create an ol.proj.Projection instance. ol.proj.get() will take care of it
24// internally.
25
26var projection = new ol.proj.Projection({
27 code: 'EPSG:21781',
28 extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864]
29});
30
31var extent = [420000, 30000, 900000, 350000];
32var layers = [
33 new ol.layer.Image({
34 extent: extent,
35 source: new ol.source.ImageWMS({
36 url: 'https://wms.geo.admin.ch/',
37 crossOrigin: 'anonymous',
38 attributions: '© <a href="http://www.geo.admin.ch/internet/geoportal/' +
39 'en/home.html">Pixelmap 1:1000000 / geo.admin.ch</a>',
40 params: {
41 'LAYERS': 'ch.swisstopo.pixelkarte-farbe-pk1000.noscale',
42 'FORMAT': 'image/jpeg'
43 },
44 serverType: 'mapserver'
45 })
46 }),
47 new ol.layer.Image({
48 extent: extent,
49 source: new ol.source.ImageWMS({
50 url: 'https://wms.geo.admin.ch/',
51 crossOrigin: 'anonymous',
52 attributions: '© <a href="http://www.geo.admin.ch/internet/geoportal/' +
53 'en/home.html">National parks / geo.admin.ch</a>',
54 params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'},
55 serverType: 'mapserver'
56 })
57 })
58];
59
60var map = new ol.Map({
61 controls: ol.control.defaults().extend([
62 new ol.control.ScaleLine()
63 ]),
64 layers: layers,
65 target: 'map',
66 view: new ol.View({
67 projection: projection,
68 center: ol.proj.fromLonLat([8.23, 46.86], projection),
69 extent: extent,
70 zoom: 2
71 })
72});