1 | goog.require('ol.Map');
|
2 | goog.require('ol.View');
|
3 | goog.require('ol.control');
|
4 | goog.require('ol.control.ScaleLine');
|
5 | goog.require('ol.layer.Tile');
|
6 | goog.require('ol.proj');
|
7 | goog.require('ol.proj.Projection');
|
8 | goog.require('ol.source.TileWMS');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | var projection = new ol.proj.Projection({
|
17 | code: 'EPSG:21781',
|
18 |
|
19 |
|
20 | extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864],
|
21 | units: 'm'
|
22 | });
|
23 | ol.proj.addProjection(projection);
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | ol.proj.addCoordinateTransforms('EPSG:4326', projection,
|
30 | function(coordinate) {
|
31 | return [
|
32 | WGStoCHy(coordinate[1], coordinate[0]),
|
33 | WGStoCHx(coordinate[1], coordinate[0])
|
34 | ];
|
35 | },
|
36 | function(coordinate) {
|
37 | return [
|
38 | CHtoWGSlng(coordinate[0], coordinate[1]),
|
39 | CHtoWGSlat(coordinate[0], coordinate[1])
|
40 | ];
|
41 | });
|
42 |
|
43 | var extent = [420000, 30000, 900000, 350000];
|
44 | var layers = [
|
45 | new ol.layer.Tile({
|
46 | extent: extent,
|
47 | source: new ol.source.TileWMS({
|
48 | url: 'https://wms.geo.admin.ch/',
|
49 | crossOrigin: 'anonymous',
|
50 | attributions: '© <a href="http://www.geo.admin.ch/internet/geoportal/' +
|
51 | 'en/home.html">Pixelmap 1:1000000 / geo.admin.ch</a>',
|
52 | params: {
|
53 | 'LAYERS': 'ch.swisstopo.pixelkarte-farbe-pk1000.noscale',
|
54 | 'FORMAT': 'image/jpeg'
|
55 | },
|
56 | serverType: 'mapserver'
|
57 | })
|
58 | }),
|
59 | new ol.layer.Tile({
|
60 | extent: extent,
|
61 | source: new ol.source.TileWMS({
|
62 | url: 'https://wms.geo.admin.ch/',
|
63 | crossOrigin: 'anonymous',
|
64 | attributions: '© <a href="http://www.geo.admin.ch/internet/geoportal/' +
|
65 | 'en/home.html">National parks / geo.admin.ch</a>',
|
66 | params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'},
|
67 | serverType: 'mapserver'
|
68 | })
|
69 | })
|
70 | ];
|
71 |
|
72 | var map = new ol.Map({
|
73 | controls: ol.control.defaults().extend([
|
74 | new ol.control.ScaleLine({
|
75 | units: 'metric'
|
76 | })
|
77 | ]),
|
78 | layers: layers,
|
79 | target: 'map',
|
80 | view: new ol.View({
|
81 | projection: projection,
|
82 | center: ol.proj.transform([8.23, 46.86], 'EPSG:4326', 'EPSG:21781'),
|
83 | extent: extent,
|
84 | zoom: 2
|
85 | })
|
86 | });
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | function WGStoCHy(lat, lng) {
|
96 |
|
97 |
|
98 | lat = DECtoSEX(lat);
|
99 | lng = DECtoSEX(lng);
|
100 |
|
101 |
|
102 | lat = DEGtoSEC(lat);
|
103 | lng = DEGtoSEC(lng);
|
104 |
|
105 |
|
106 | var lat_aux = (lat - 169028.66) / 10000;
|
107 | var lng_aux = (lng - 26782.5) / 10000;
|
108 |
|
109 |
|
110 | var y = 600072.37 +
|
111 | 211455.93 * lng_aux -
|
112 | 10938.51 * lng_aux * lat_aux -
|
113 | 0.36 * lng_aux * Math.pow(lat_aux, 2) -
|
114 | 44.54 * Math.pow(lng_aux, 3);
|
115 |
|
116 | return y;
|
117 | }
|
118 |
|
119 |
|
120 | function WGStoCHx(lat, lng) {
|
121 |
|
122 |
|
123 | lat = DECtoSEX(lat);
|
124 | lng = DECtoSEX(lng);
|
125 |
|
126 |
|
127 | lat = DEGtoSEC(lat);
|
128 | lng = DEGtoSEC(lng);
|
129 |
|
130 |
|
131 | var lat_aux = (lat - 169028.66) / 10000;
|
132 | var lng_aux = (lng - 26782.5) / 10000;
|
133 |
|
134 |
|
135 | var x = 200147.07 +
|
136 | 308807.95 * lat_aux +
|
137 | 3745.25 * Math.pow(lng_aux, 2) +
|
138 | 76.63 * Math.pow(lat_aux, 2) -
|
139 | 194.56 * Math.pow(lng_aux, 2) * lat_aux +
|
140 | 119.79 * Math.pow(lat_aux, 3);
|
141 |
|
142 | return x;
|
143 |
|
144 | }
|
145 |
|
146 |
|
147 |
|
148 | function CHtoWGSlat(y, x) {
|
149 |
|
150 |
|
151 |
|
152 | var y_aux = (y - 600000) / 1000000;
|
153 | var x_aux = (x - 200000) / 1000000;
|
154 |
|
155 |
|
156 | var lat = 16.9023892 +
|
157 | 3.238272 * x_aux -
|
158 | 0.270978 * Math.pow(y_aux, 2) -
|
159 | 0.002528 * Math.pow(x_aux, 2) -
|
160 | 0.0447 * Math.pow(y_aux, 2) * x_aux -
|
161 | 0.0140 * Math.pow(x_aux, 3);
|
162 |
|
163 |
|
164 | lat = lat * 100 / 36;
|
165 |
|
166 | return lat;
|
167 |
|
168 | }
|
169 |
|
170 |
|
171 | function CHtoWGSlng(y, x) {
|
172 |
|
173 |
|
174 |
|
175 | var y_aux = (y - 600000) / 1000000;
|
176 | var x_aux = (x - 200000) / 1000000;
|
177 |
|
178 |
|
179 | var lng = 2.6779094 +
|
180 | 4.728982 * y_aux +
|
181 | 0.791484 * y_aux * x_aux +
|
182 | 0.1306 * y_aux * Math.pow(x_aux, 2) -
|
183 | 0.0436 * Math.pow(y_aux, 3);
|
184 |
|
185 |
|
186 | lng = lng * 100 / 36;
|
187 |
|
188 | return lng;
|
189 |
|
190 | }
|
191 |
|
192 |
|
193 |
|
194 | function DECtoSEX(angle) {
|
195 |
|
196 |
|
197 | var deg = parseInt(angle, 10);
|
198 | var min = parseInt((angle - deg) * 60, 10);
|
199 | var sec = (((angle - deg) * 60) - min) * 60;
|
200 |
|
201 |
|
202 | return deg + min / 100 + sec / 10000;
|
203 |
|
204 | }
|
205 |
|
206 |
|
207 | function DEGtoSEC(angle) {
|
208 |
|
209 |
|
210 | var deg = parseInt(angle, 10);
|
211 | var min = parseInt((angle - deg) * 100, 10);
|
212 | var sec = (((angle - deg) * 100) - min) * 100;
|
213 |
|
214 |
|
215 | var parts = String(angle).split('.');
|
216 | if (parts.length == 2 && parts[1].length == 2) {
|
217 | min = Number(parts[1]);
|
218 | sec = 0;
|
219 | }
|
220 |
|
221 |
|
222 | return sec + min * 60 + deg * 3600;
|
223 |
|
224 | }
|