Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Features loading from Protocol to FeatureStore failed. #173

Open
NeilujD opened this issue Apr 25, 2013 · 18 comments
Open

Bug: Features loading from Protocol to FeatureStore failed. #173

NeilujD opened this issue Apr 25, 2013 · 18 comments

Comments

@NeilujD
Copy link

NeilujD commented Apr 25, 2013

When using the protocol config to load features in a FeatureStore and then load the features form the FeatureStore to a Vector Layer, the features are not added.

Example :

  • the layer I want : layer.features[x] = my feature
  • the layer I get : layer.features[0].features[x] = my feature

In other words the "features" parameter of the layer contains another "features" attributes, which is wrong IMHO.

In think this is a bug because the features are not displayed at all on the layer.

I found a way to resolve it :
In the file : GeoExt2/src/GeoExt/data/proxy/Protocol.js

I changed the line 108 :

  • FROM : "var result = o.reader.read(response);"
  • TO : "var result = o.reader.read(response.features);"

As a result of this patch, the features are displayed correctly.

Thank you in advance,

Julien Collard

@marcjansen
Copy link
Member

Hey @NeilujD, I have observed sth. similar, and think your first findings are correct. I'll try to have a deeper look in the next days. Thanks for your report!

@sluedtke
Copy link

sluedtke commented Oct 6, 2014

Hi all,

I am having trouble with this as well. Loading a geojson displays fine but the attributes are not listed in a "Ext.grid.GriPanel" . Instead I see entries in the first column like "OpenLayers_Feature_Vector_XX" where XX is a number.

Similar code for geoext1.1 works fine for both.

The attributes I am looking for are stored in layer.features[x].data.

Not sure whether this is the right channel to post these points. Sorry if not.

Thanks in advance

Stefan

@marcjansen
Copy link
Member

I haven't found time to dig deeper here, sorry.

I still think that the suggested change doesn't look to bad. I won't have time the next days, but I'll try not to forget about this one.

Thanks for bumping this issue.

@chrismayer
Copy link
Contributor

I also won't be able to look at this before the end of the week. But I am sure we'll get this handled soon. Thanks for keeping this up!

@fobetor
Copy link

fobetor commented Nov 22, 2014

I am having the same problem as Stefan, there is no way of displaying features in a gridpanel
Thanks
Fernando

@chrismayer
Copy link
Contributor

Hi all,
I think we have to split this a bit to get things clearer:

One problem is the thing with the nested feature attributes described by @NeilujD. Can you offer some code or ensure the problem still exists? When I take a look at the file GeoExt2/src/GeoExt/data/proxy/Protocol.js there is no line var result = o.reader.read(response);. @bartvde changed this to var result = o.reader.read(response.features || response); in 698d8ad. Does this solve your problem finally?

The other thing is the problem with the attributes in the GridPanel, desrcibed by @sluedtke and @fobetor. When I look at our online example (http://geoext.github.io/geoext2/examples/grid/feature-grid.html) displaying the attributes in the GridPanel should be working. Can you get your things running with some code similar to the code in the example? If not can you provide some code excerpts?

Cheers,
Chris

@fobetor
Copy link

fobetor commented Nov 24, 2014

Hi chris
Basically, I am using a feature store to get json features from geoserver
store = new GeoExt.data.FeatureStore({
layer: route_layer,
fields:[
{name: 'seq',type:'integer'},
{name: 'gid',type:'integer'},
{name: 'name',type:'string'},
{name: 'heading',type:'float'},
{name: 'cost',type:'float'}
],

       proxy: new GeoExt.data.proxy.Protocol({
    //  abortPrevious: true,
    //  setParamsAsOptions: true,
          protocol: new OpenLayers.Protocol.HTTP({

                url: "../proxy.php?http://Geoserver.url.com/ows&",

              format: new OpenLayers.Format.GeoJSON({

                })
            })
        })

    });

The features are drawn correctly on openlayers, and I can see the features in DOM in console, but the grid is not filled with the store data. The features appears in console as Stefan describes: Feature_vector_XX.
I cant find why if features are correctly drawn in openlayers, the Grid is not filled.
If I replace the url to a local .json file (as your example) then it works.
It fails when reading remote ajax json from geoserver
Thanks
Fernando

@chrismayer
Copy link
Contributor

Hi @fobetor ,
thanks for the information. That will help to find the problem. One last question: Which version of GeoExt do you use (2.0.0, 2.0.1, 2.0.2 or master) ?

@fobetor
Copy link

fobetor commented Nov 25, 2014

Hi Chris
I am using v 2.0.2 from this repository.
Thanks

@chrismayer
Copy link
Contributor

Okay I found the point. The main difference between your code and the online example here is that you are using a GeoExt.data.proxy.Protocol to query the features instead of defining a layer having an OpenLayers.Protocol. Both ways are fine, but if you go with a GeoExt.data.proxy.Protocol you have to define an appropriate reader for your proxy, a GeoExt.data.reader.Feature. Otherwise a default Ext.data.reader.Json is used by the proxy class which does not know anything about feature attributes and so they will be lost.

Here is a code snippet which works:

        // create feature store, binding it to the vector layer
        var store = Ext.create('GeoExt.data.FeatureStore', {
            layer: vecLayer,
            fields: [
                {name: 'name', type: 'string'}
            ],
            autoLoad: true,
            proxy: Ext.create('GeoExt.data.proxy.Protocol', {
                reader: Ext.create('GeoExt.data.reader.Feature', {root: 'features'}),
                protocol: new OpenLayers.Protocol.HTTP({
                    url: "../data/summits.json",
                    format: new OpenLayers.Format.GeoJSON({})
                })
            })
        });

BTW if the URL specified in the protocol is a local one or a remote one doesn't matter.

Hope this helps, maybe another online example showing how to use the GeoExt.data.proxy.Protocol to load features would helpful.

Cheers,
Chris

@chrismayer
Copy link
Contributor

I just added a PR (#318) with a new example showing the before mentioned.

@fobetor
Copy link

fobetor commented Nov 25, 2014

Thanks Chris
But now, once I use your code, I get a error in the console:

"NetworkError: 404 Not Found - http://172.26.0.100/web/New/proxy/%5Bobject%20Object%5D.js"
(I am testing in my local network)
I am missing somthing related to the proxy in the protocol? ... I was using:
url: "../proxy.php?http://Geoserver.url.com/ows&",
Thanks

@chrismayer
Copy link
Contributor

You are pointing to "http://172.26.0.100/web/New/proxy/[object Object].js" Maybe your your JS setting the URL is wrong? From a GeoExt point-of-view all should be fine now.

@fobetor
Copy link

fobetor commented Nov 26, 2014

Hi Cris
No, I am using this:
store = new GeoExt.data.FeatureStore({
layer: route_layer,
fields:[
{name: 'seq',type:'integer'},
{name: 'gid',type:'integer'},
{name: 'name',type:'string'},
{name: 'heading',type:'float'},
{name: 'cost',type:'float'}
],
proxy: Ext.create(GeoExt.data.proxy.Protocol({
reader:Ext.create(GeoExt.data.reader.Feature, {root: 'features'}),
protocol: new OpenLayers.Protocol.HTTP({
url: "../proxy.php?http://localgeoserver/ows&",
format: new OpenLayers.Format.GeoJSON({})
})
})
)});
without the changes you recommended, the proxy.php was found and used.
Now I find the error I mentioned:
/proxy/[object Object].js was not found on this server
I am lost :-)
thank you

@fobetor
Copy link

fobetor commented Nov 26, 2014

Escuses, it was my fault, I missed a "comma" in line
proxy: Ext.create(GeoExt.data.proxy.Protocol , ({
All works fine now. Thank you very very much
You can close the issue.
Best
Fernando

@marcjansen
Copy link
Member

Is everybody fine with closing this? Especially @NeilujD and @sluedtke may have to say something here.

@sluedtke
Copy link

I would like to say something but I am not able to test anything due to
a nasty illness.

A soon as I am fit again I will go and test it .. think next week.

Cheers

On 11/26/2014 08:48 PM, Marc Jansen wrote:

Is everybody fine with closing this? Especially @NeilujD and @sluedtke may have to say something here.


Reply to this email directly or view it on GitHub:
#173 (comment)

PGP Public Key: http://bit.ly/13d9Sca

@sluedtke
Copy link

sluedtke commented Dec 7, 2014

Hi all,

so I eventually found time to try the "reader" option and it partly solved my problem.

The following part is working now:
the properties read from the geojson input are now part of the vector layer and store and available at (i) vec_layer.features[XX].attributes or vec_layer.features[XX].data and (ii) the associated store store.layer.features[XX].attributes or store.layer.features[XX].data.

However, using that store with "Ext.create('Ext.grid.GridPanel'," does:
(i) throwing an error that says
TypeError: layer.map is null
layer.map.addControl(selectControl);
FeatureModel.js (line 174, col 8)

and (ii) the content displayed in the grid is, as far as I can see, the content of store.data.items[XX].data. and not correct. I still see an "OpenLayers_Feature_Vector_XXXX".

I am not sure whether this information is of importance within this context, but I do have 2 map-panels next to each other in my application. That is basically the only special point about it.

Thanks for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants