[OpenLayers-Users] Questions on using Protocol.HTTP and custom
XML to load/edit features
Eric Lemoine
eric.lemoine at camptocamp.com
Wed Mar 10 01:06:28 EST 2010
On Monday, March 8, 2010, Stephen Woodbridge <woodbri at swoodbridge.com> wrote:
> OK, to partially answer some of my own questions ... inline below.
>
> Stephen Woodbridge wrote:
>> Hi all,
>>
>> I am trying to implement a vector layer that will allow editing point
>> data. The data is accessed via a PHP script that serves some arbitrary
>> XML. The layer looks like this so far:
>>
>> vector = new OpenLayers.Layer.Vector("POI", {
>> maxResolution: 360.0/16777216/2, // zoom 15
>> styleMap: styleMap,
>> protocol: new OpenLayers.Protocol.HTTP({
>> url: "poi-server.php",
>> params: {
>> m: 'r',
>> srs: 'EPSG:4326'
>> },
>> format: new OpenLayers.Format.XML()
>> }),
>> strategies: [
>> new OpenLayers.Strategy.BBOX({ratio: 1}),
>> new OpenLayers.Strategy.Save({
>> auto: true//,
>> //save: function() { alert("Save called."); }
>> }),
>> ]
>> });
>>
>> This seems like it almost works. But has the following problems, so
>> maybe I'm just taking the wrong approach all together. Here is a live
>> example:
>>
>> http://imaptools.com:8080/tilecache/test.html?zoom=17&lat=33.89595&lon=35.49935&layers=BT
>>
>> Issue:
>>
>> 1) the feature request does not seem to load on page load, but fires if
>> you pan the map slightly
>>
>> 2) when the features load, I get an error on line 128 of
>> OpenLayers/Format/XML.js because test.indexOf() is not a method. This is
>> because text is type Document not string?
>
> This appears to be because I need to write my own class like
> OpenLayers.Format.MyXML that parses the XML document the PHP returns and
> returns an array of features. Working on writing this.
>
>> 3) I assume the the XML parser will parse the response into an
>> appropriate tree object, then I need to add some code that reads the
>> tree and constructs feature objects that I then add to the layer. So is
>> the problem above because the text object passed to read IS my tree and
>> I need to pass a my own read() function to some code to do that? Where
>> do I do that?
>
> See 2) above.
>
>> 4) If I add a point using the toolbar add point button, I get
>>
>> Security error" code: "1000
>> http://imaptools.com:8080/ol28/lib/OpenLayers/Format/XML.js
>> Line 198
>>
>> data = serializer.serializeToString(node);
>>
>> What is this error and why am I getting it? I assumed that a default
>> serializer exists, I probably need to add my own it write the expected
>> XML the the PHP needs. Where would I add this and what are the exected
>> inputs and outputs?
>
> I'm hoping this is probably related to the above. will report back after
> I get my XML parser working.
>
>> 5) I eventually need to issue the Ajax requests by sending XML documents
>> to the server instead of issuing GET requests. So to do this I assume I
>> need to a) write code to serialize some params into a document, then b)
>> get HTTP protocol to send the document. How do I do this? The PHP code
>> is only temporary for testing and developing in my environment.
>>
>> I learned a lot today, just by reading lots of OL code but I still have
>> a ways to go.
>>
>> I would appreciate and help and guidance.
>
> Any thoughts on 1) or 5)? Just a pointer would be helpful :)
Hi Steve.
For 1) what version of OL are you using? I thought this issue was
fixed a while back. A test case demonstrating the problem would be
useful.
For 5) the HTTP protocol has a readWithPost option that allows sending
read requests with POST instead of GET. But I don't think it'll work
in your case because you it will post encoded params, and you won't be
able to provide it with your XML document. So I think you need to
implement your own protocol, possibly by extending/overriding
Protocol.HTTP.
Cheers,
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
More information about the Users
mailing list