0

I've created a SQL layer, I'm passing the values for that query from client, I want my map to be able to zoom to whatever the layer that comes after query. I tried GetCapabilities, but it zooms to the extent of whole layer, which is not quite helpful.

I've many layers on GeoServer which, when I click on checkbox, displayed on the map.

This is what I'm using now in my program

var url = 'http://localhost:8080/geoserver/wms?;
request=GetCapabilities&service=WMS&version=1.1.0';
var parser = new ol.format.WMSCapabilities();

$.ajax(url).then(function(response) 
{
    var result = parser.read(response);

    var Layers = result.Capability.Layer.Layer; 
    for(var i=0; i<Layers.length;i++){
     var layerobj = Layers[i];

      if (layerobj.Name == 'SPA:'+value.id) {

              var ex = layerobj.BoundingBox[0].extent;
              //ext = map.getView().calculateExtent(map.getSize());

              var X = ex  [0] + (ex  [2]-ex  [0])/2;
              var Y = ex  [1] + (ex  [3]-ex  [1])/2;
      }
    }
    map.getView().setCenter([X,Y])
    map.getView().setZoom(19);

Using this code, I'm able to set zoom level and center of map according to complete layer, but that is not what I want, I want to set zoom level and center according to the features that I get after query.

  • 1
    GetCapabilities, is a request to the service for further details about the service, and nothing to do with fetching any content to the client. A WMS doesn't provide features, just (mainly) image representations of features. – nmtoken Mar 12 at 7:01
  • I just want to get zoomed to the features that are on map (after query). I'm not concerned of its WMS or WFS. How can I do it – krishna lodha Mar 12 at 7:09
  • 2
    Could you edit the question to add more details, especially on what you have tried in code. The how to do it as a WMS and GetMap operation vs. how to do it as a WFS (GetFeature) will be different questions I feel. Also which version of OpenLayers are you using? – nmtoken Mar 12 at 7:22
  • I think there might be some misconceptions about layers. There is no SQL-Layer, the thing you request the capabilities from is a WMS, which, as as others have noted, only gives you images without information about features. – Rob Mar 13 at 13:08
  • @Rob but If I publish it as WFS, will I be able to apply the style to it when it displays on screen? – krishna lodha Mar 13 at 16:13

Your Answer

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

Browse other questions tagged or ask your own question.