[OSM-dev] POI layer refusing to talk to server php

Nick Whitelegg Nick.Whitelegg at solent.ac.uk
Fri Jan 7 15:13:16 GMT 2011


Hi,

You don't really need a text file, you can generate XML directly from the PHP and have OpenLayers read that. One good format to use for the XML is GeoRSS as OpenLayers already has a parser for that.
The OpenLayers parser uses GeoRSS with Atom rather than RSS 2.0.

Look at http://www.free-map.org.uk. The annotations (red stars) are generated from a GeoRSS feed generated in turn by a PHP script from the database.

Here is how I create the layer (as you can probably tell, annotation.php generates the GeoRSS feed):

freemap.layerAnnotations = new OpenLayers.Layer.Vector ("Annotations",
            { strategies: [new OpenLayers.Strategy.BBOX()],
             protocol: new OpenLayers.Protocol.HTTP
                 ( { url: "/freemap/annotation.php?action=getByBbox",
                    format: new OpenLayers.Format.GeoRSS() } ),
            styleMap: asm } );

You can alternatively define your own format if you don't want to use GeoRSS. See
http://www.free-map.org.uk/otv/RouteJSON.js
as an example (this is JSON based, and creates LineStrings, but it's the same general idea).

Nick


More information about the dev mailing list