[OpenLayers-Users] Make vector layer from JSON
Hugo
hfpmartins at gmail.com
Mon Mar 8 14:27:33 EST 2010
Thanks a lot for all the inputs you have given.
In fact with GeoJSON everything goes smoothly.
Cheers,
Hugo
On Mon, Mar 8, 2010 at 7:20 PM, Eric Lemoine <eric.lemoine at camptocamp.com>wrote:
> On Saturday, March 6, 2010, Hugo <hfpmartins at gmail.com> wrote:
> > Hello all,
> >
> > I'm trying to create a vector layer based on a php query (which includes
> the_geom) encoded in JSON. Until the moment i haven't been able to achieve
> this.
> > Following, is the relevant part of the code:
> >
> > var connect = new Ext.data.Connection();
> > connect.request({
> > url: 'mfbase/geoquery.php',
> > params: {
> > species: species,
> > datai: datai,
> > dataf: dataf
> > },
> > success: function(response){
> > var resp = response.responseText;
> > var json = new OpenLayers.Format.JSON();
> > var data = json.read(resp);
> > //console.log(data[0].the_geom);
> >
> > var querylayer1 = new OpenLayers.Layer.Vector(
> > 'Query1',
> > {
> > isBaseLayer: false,
> > projection: wgs,
> > geometryName: 'the_geom',
> > }
> > );
> >
> > querylayer1.addFeatures(data);
>
> addFeatures should receive an array of OpenLayers.Feature.Vector objects.
>
> How are geometries encoded in your JSON responses? If they are encoded
> as WKT you will also need OpenLayers.Format.WKT.
>
> Have you considered using GeoJSON? Using GeoJSON your client code will
> be simpler.
>
> Cheers,
>
> > map.addLayer(querylayer1);
> > }
> > })
> > Any suggestions are more than welcomed :)
> > Thanks to you all!
> >
> > Cheers,
> >
> >
> > --
> > Hugo Martins
> > FMV-UTL
> > CIISA-Epidemiologia e Saúde Pública Veterinária
> > Av. da Universidade Técnica
> > 1300-477 Lisboa
> > N 38°42'49.54", W 9°11'43.42"
> >
>
> --
> 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
>
--
Hugo Martins
FMV-UTL
CIISA-Epidemiologia e Saúde Pública Veterinária
Av. da Universidade Técnica
1300-477 Lisboa
N 38°42'49.54", W 9°11'43.42"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100308/574c7665/attachment.html
More information about the Users
mailing list