Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active Jul 1, 2018
Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name=description content="">
<meta name=viewport content="width=device-width, initial-scale=1">
<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-debug.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
var vectorSource = new ol.source.Vector({
url: 'wfs.xml',
format: new ol.format.WFS(),
loader: function(extent, resolution, projection) {
var url = 'wfs.xml';
fetch(url)
.then(response => response.text())
.then(text => {
vectorSource.addFeatures(
vectorSource.getFormat().readFeatures(text, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
})
);
})
}
})
var vector = new ol.layer.Vector({
source: vectorSource
});
map.addLayer(vector);
vectorSource.on('change', e => {
if (vectorSource.getState() === 'ready') {
map.getView().fit(vectorSource.getExtent());
}
})
</script>
</body>
</html>
<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:gml="http://www.opengis.net/gml"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mapserver.gis.umn.edu/mapserver http://localhost/MapServer/mapserv.exe?map=c:/inetpub/wwwroot/data//Region_Map_01392779-38eb-4685-a94c-d738038843a6.map&amp;SERVICE=WFS&amp;VERSION=1.1.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=Name&amp;OUTPUTFORMAT=text/xml;%20subtype=gml/3.1.1 http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:4326">
<gml:lowerCorner>8.428503 77.171508</gml:lowerCorner>
<gml:upperCorner>9.201230 77.398780</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<ms:Region_Map gml:id="Name.Layer.fid1">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:4326">
<gml:lowerCorner>8.428503 77.353326</gml:lowerCorner>
<gml:upperCorner>8.473957 77.398780</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<ms:msGeometry>
<gml:Polygon srsName="EPSG:4326">
<gml:exterior>
<gml:LinearRing>
<gml:posList srsDimension="2">8.428503 77.398780 8.428503 77.353326 8.473957 77.353326 8.473957 77.398780 8.428503 77.398780 </gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</ms:msGeometry>
<!--other content-->
</ms:Region_Map>
</gml:featureMember>
<gml:featureMember>
<ms:Region_Map gml:id="Name.Layer.fid2">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:4326">
<gml:lowerCorner>8.503612012048896 77.15217590332031</gml:lowerCorner>
<gml:upperCorner>8.591205465526205 77.24967956542967</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<ms:msGeometry>
<gml:Polygon srsName="EPSG:4326">
<gml:exterior>
<gml:LinearRing>
<gml:posList srsDimension="2">8.503612012048896 77.15217590332031 8.503612012048896 77.24967956542967 8.591205465526205 77.24967956542967 8.591205465526205 77.15217590332031 8.503612012048896 77.15217590332031 </gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</ms:msGeometry>
<!-- other data-->
</ms:Region_Map>
</gml:featureMember>
<!--Other such tags-->
</wfs:FeatureCollection>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment