[OpenLayers-Users] HTTP protocol with featureserver

Andreas Hocevar ahocevar at opengeo.org
Wed Dec 10 16:12:51 EST 2008


Alexandre Dube wrote:
> Andreas Hocevar wrote:
>   
>>   
>> Yes, but quite some efforts would be required. Reading the insertIds
>> this is the format's job. Format.GeoJSON does not know about insertIds.
>> The best thing to do here would be to subclass Format.GeoJSON and create
>> e.g. a Format.GeoJSON.FeatureServer. The next thing is that you need a
>> protocol that can handle insertIds. Protocol.HTTP cannot do that, so
>> this would also have to be extended.
>>
>> I am also quite new to the vector behavior stuff, so I might be wrong.
>> But to me it seems that the above should work.
>>
>> Let me know when you need more help, because I have to gain deeper
>> insight into that code anyway and doing it for a purpose other than just
>> looking at it will also make it easier for me.
>>
>> Regards,
>> Andreas.
>>
>>   
>>     
> Yep, that's exactly what I had in mind.
>
> Eric suggested to use the protocol.commit() function, but it has the 
> same problem ( no fid on new added features ), so I'll have to implement 
> one.  I'm still trying to figure how to just add function on commit(), 
> there's already something for that but I'm missing something because 
> when I set one, it replaces what is usually does instead of adding one :
>
>         olWFSRoads = new OpenLayers.Layer.Vector("Roads FS GeoJSON", {
>             scales: oMap.getScales(8,10),
>             styleMap: oStyleMap,
>             strategies: [new OpenLayers.Strategy.BBOX()/*, oSaveStrategy*/],
>             protocol: new OpenLayers.Protocol.HTTP({
>                 url: szFSURL+"/bdga_route_l_arc?format=GeoJSON",
>                 format: new OpenLayers.Format.GeoJSON(),
>                 create: function(){alert("foo")}  //<-- this gets 
> triggered, but no POST is created...
>             })
>         });
>
> I'll continue to look deeper and try to understand this.
>   

You can pass a userCallback to the create function if you instantiate
the protocol like that:

new OpenLayers.Protocol.HTTP({
    url: "yourUrl",
    format: OpenLayers.Format.GeoJSON, // needs to read insertFids
    options: {
        create: {
            callback: function(response) {
                // your stuff here
            }
            scope: yourFunctionScope
        }
    }
}

Regards,
Andreas.

-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.




More information about the Users mailing list