0

I have a point dataset in an Openlayers 3 map. The aim is to be able to click each point and get the information about that point displayed. The code below works just fine, it loads all the layers up and when I click a point, it retrieves some information. However it will only return information for one point, no matter where I click on the map. Can anyone see where I have gone wrong here?

var layers = [
  new ol.layer.Tile({
    source: new ol.source.MapQuest({layer: 'sat'})
  }),

  new ol.layer.Image({
    extent: [16935988.2390421, -3393028.96482803, 17102996.5023459, -3207079.63356002],
    source: new ol.source.ImageWMS({
      url: 'http://geonct.com:80/geoserver/NCTPROP/wms',
      params: {'LAYERS': 'NCTPROP:corr'},
      serverType: 'geoserver'
    })
  }),
  new ol.layer.Image({
    extent: [16935988.2390421, -3393028.96482803, 17102996.5023459, -3207079.63356002],
    source: new ol.source.ImageWMS({
      url: 'http://geonct.com:80/geoserver/NCTPROP/wms',
      params: {'LAYERS': 'NCTPROP:br_web'},
      serverType: 'geoserver'
    })
  }),
  new ol.layer.Tile({
      source: new ol.source.TileWMS({
          url: 'http://geonct.com:80/geoserver/NCTPROP/wms',
          params: {'LAYERS': 'NCTPROP:br_point'},
          serverType: 'geoserver'
        })
  })

];
function loadMap(){

var map = new ol.Map({
  layers: layers,
  target: 'map',
  view: new ol.View({
    center: [17031695, -3310901],
    zoom: 9
  })
});
var view = new ol.View({
  center: [0, 0],
  zoom: 1
});
map.on('singleclick', function(evt) {
  document.getElementById('info').innerHTML = '';
  var viewResolution = /** @type {number} */ (view.getResolution());
  var url = layers[3].getSource().getGetFeatureInfoUrl(
      evt.coordinate, viewResolution, 'EPSG:3857',
      {'INFO_FORMAT': 'text/html'});
  if (url) {
    document.getElementById('info').innerHTML =
        '<iframe seamless src="' + url + '"></iframe>';
  }
});
};
function layerSwap(evt){
   layers[evt.value].setVisible(evt.checked);
}
2
  • Feature_count defaults to one. Add parameter and use value of 10 or what you need.
    – user30184
    Sep 18, 2014 at 22:03
  • Almost there! Do i wanted it so that if I click on a point, it returns the attributes of that point, do I need to specify a bounding box parameter around the point?
    – user25074
    Sep 19, 2014 at 3:05

1 Answer 1

4

You need to specify WMS params in getGetFeatureInfoUrl() function.
In your case, try to ask for more features by adding the param FEATURE_COUNT after INFO_FORMAT.

For instance:

var url = layers[3].getSource().getGetFeatureInfoUrl(
  evt.coordinate,
  viewResolution,
  'EPSG:3857',
  {
     'INFO_FORMAT': 'text/html',
     'FEATURE_COUNT': '20' //or whatever you want
  }
);

Good luck

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.