Sunday 28 July 2019

wms - How to get getGetFeatureInfoUrl from multiple layers in OpenLayers 3


I have multiple layers in a map with layer group now onclick I want to get the getGetFeatureInfoUrl for the different layers on which I am clicking but the problem is that I am getting only the Info for the last layer appended not the others.


Here is my code:



 var wms_layer;
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Group({
'title': 'Base maps',
layers: [
new ol.layer.Tile({
title: 'Water color',
type: 'base',

visible: false,
source: new ol.source.Stamen({
layer: 'watercolor'
})
}),
new ol.layer.Tile({
title: 'OSM',
type: 'base',
visible: true,
source: new ol.source.OSM({

attributions: [
'All maps © OpenCycleMap',
ol.source.OSM.ATTRIBUTION
],
url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png'
})
})
]
}),
new ol.layer.Group({

title: 'Hisar Data Layers',
layers: [
new ol.layer.Tile({
title: 'Habitations',
source: new ol.source.TileWMS({
url: 'http://192.168.2.2:8080/geoserver/HissarFullData/wms?service',
params: {
'LAYERS': 'HissarFullData:habitations',
'VERSION': '1.1.0',
'FORMAT': 'image/png',

},
serverType: 'geoserver'
})
}),
wms_layer = new ol.layer.Tile({
title: 'Hisar PWD',
source: new ol.source.TileWMS({
url: 'http://192.168.2.2:8080/geoserver/HissarFullData/wms?service',
params: {
'LAYERS': 'HissarFullData:pwd',

'VERSION': '1.1.0',
'FORMAT': 'image/png',
},
serverType: 'geoserver'
})
}),
new ol.layer.Tile({
title: 'Hisar Block',
source: new ol.source.TileWMS({
url: 'http://192.168.2.2:8080/geoserver/HissarFullData/wms?service',

params: {
'LAYERS': 'HissarFullData:block_boundary',
'VERSION': '1.1.0',
'FORMAT': 'image/png',
},
serverType: 'geoserver'
})
})
]
})

],
view: new ol.View({
center: ol.proj.transform([75.7217, 29.1492], 'EPSG:4326', 'EPSG:3857'),
zoom: 10,
minZoom: 5,
maxZoom: 17
})
});
var layerSwitcher = new ol.control.LayerSwitcher({
tipLabel: 'Layers' // Optional label for button

});
map.addControl(layerSwitcher);
var viewProjection = map.getView().getProjection();
var viewResolution = map.getView().getResolution();
map.on('click', function (evt) {
var url = wms_layer.getSource().getGetFeatureInfoUrl(
evt.coordinate, viewResolution, viewProjection,
{
'INFO_FORMAT': 'text/html',
});

if (url) {
document.getElementById('info').innerHTML =
'';
$('#myModal').modal('show');
}
});

Whenever I click on the map I always getting info of the HissarFullData:block_boundary layer. I am using Layer switcher with this .




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...