[OpenLayers-Users] Pass layers array to php with json

sendeman martijnsendenspam at gmail.com
Fri Jul 31 05:59:31 EDT 2009


Hi All,

I'm trying to load some php into a div in my mapping application through a 
http://docs.jquery.com/Ajax/load#urldatacallback jQuery load function .

This works just fine, but now I want to pass all the maps layers to the php
script, so the php script can use some of the layer properties (name, id,
visibility, etc.)

I think I have to use json to serialize layer information, but I'm not at
all sure how to do this in openlayers. I tried:

[CODE]
var layers_json = openlayers.format.json.write(map.layers);
jQuery("#modules").load("/geoviewer/includes/legend.php", {layers:
layers_json});

And in the php:
if (isset($_REQUEST['layers'])) {
  $layers = json_decode($_REQUEST['layers']);
}
for ($intCounter = 0; $intCounter < count($layers); $intCounter++) {
  echo($layers[$intCounter]->{'name'});
}
[/CODE]

However, this doesn't work at all. :-)



Could someone get me on track with this?



Thanks a lot in advance for any help! It would be greatly appreciated.

Best regards,
Martijn Senden.
-- 
View this message in context: http://n2.nabble.com/Pass-layers-array-to-php-with-json-tp3361638p3361638.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list