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 a map with WMS layer. And want to zoom to selected object. Now i use GetCapabilities from Geoserver and zoom to bbox of whole layer.
So how to do what i want?

Or can u tell me how to get feature bbox from Capabilities? Or how to get FeatureInfo without clicking on map?

UPDATE

                       info_id=myVecLayer.getFeaturesByAttribute("id",'5')
                       alert(info_id[0].geometry.getBounds());
                       app.mapPanel.map.zoomToExtent(info_id[0].geometry.getBounds());
                       //myVecLayer is WFS layer

Its do something strange. If feature shows in map window it will be zoomd to it. But if not shows get a error TypeError: info_id[0] is undefined. What is wrong?

UPDATE 2

Ok now this is Request method

                        info_id=OpenLayers.Request.GET({
                                    url:'http://localhost:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetFeature&typeName=cite:filedata_temp&featureID=filedata_temp.4',
                                    success: function(e){
                                    alert(e.responseText);
                                    }
                                });

its ok. But how to get bbox from there?

UPDATE 3

Now i use a GeoExt.FeatureStore to zoom to feature.
But i have a problem i try zoom_store.layer.getFeaturesByAttribute("id",'5'); and all work. But if i use variable zoom_store.layer.getFeaturesByAttribute("id",some_variable); i get error TypeError: info_id[0] is undefined. Why its heppening?

share|improve this question
    
How did you selected the object in the first place? I guess you already did a WMS GetFeatureInfo or a WFS GetFeaure request to do the selection? Or is the selection just done "visually" with a CQL filter? –  Andrea Aime Jul 31 '12 at 7:07
    
i use CQL filter. –  Kliver Max Jul 31 '12 at 7:52
    
@Kliver Max, first of all, check out if you have info_id[x] and then run your zooming code... –  Aragon Jul 31 '12 at 9:27
    
I change getFeaturesByAttribute to getFeatureByFidand all works fine. I dont know whats wrong with getFeaturesByAttribute maybe this Returns an array of features that have the given attribute key set to the given value. Comparison of attribute values takes care of datatypes, e.g. the string ‘1234’ is not equal to the number 1234. –  Kliver Max Jul 31 '12 at 9:43
add comment

3 Answers 3

In order to get the bbox you can use the same CQL filter in a WFS GetFeature request, and enable "feature bounding" in the WFS options to make it generate the bbox. This will unfortunately also give you the full feature contents, if you just want the BBOX there is a WPS process that returns just the BBOX instead.

share|improve this answer
    
im update question. And try do request but how parse it? –  Kliver Max Jul 31 '12 at 8:18
    
I'm not familiar with OL enough, but surely there are ways to parse GML? Regardless, if you load the response in a DOM you can just go for the element representing the bounding box of the collection –  Andrea Aime Jul 31 '12 at 10:34
add comment
up vote 0 down vote accepted

So after all i use this.
1. Create GeoExt.FeatureStore.

                    zoom_store = new GeoExt.data.FeatureStore({
                                layer: myVecLayer,
                                fields: [
                                    {name: 'id', type: 'int'},
                                    {name: 'mydata', type: 'String'}
                                ],
                                 proxy: new GeoExt.data.ProtocolProxy({
                                    protocol: new OpenLayers.Protocol.WFS({
                                        version: "1.0.0",
                                        srsName:"EPSG:900913",
                                        url: "http://localhost:8080/geoserver/wfs",
                                        featureType: "filedata_temp",
                                        featureNS: "http://www.opengeospatial.net/cite",
                                        //filter:Ffilter
                                    })
                                }),
                                autoLoad: true
                            });

2 Create atother one layer.

vectorLayer = new OpenLayers.Layer.Vector("Editable features");
                                app.mapPanel.map.addLayer(vectorLayer);
                                vectorLayer.visibility=false;

3 Add features to this layer.

vectorLayer.addFeatures(some_features);

4 Zoom to this layer.

app.mapPanel.map.zoomToExtent(vectorLayer.getDataExtent());
                            vectorLayer.removeAllFeatures();

I will glad if u give me something more usefull.

share|improve this answer
add comment

I don't know if you solve the problem but you can try this:

zoom_store.layer.getFeaturesByAttribute("id",String(some_variable));

Works for me

share|improve this answer
add comment

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.