[OpenLayers-Users] Http request?

Christopher Schmidt crschmidt at metacarta.com
Sat Jan 19 08:42:00 EST 2008

On Sat, Jan 19, 2008 at 01:16:15PM +0100, Andrea Maschio wrote:
> Il giorno 18/gen/08, alle ore 13:02, Christopher Schmidt ha scritto:
> >
> >The "X" in AJAX is for XML/XMLHttpRequest. XMLHttpRequest is not
> >neccesary to receive tiles -- instead, the proper URL is simply stuck
> >into an <img> tag, which (of course) can be loaded from other sites.
> Ok, so as I understand except fo wfs-t (that means transactional web  
> feature service and it's supposed to edit geometries and for this to  
> interact with the server) all other types of OL visualizations are  
> based on an image that is generated by the application server and  
> provided with layer information and other useful visualization stuff  
> in the xml file generated.

Close. By default (/ in the common case), OL has *no* interaction with
XML -- only with images. It uses the local Javascript configuration to
figure out how it should request those images. 

> Sorry if it is obvious, but i'm trying to figure out what i need and  
> if OL covers my purposes. Because I need to select some feature and  
> then with the information collected by a selection (with the mouse)  
> dialog with the server to do some operation on data.

I wasn't clear enough before: There are always ways *around* the Same
Origin Policy. Specifically, you can set up a proxy on any server that
you're serving from, such that all requests go through a specific URL 
(which is local) which does the actual talking to the server. This is a
reasonably common use case: this is why wfs.html shows points on
http://openlayers.org/dev/examples/wfs.html , even though the points are
from a remote server.

> Do I need wfs-t for this or maybe is better to collect the data in non  
> httprequest-way and then treat the data as parameters for a query. I  
> mean: in wfs-t is there a simpler way to edit data than collecting all  
> the gids of the features and then building a query with these ids?

Even if you did, unless you only wanted to see them (as an image) you
would still need to make a request to get the raw feature data: You will
need to use a Proxy, or host your HTML in the same "Origin" as your
server: see http://en.wikipedia.org/wiki/Same_origin_policy .

> >OpenLayers takes as a core tenet: "You can not talk to the server."  
> >This
> >means you can't use XMLHttpRequest to do anything that is crucial to
> >functionality unless there is no other way. All configuration, for
> >example, is not taken from the WMS GetCapabilities, but is instead  
> >taken
> >from local Javascript configuration -- duplicating information, but an
> >unfortunate consequence of the Same Origin Policy.
> Probably I didn't understood how things go in OL. When I instantiate a  
> map and then a layer and then add a layer to the map, how goes the  
> communication with the WFS server?

Relatively few maps have WFS servers in use. Most of them use WMS -- and
in that case, the only communication is putting <img
src="http://wms.example.com/" /> tags into the page.

For WFS, if the server is local, the server just uses XMLHttpRequest to
open "/cgi-bin/mapserv?foo=bar" or what have you -- essentially, if you
can form a valid relative URL to the server from the HTML page, you can
talk to it with XMLHttpRequest.

If the server is remote, a ProxyHost variable is set, which tells
OpenLayers to send all its XMLHttpRequests through a single proxy first,
which then passes on the request to the final destination.

Does this help answer your questions? In general, I consider WFS a
relative 'corner case' -- OpenLayers users seldom use it compared to the
number of WMS users, for exactly the reasons you describe, so I
apologize if my first email was less than clear.

Christopher Schmidt

More information about the Users mailing list