3

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?

4
  • 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? Commented Jul 31, 2012 at 7:07
  • i use CQL filter.
    – Kliver Max
    Commented Jul 31, 2012 at 7:52
  • @Kliver Max, first of all, check out if you have info_id[x] and then run your zooming code...
    – urcm
    Commented Jul 31, 2012 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
    Commented Jul 31, 2012 at 9:43

3 Answers 3

1

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.

2
  • im update question. And try do request but how parse it?
    – Kliver Max
    Commented Jul 31, 2012 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 Commented Jul 31, 2012 at 10:34
0

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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