geoext2
geoext2 copied to clipboard
Bug: Features loading from Protocol to FeatureStore failed.
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
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!
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
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.
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!
I am having the same problem as Stefan, there is no way of displaying features in a gridpanel Thanks Fernando
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 698d8ad0f8b58f. 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
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
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) ?
Hi Chris I am using v 2.0.2 from this repository. Thanks
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
I just added a PR (#318) with a new example showing the before mentioned.
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
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.
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
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
Is everybody fine with closing this? Especially @NeilujD and @sluedtke may have to say something here.
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: https://github.com/geoext/geoext2/issues/173#issuecomment-64701129
PGP Public Key: http://bit.ly/13d9Sca
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!