asynchronous cross domain POST request inside openlayers

3 messages Options
Embed this post
Permalink
loic devaux

asynchronous cross domain POST request inside openlayers

Reply Threaded More More options
Print post
Permalink
Hi List,

I am implementing a new OpenLayers layer type ( using existing WMS layer code) to display data from CartoWeb (3.5) Web-GIS with OpenLayers. Because CartoWeb's architecture can be divided in two servers ( one dealing with the user interface and another dealing with the GIS processes) I need to make a cross browser POST request to fetch data but that's not possible with Xmlhttprequest . I don't want to user OpenLayers Proxyhost capability because that will increase traffic and complexity for deployment.
There are some solutions with GET requests but the one that works fine for me for POST requests is submitting a dynamically generated form inside a dynamic iframe. I read Google Maps has something similar.
Now my problem is that I rely on the onLoad event of the iframe that tells me when the fetched data is available in the browser. Because this is an asynchronous execution I haven't found a way to feed OpenLayers with the data because there is no way (?) in javascript ( without doing ugly cpu intensive javascript loops or waiting for javascript 1.7 ) to halt execution and resume it once the callback function (which retrieves the data) associated to the onLoad event of my iframe has been triggered.
I managed however to make things work for the layerswitcher control but the other openlayers controls are far more complex and  I try to be the less intrusive as possible so I don't want to modify the source code of each control (which wouldn't be a solution for custom controls anyway).
The only solution I see would be to be able to specify the execution order of the callbacks so I could execute my callback first which woud :
- store the event context
- stop the other callbacks from executing
- fetch the CartoWeb data
- recall the stopped callbacks using the stored context

I don't know if this is feasible as it seems that each browser might handle the execution order of browser events differently but maybe OpenLayers has more control on his own events.

Sorry for the necessary verbosity. I'd be glad to see alternative solutions. I believe that by solving this problem we would at the same time extend OpenLayers interoperability since cross domain requests inside the browser might more and more belong to the future of the web even though this raises legitimate security concerns.

Loïc
Eric Lemoine-2-2

Re: asynchronous cross domain POST request inside openlayers

Reply Threaded More More options
Print post
Permalink
On Tue, Mar 31, 2009 at 5:30 PM, loic devaux <[hidden email]> wrote:

>
> Hi List,
>
> I am implementing a new OpenLayers layer type ( using existing WMS layer code) to display data from CartoWeb (3.5) Web-GIS with OpenLayers. Because CartoWeb's architecture can be divided in two servers ( one dealing with the user interface and another dealing with the GIS processes) I need to make a cross browser POST request to fetch data but that's not possible with Xmlhttprequest . I don't want to user OpenLayers Proxyhost capability because that will increase traffic and complexity for deployment.
> There are some solutions with GET requests but the one that works fine for me for POST requests is submitting a dynamically generated form inside a dynamic iframe. I read Google Maps has something similar.
> Now my problem is that I rely on the onLoad event of the iframe that tells me when the fetched data is available in the browser. Because this is an asynchronous execution I haven't found a way to feed OpenLayers with the data because there is no way (?) in javascript ( without doing ugly cpu intensive javascript loops or waiting for javascript 1.7 ) to halt execution and resume it once the callback function (which retrieves the data) associated to the onLoad event of my iframe has been triggered.
> I managed however to make things work for the layerswitcher control but the other openlayers controls are far more complex and  I try to be the less intrusive as possible so I don't want to modify the source code of each control (which wouldn't be a solution for custom controls anyway).
> The only solution I see would be to be able to specify the execution order of the callbacks so I could execute my callback first which woud :
> - store the event context
> - stop the other callbacks from executing
> - fetch the CartoWeb data
> - recall the stopped callbacks using the stored context
>
> I don't know if this is feasible as it seems that each browser might handle the execution order of browser events differently but maybe OpenLayers has more control on his own events.
>
> Sorry for the necessary verbosity. I'd be glad to see alternative solutions. I believe that by solving this problem we would at the same time extend OpenLayers interoperability since cross domain requests inside the browser might more and more belong to the future of the web even though this raises legitimate security concerns.
>
> Loïc

Hi Loïc

Just a quick comment. I fail to see why you need synchronous behavior
here, e.g. why would the LayerSwitcher need to know when the data has
been received?

--
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
loic devaux

Re: asynchronous cross domain POST request inside openlayers

Reply Threaded More More options
Print post
Permalink
The openLayers controls  ( and this includes the Layerswitcher) shouldn't need to know when the data has been received but technically speaking it is the only place I found where I could insert the code fetching the data and still keep a synchronous behaviour.
Why do I need synchronous execution and what data am I fetching?
The new openLayers layer type I implemented to interact with CartoWeb server part uses code found in the WMS layer type so there is a getURL() function  that is in charge of returning the url of the generated bitmap representation of the layer. So when getUrl() gets executed data must have already been retrieved. In my case data is a soap response containing the url of the generated bitmap and coordinates of each geometry so I can create placemarks. If I don't have synchronous execution then I have no guarantee that getUrl() will be able to return the url since it might not be able to extract the url from the soap response if the response didn't arrive yet ( which might be the case when things are done asynchronously).

Because the code in the LayerSwitcher launched when the user clicks on a layer checkbox  is simple :

onInputClick: function(e) {
....
                this.layerSwitcher.updateMap();        
.....

I can pass the updateMap() function as a callback to the onLoad event of the iframe so once the iframe retrieves the data it calls updateMap() which later on calls getUrl() which is happy to process the data.

Unfortunately this is not easy to implement for other controls...



Eric Lemoine-2-2 wrote:
Hi Loïc

Just a quick comment. I fail to see why you need synchronous behavior
here, e.g. why would the LayerSwitcher need to know when the data has
been received?

--
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@camptocamp.com
http://www.camptocamp.com
_______________________________________________
Dev mailing list
Dev@openlayers.org
http://openlayers.org/mailman/listinfo/dev