0

Am doing a project using OpenLayers + Geoserver and am having four WFS layers that am using to display grids for each(schools,towns,hospitals).

I wanted to know whether its possible to display featureinfo popups for the WFS layers when clicked on map.

If so, how should I do it?

2

Unless your doing some fancy client side geometry editing or client side styling you should use WMS instead. GetFeatureInfo is a WMS request. If you use WMS you can make a custom template in Geoserver to return formatted HTML with your attributes:

http://docs.geoserver.org/latest/en/user/tutorials/GetFeatureInfo/index.html

The GetFeatureInfo HTML (if you use HTML templates) can easily be rendered to a popup dialog.

Not a popup, but shows the concept of GetFeatureInfo: http://openlayers.org/en/v3.2.0/examples/getfeatureinfo-tile.html

Some HTML to get you started:

    <div class="span12">
        <div id="map" class="map">
            <div id="popup" class="ol-popup">
                <a href="#" id="popup-closer" class="ol-popup-closer"></a>
                <div id="popup-content"></div>
            </div>
        </div>

    </div>
</div>

And Javascript:

var content = document.getElementById('popup-content');

map.on('singleclick', function(evt) {
  var viewResolution = /** @type {number} */ (view.getResolution());
  var url = pointWmsSource.getGetFeatureInfoUrl(
      evt.coordinate, viewResolution, 'EPSG:3857',
      {'INFO_FORMAT': 'text/html'});
  if (url) {
    var coordinate = evt.coordinate;
    overlay.setPosition(coordinate);

    content.innerHTML = '<iframe seamless id="infoiframe" src="' + url + '"></iframe>';
    container.style.display = 'block';
  }
});
  • Thank you Jakob for this.But, I am able to use the WMS GetInfofeature well and the popups are ok.Am not doing any editing of the data on client side.The issue is, I have thee grids that are reading data from three layers.The grids are used for searching e.g. Schools. When using WMS layers its not possible to create grid from the layers.right? That why am intending to use WFS but I need to know how to display info on popup for the three layers when selected on map.Hope you understand my issue – Wanjohi254 Mar 6 '15 at 13:37
  • Have you seen section 4.3.2 of girona-openlayers-workshop.readthedocs.org/en/latest/controls/… For accessing attributes on selected WFS geometries? – Jakob Mar 6 '15 at 13:50
  • Gone through it sometime and its very cool when having one WFS layer loaded.Am not sure whether its possible to loop through the three layers I have.Let me try out the loop and see what I will have..Thanks – Wanjohi254 Mar 6 '15 at 14:39

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.