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';
style: style_function
});
+ let center = fromLonLat([lon, lat]);
let map = new OlMap({
target: jq_map[0],
layers: [
],
overlays: [popup_overlay],
view: new OlView({
- center: fromLonLat([lon, lat]),
+ center: center,
zoom: zoom
}),
controls: olControlDefaults({
'7.530 46.023, 7.136 45.928, 6.843 46.173, 6.792 46.454, 6.412 46.474, 6.186 46.362)))';
- 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);
function insertWmtsLayer(capabilitiesUrl: string, layer: string, attributions: string) {
}
- 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,
}
+ 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 (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;
}