Files
openlayers/examples/getfeatureinfo-layers.js
Frederic Junod 79c8afdba8 Simplify import path in examples
To have the same path (starting with `ol/`, without `.js`) as in the documentation.
The support was added in the webpack config in #8928
2018-11-26 17:18:52 +01:00

24 lines
892 B
JavaScript

import WMSGetFeatureInfo from 'ol/format/WMSGetFeatureInfo';
fetch('data/wmsgetfeatureinfo/osm-restaurant-hotel.xml').then(function(response) {
return response.text();
}).then(function(response) {
// this is the standard way to read the features
const allFeatures = new WMSGetFeatureInfo().readFeatures(response);
document.getElementById('all').innerText = allFeatures.length.toString();
// when specifying the 'layers' options, only the features of those
// layers are returned by the format
const hotelFeatures = new WMSGetFeatureInfo({
layers: ['hotel']
}).readFeatures(response);
document.getElementById('hotel').innerText = hotelFeatures.length.toString();
const restaurantFeatures = new WMSGetFeatureInfo({
layers: ['restaurant']
}).readFeatures(response);
document.getElementById('restaurant').innerText = restaurantFeatures.length.toString();
});