-
-
Save ThomasG77/840d89e3cdcc3519ac5b65e6872c2cc4 to your computer and use it in GitHub Desktop.
Demo for https://gis.stackexchange.com/questions/285232/openlayers-4-wfs-vector-select with EPSG 27700 for map
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>Box Selection</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="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.14/proj4.js"></script> | |
<script src="http://epsg.io/27700.js"></script> | |
<script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script> | |
</head> | |
<body> | |
<div id="map" class="map"></div> | |
<script> | |
var extent = ol.proj.transformExtent([-8.74, 49.81, 1.84, 60.9], 'EPSG:4326', 'EPSG:27700'); | |
var projection = ol.proj.get('EPSG:27700'); | |
projection.setExtent(extent); | |
var vectorSource = new ol.source.Vector({ | |
format: new ol.format.WFS(), | |
url: function(extent) { | |
// Possible to remove https://cors-anywhere.herokuapp.com/ | |
// Added to manage CORS issue as I don't own the server | |
return 'https://cors-anywhere.herokuapp.com/http://www.trafficorders.uk/cgi-bin/mapserv?map=/var/www/vhosts/trafficorders.uk/httpdocs/maps/wfsareas.map&service=WFS&' + | |
'version=1.1.0&request=GetFeature&typename=la_areas&' + | |
'outputFormat=text/xml; subtype=gml/3.1.1&srsname=EPSG:27700'; | |
}, | |
strategy: ol.loadingstrategy.all | |
}); | |
var map = new ol.Map({ | |
layers: [ | |
new ol.layer.Tile({ | |
source: new ol.source.OSM(), | |
projection: 'EPSG:27700' | |
}), | |
new ol.layer.Vector({ | |
source: vectorSource | |
}) | |
], | |
target: 'map', | |
view: new ol.View({ | |
projection: 'EPSG:27700', | |
center: ol.proj.fromLonLat([-2.78624, 54.90409], projection), | |
zoom: 1 | |
}) | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment