I am trying to get the information through a WMS stream for a single layer, but when I click on any point on the map my popup appears empty.

map.on('singleclick', function(evt) {
// Hide existing popup and reset it's offset
popup.setOffset([0, 0]);
// Attempt to find a marker from the planningAppsLayer
var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
    return feature;
if (feature) {
    var coord = feature.getGeometry().getCoordinates();
    var props = feature.getProperties();
    var info = "<h2><a href='" + props.caseurl + "'>" + props.casereference + "</a></h2>";
        info += "<p>" + props.locationtext + "</p>";
        info += "<p>Status: " + props.status + " " + props.statusdesc + "</p>";
    // Offset the popup so it points at the middle of the marker not the tip
    popup.setOffset([0, -22]);
    popup.show(coord, info);
} else {
    var url = districtLayer
                        'INFO_FORMAT': 'text/javascript',
                        'format_options': 'callback:parseResponse',
                        'propertyName': 'NAME,AREA_CODE,DESCRIPTIO'
         url: url,
         type: 'jsonp',
         jsonpCallbackName: 'parseResponse'
    }).then(function (data) {
        var feature = data.features[0];
        var props = feature.properties;
        var info = "<h2>" + props.NAME + "</h2><p>" + props.DESCRIPTIO + "</p>";
        popup.show(evt.coordinate, info);

How could I get information for a specific layer ?

  • 1
    What request is actually sent to the WMS server, if you try this in a web browser do you get any error? You request application/json, but is that format supported by the WMS (check the GetCapabilities response). – nmtoken Feb 8 '17 at 20:11
  • i change this part and i have now 'INFO_FORMAT': 'text/javascript', 'format_options': 'callback:parseResponse'/ – BORUSSEN11 Feb 9 '17 at 8:33
  • From what I know, you can not get attributes info from a WMS layer. You should use WFS instead. – juminet Feb 9 '17 at 11:25

To get information for a specific WMS layer, at a specific position, you have to create a URL string to request that information from the server. That's the purpose of a GetFeatureInfo request.



In your code, you have to create such URL on the click event. Then you fetch the URL and you handle the response. If you choose the application/json format, you can use that to create a nice popup, for example. If you choose text/html format, you already receive a HTML formated response.

I've prepared a OL3 GetFeatureInfo fiddle for you, that creates the proper GetFeatureInfo URL.

Open the developer tools in your browser and check the requests sent in the network tab. Change the INFO_FORMAT parameter to see the difference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.