In OL2 I think that it was done by using something like this:

the_control = new OpenLayers.Control.GetFeature({
   protocol: OpenLayers.Protocol.WFS.fromWMSLayer(mymap, {
      geometryName: 'geom',
      featureType: 'feature'
   box: false,
   hover: false

which sent XML request to mapserver which returned GML response with the geometry.

What is the alternative in OL3? I just want to 'highlight' the the feature on WMS layer. How to setup the select interaction with the WMS layer OL3, send information to mapserver and highlight the feature according to the response? And how to configure layer in mymap.map file?

I get response from mapserver like this:

<?xml version="1.0" encoding="UTF-8"?>

    <gml:name>TODO 3 (WMS)</gml:name>
                <gml:Box srsName="EPSG:102067">
                    <gml:coordinates>-687941.344000,-1099495.708000 -678154.701000,-1093996.637000</gml:coordinates>


The style is set up like this:

new ol.style.Style({
  stroke: new ol.style.Stroke({
     color: '#007FFF',
     width: 5
  • Trying to do the same with ol3 + GeoServer. No luck so far. Do Geoserver layers require any configuration as well?
    – user50142
    Commented Apr 7, 2015 at 13:49

1 Answer 1


The easiest way to achieve the same in OpenLayers 3 is to use WMS GetFeatureInfo. Your code could look something like this (assuming mymap is your layer with a WMS source, and map is your ol.Map instance):

var parser = new ol.format.WMSGetFeatureInfo();
var highlightOverlay = new ol.Layer.Vector({
  // style: (customize your highlight style here),
  source: new ol.source.Vector(),
  map: map
map.on('singleclick', function(evt) {
  var view = map.getView();
  var url = mymap.getSource().getFeatureInfoUrl(evt.coordinate,
      view.getResolution(), view.getProjection(),
      {'INFO_FORMAT': 'application/vnd.ogc.gml'});
  $.ajax(url).then(function(response) {
    var features = parser.readFeatures(response);

In your MapServer mapfile, you will have to set the layer TEMPLATE parameter for the layer to be queryable by GetFeatureInfo requests. You also need to configure some METADATA to include geometries in the response:

    "gml_geometries" "mygeom"
    "gml_mygeom_type" "line"

The above assumes that your layer is a line layer, and that the geometry column in your data is 'mygeom'.

  • After your answer there was a progress (see the update of question), but no highlight on the map.. nothing happens after a click
    – khamyl
    Commented Mar 25, 2015 at 12:37
  • Your GetFeatureInfo response does not contain geometries. I edited my answer to show you how to configure your LAYER in the mapfile to include geometries.
    – ahocevar
    Commented Mar 25, 2015 at 13:25
  • Getting closer.. now I have this in my getFeatureResponse: <!-- Warning: Cannot write geometry- no line/multiline geometry defined. -->
    – khamyl
    Commented Mar 25, 2015 at 15:09
  • Ok problem solved.. this was because the Layer TYpe was set to TYPE LINE and the geometry type was POINT.. many thanks for help!!!
    – khamyl
    Commented Mar 25, 2015 at 15:20
  • Glad I could help. I changed the layer and geometry type in my answer to LINE so future readers don't run into the same problem.
    – ahocevar
    Commented Mar 25, 2015 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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