Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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);
share|improve this question
    
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? –  iant May 18 '12 at 7:27
    
I updated my question Thanks –  Iliaka May 18 '12 at 7:42

3 Answers 3

up vote 0 down vote accepted

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.

share|improve this answer
    
no I have something like this someLayer.mergeNewParams({ "CQL_FILTER": celIDCondition }); –  Iliaka May 17 '12 at 14:22

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...

share|improve this answer
    
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 –  Iliaka 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 –  Iliaka May 18 '12 at 7:08

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.

share|improve this answer
    
Yes someLayer is WMS layer –  Iliaka May 18 '12 at 9:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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