]> ToastFreeware Gitweb - philipp/winterrodeln/mediawiki_extensions/wrmap.git/blobdiff - src/wrmap.ts
Work on adding South Tyrol/Bozen.
[philipp/winterrodeln/mediawiki_extensions/wrmap.git] / src / wrmap.ts
index 117b10269f5587e22bd1acd95cb849ef21c57625..f80ac19db3de1430cde830012bc0c33b27262895 100644 (file)
@@ -15,7 +15,7 @@ import { optionsFromCapabilities } from 'ol/source/WMTS';
 import OlSourceOsm from 'ol/source/OSM';
 import OlLayerVector from 'ol/layer/Vector';
 import OlLayerTile from 'ol/layer/Tile';
-import { Geometry, SimpleGeometry as OlSimpleGeometry } from 'ol/geom';
+import { Geometry, SimpleGeometry as OlSimpleGeometry, SimpleGeometry } from 'ol/geom';
 import OlPoint from 'ol/geom/Point';
 import OlInteractionDragPan from 'ol/interaction/DragPan';
 import OlInteractionMouseWheelZoom from 'ol/interaction/MouseWheelZoom';
@@ -288,6 +288,7 @@ function init_wrmap(_: number, jq_map_element: HTMLElement) {
                style: style_function
        });
 
+       let center = fromLonLat([lon, lat]);
        let map = new OlMap({
                target: jq_map[0],
                layers: [
@@ -295,7 +296,7 @@ function init_wrmap(_: number, jq_map_element: HTMLElement) {
                ],
                overlays: [popup_overlay],
                view: new OlView({
-                       center: fromLonLat([lon, lat]),
+                       center: center,
                        zoom: zoom
                }),
                controls: olControlDefaults({
@@ -365,19 +366,24 @@ function init_wrmap(_: number, jq_map_element: HTMLElement) {
                '8.941 46.027, 8.970 45.881, 8.867 46.107, 8.515 46.269, 8.440 46.489, 8.045 46.299, 8.062 46.176, 7.818 45.986, ' +
                '7.530 46.023, 7.136 45.928, 6.843 46.173, 6.792 46.454, 6.412 46.474, 6.186 46.362)))';
 
+       const bolzanoWkt = 'POLYGON ((10.452 46.680, 10.501 46.800, 11.012 46.725, 11.202 46.923, 11.743 46.926, ' +
+               '12.047 47.001, 12.072 46.884, 12.335 46.673, 12.058 46.706, 11.973 46.577, 11.654 46.548, 11.534 46.402, ' +
+               '11.232 46.285, 11.242 46.540, 10.650 46.499, 10.452 46.680))'
 
-       function getCountryFeature(countryWkt: string) {
+
+       function getCountryGeometry(countryWkt: string) {
                let format = new OlFormatWkt();
-               let feature = format.readFeature(countryWkt, {
+               let geometry = format.readGeometry(countryWkt, {
                        dataProjection: EPSG4326,
                        featureProjection: EPSG3857,
                });
-               return feature;
+               return geometry;
        }
 
 
-       const austria = getCountryFeature(austriaWkt);
-       const swiss = getCountryFeature(swissWkt);
+       const austria = getCountryGeometry(austriaWkt);
+       const swiss = getCountryGeometry(swissWkt);
+       const bolzano = getCountryGeometry(bolzanoWkt);
 
 
        function insertWmtsLayer(capabilitiesUrl: string, layer: string, attributions: string) {
@@ -411,22 +417,44 @@ function init_wrmap(_: number, jq_map_element: HTMLElement) {
        }
 
 
-       function allFeaturesInCountry(features: Feature<Geometry>[], country: OlFeatureLike): boolean {
-               let countryGeometry = country.getGeometry() as Geometry;
-               function isInCountry(feature: OlFeatureLike) {
-                       let featureGeometry = feature.getGeometry() as OlSimpleGeometry;
-                       return countryGeometry.intersectsCoordinate(featureGeometry.getFirstCoordinate());
-               }
-               return features.every(isInCountry);
+       function allFeaturesInCountry(features: Feature<Geometry>[], country: Geometry): boolean {
+               return features.every(function (feature: Feature<Geometry>) {return country.intersectsCoordinate((feature.getGeometry() as SimpleGeometry).getFirstCoordinate())});
+       }
+
+       enum BackgroundLayer {
+               BasemapAt,
+               VaoAusland,
+               Sosm,
+               Bolzano,
        }
 
+       let backgroundLayer = BackgroundLayer.BasemapAt;
 
        if (allFeaturesInCountry(features_all, austria)) {
-               insertWmtsLayer('https://mapsneu.wien.gv.at/basemapneu/1.0.0/WMTSCapabilities.xml', 'bmapgrau', 'Grundkarte: <a href="https://www.basemap.at/">basemap.at</a>');
+               backgroundLayer = BackgroundLayer.BasemapAt;
        } else if (allFeaturesInCountry(features_all, swiss)) {
-               insertSwissLayer();
+               backgroundLayer = BackgroundLayer.Sosm;
+       } else if (allFeaturesInCountry(features_all, bolzano)) {
+               backgroundLayer = BackgroundLayer.Bolzano;
+       } else if (swiss.intersectsCoordinate(center)) {
+               backgroundLayer = BackgroundLayer.Sosm;
        } else {
-               insertWmtsLayer('https://mapsneu.wien.gv.at/vaoneu/1.0.0/WMTSCapabilities.xml', 'vaoausland', 'Grundkarte: <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>');
+               backgroundLayer = BackgroundLayer.VaoAusland;
+       }
+
+       switch (backgroundLayer) {
+               case BackgroundLayer.BasemapAt:
+                       insertWmtsLayer('https://mapsneu.wien.gv.at/basemapneu/1.0.0/WMTSCapabilities.xml', 'bmapgrau', 'Grundkarte: <a href="https://www.basemap.at/">basemap.at</a>');
+                       break;
+               case BackgroundLayer.VaoAusland:
+                       insertWmtsLayer('https://mapsneu.wien.gv.at/vaoneu/1.0.0/WMTSCapabilities.xml', 'vaoausland', 'Grundkarte: <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>');
+                       break;
+               case BackgroundLayer.Sosm:
+                       insertSwissLayer();
+                       break;
+               case BackgroundLayer.Bolzano:
+                       insertWmtsLayer('https://geoservices.buergernetz.bz.it/mapproxy/service?REQUEST=GetCapabilities&SERVICE=WMTS', 'oown-OpenStreetMap:Terrain', 'Grundkarte: <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>');
+                       break;
        }