[OpenLayers-Users] Best option for visualizing JSON

Lehtonen, Mika mika at digikartta.net
Thu Jan 8 07:25:51 EST 2009


Thanks Christopher,
for your answer. However, beacuse there's not so many points and I have 
to put this together quickly and because this is just a temporary 
solution, I ended up adding points onto a vector layer one by one. So 
here's the function that does that:

function json(req) {
    g =  new OpenLayers.Format.JSON();
    vastaus = g.read(req.responseText);
    vlayer.destroyFeatures();
    for (i in vastaus) {
    piste = new OpenLayers.Geometry.Point(vastaus[i].x, vastaus[i].y);
    spot = new OpenLayers.Feature.Vector(piste,{id: vastaus[i].id});
    vlayer.addFeatures(spot);
    }
     // vlayer.redraw(true);
    }

Behind this, is an OpenLayers.Request that requests the json from 
database using php-script for that. I also have a function which adds 
points to the database. This all works fine in FF3, but not in IE7. If I 
add a point in IE, it won't appear until I restart the browser. Even 
reloading the page won't help. Still if, after I have added the point in 
IE, I reload the page in FF3, the newly added point appears in it.
Any idea what's wrong?

- mika -

Christopher Schmidt kirjoitti:
> On Wed, Jan 07, 2009 at 11:28:37PM +0200, Lehtonen, Mika wrote:
>   
>> Hi,
>> I have some JSON data produced from an "ordinary" database. Basically 
>> it's an array having objects that include x-, y- and some attribute values.
>>
>> What would be the best way to render these x-, y-values as points or 
>> markers in Openlayers. Should I use Marker or Vector or what layer? Any 
>> Examples?
>>     
>
> I'd recommend turning the data into GeoJSON on the server, then using a
> Vector Layer with the HTTP Protocol and the GeoJSON format
> (alternatively, a GML Layer with a GeoJSON format). If you really can't
> do that, then you could write a custom subclass o the JSON format,
> basing it of something like the GeoJSON format, and follow either of the
> above options with your custom format.
>
> Regards,
>   



More information about the Users mailing list