[OpenLayers-Users] Importing JSON to WKT

Joel Leininger leiningr at gmail.com
Mon Jul 9 19:44:37 PDT 2012


I have a vector layer populated with some multipolygons. I use a php
frontend to query a postgis database for necessary shapes, and initialize
the reader with the statement

var parcer = new OpenLayers.Format.WKT();

I then populate the layer with multimple statements like
var polygon0 = parcer.read("MULTIPOLYGON(((-8529098.94304024
4765383.48913123
blah, blah blah.
The multipolygon statements being encoded into the javascript as the page
is being built by php.

Everything works well. So far.

Now, after the page is loaded the user has opportunity to query that same
postgis database and get more shapes. I use a php backend to serve up JSONs
for each query, and firebug tells me that the WKT makes it into the right
variable in the script. It all looks perfect in the firebug variable
listing. Here are the statements I use to process the JSON response:

function updateSuccess(updateRequest) {
    updateJson = new OpenLayers.Format.JSON();
    updateOutput = updateJson.read(updateRequest.responseText);
    updateStatus = updateOutput.status;
    if (updateStatus == 'added') {
       new polygone = parcer.read(updateOutput[0]);
       ...
       further statements to redraw the layer, etc.

(updateOutput[0] reflects the fact that I'm providing for potentially
multiple polygons being updated -- in the future. For now, I'd be happy if
only one worked.

The problem seems to be that the parcer.read statement will not process any
variable, just a literal text string. (I've experimented all day
substituting different variables and literals.) If I plug in a new
MULTIPOLYGON literal, the statement will work, and processing will proceed.
Any variable though, and polygone remains undefined. I also experimented
with adding quotes to the string inside the variable as I noticed that php
didn't include any in the JSON encoding. That made no difference. Am I
missing something?? If variables can't be used in a read function, how does
one provide for future activity?

I'm using openlayers 2.11, by the way.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120709/4050cf28/attachment-0001.html>


More information about the Users mailing list