0

I have WMS map, after applying CQL filter to layer how can I zoom map to see filter result?

UPDATE:

Here is my code what I'm trying to do

var layerArray = map.layers;
var someLayer;

for (var i = 0; i < layerArray.length; i++) {
    if (layerArray[i].name == "myLayer"){
        someLayer = layerArray[i];
        break;
        }
}

someLayer.mergeNewParams({
    "CQL_FILTER": celIDCondition /* (CID =1351 and LAC = 401) */
});

// instead of somelayer.maxExtend I want to extent map acording to CQL_FILTER result
map.zoomToExtent(someLayer.maxExtent);
1
  • it seems that you need to expand this question to give us a better idea about what you are trying to do. Maybe you could post the code you are using so far?
    – Ian Turton
    May 18 '12 at 7:27
1

you can try:

var dataExtent = vectors.getDataExtent();
map.zoomToExtent(dataExtent);

or

map.zoomToExtent(vectors.getDataExtent());

.

vectors is the layer which you add features from CQL_Filter.

you can try it here with firebug writing this to console:

map.zoomToExtent(states.getDataExtent())

UPDATE:

var fixWMSLayerExtent = function(layer)
{
var readr = new Ext.data.XmlReader(
{ record: 'Layer'},
[
{name: 'name', mapping: 'Name'}
,{name: 'minx', mapping: 'LatLonBoundingBox > @minx'}
,{name: 'miny', mapping: 'LatLonBoundingBox > @miny'}
,{name: 'maxx', mapping: 'LatLonBoundingBox > @maxx'}
,{name: 'maxy', mapping: 'LatLonBoundingBox > @maxy'}
]);

var myStore = new Ext.data.Store({
url : "/MapProxy?url=" + layer.url +'&request=GetCapabilities' ,
reader : readr
});
myStore.load({'layer' : layer, callback: function(r, options, success)
{
var rindex = this.find('name', options.layer.name, 0, true, true);
var rec = this.getAt(rindex);
layer.maxExtent = new OpenLayers.Bounds(rec.data.minx, rec.data.miny, rec.data.maxx, 
rec.data.maxy);
} });
};

the code is from Sergey Malgin...

i hope it helps you...

3
  • it takes me to the center of worlds map. when I alert dataExtend it gives undefined. my layer is wms layer not vector layer. Thanks
    – Lazonaden
    May 17 '12 at 14:17
  • ok. so you directly use wms layer... there is a solution for this... i have updated my answer...
    – Aragon
    May 17 '12 at 14:21
  • seems to be good solution but I am not using Ext
    – Lazonaden
    May 18 '12 at 7:08
0

if you just have a point then you can use something like:

   map.setCenter(
     new OpenLayers.LonLat(longitude,latitude),
   10);

You can see a whole application which demonstrates this process at http://ian01.geog.psu.edu/geoserver_docs/apps/gaz/index.html

Updated

You can't do what you want directly I'm afraid. The bounds of a WMS layer are defined in the request URL so the requested image will always be the same as the OpenLayers.Map object it is in (otherwise there would be edges and uncoloured in bits in the map).

The only way you will be able to do this is to make a WFS request (so that you ask for the actual data instead of a picture of the data) and then calculate the bounds of the returned object and zoom to that or calculate the centroid of the object and set a zoomlevel and center the map on that point.

1
  • no I have something like this someLayer.mergeNewParams({ "CQL_FILTER": celIDCondition });
    – Lazonaden
    May 17 '12 at 14:22
0

If i read your code (and comments) correctly, i assume that "someLayer" is a WMS-layer, is this correct?

If so, getting the maxExtent is a bit problematic, as wms does not support this. If your WMS server offers the layer as WFS in addition to WMS, you could do a WFS request to the server, using the same filter as your WMS request, and get the extent from the features returned from the WFS request.

I could try to sketch an outline for the code doing this, but would like to get a confirmation that your someLayer is indeed a WMS layer.

1
  • Yes someLayer is WMS layer
    – Lazonaden
    May 18 '12 at 9:12

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.