mercredi 30 septembre 2015

Zoom to layer extent in Openlayers 3

I have a drop down list of application numbers and when the user clicks on one of these, I would like my application to display that feature on the map from my application layer and then zoom to its extent.

The feature is displaying correctly but I cannot seem to be able to zoom to the extent of the layer, I receive an error:

Uncaught TypeError: Cannot read property '0' of undefined

The relevant code is below which is within an if statement, there appears to be some sort of issue with the last 2 lines - is it because I am unable to call methods to the map layer as it was created at the same time? Do I need to delay the zoom to extent somehow?

if (name === "planning") {
      var planapp = new ol.layer.Tile({
      source: new ol.source.TileWMS({url: '../../geoserver/wms',
      serverType: 'geoserver',
      params:{
        'LAYERS':"planning:planapps_testlayer", 'TILED':true, 'cql_filter':"applicatio='" + datum.APPLICATION_NUMBER + "'"
      }
      }),
      name: 'planapp',
      label: 'Planning Applications',
      visible: true
      });
    map.addLayer(planapp);
    var selectedAppExtent = planapp.getExtent();
    map.getView().fit(selectedAppExtent, map.getSize());
  }

Thanks for any help you can give!

Aucun commentaire:

Enregistrer un commentaire