-
-
Save ThomasG77/7be91afe37fd07d42c7f94116a95b536 to your computer and use it in GitHub Desktop.
Solution to https://gis.stackexchange.com/questions/285900/openlayers-wfs-projection-not-showing-epsg25832
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Simple Map</title> | |
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css"> | |
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --> | |
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script> | |
<script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.4.4/proj4.js"></script> | |
</head> | |
<body> | |
<div id="map" class="map"></div> | |
<script> | |
let myProjectionName = 'EPSG:25832'; | |
proj4.defs(myProjectionName, '+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs'); | |
var myProjection = ol.proj.get(myProjectionName); | |
myProjection.setExtent([239323.44497533192, 4294418.796805557, 760676.5550246682, 9320086.206906328]); | |
var mapView = new ol.View({ | |
center: ol.proj.transform([9.98, 53.55], 'EPSG:4326', 'EPSG:25832'), | |
zoom: 9, | |
projection: 'EPSG:25832' | |
}); | |
var vectorLayer = new ol.source.Vector({ | |
format: new ol.format.WFS(), | |
url: function(extent) { | |
return 'https://cors-anywhere.herokuapp.com/https://geodienste.hamburg.de/HH_WFS_Statistik_Stadtteile_Wahlergebnisse' + | |
'?version=1.1.0&request=GetFeature&typename=Statistik_Stadtteile_Wahlergebnisse:Buergerschaftswahl_15.02.2015_-_Wahlbeteiligung_in_Prozent' + | |
'&bbox' + extent.join(',') + ',EPSG:25832'; | |
}, | |
strategy: ol.loadingstrategy.bbox | |
}); | |
let map = new ol.Map({ | |
target: 'map', | |
layers: [ | |
new ol.layer.Tile({ | |
source: new ol.source.OSM(), | |
projection: 'EPSG:25832' | |
}), | |
new ol.layer.Vector({ | |
source: vectorLayer, | |
projection: 'EPSG:25832' | |
}) | |
], | |
view: this.mapView | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment