[OpenLayers-Users] How do i add multiple GeoJson features to same
layer
giris68
per-erik.modig at itmedia.se
Wed Apr 23 11:06:57 EDT 2008
Hi!
I save all my features (polygon/vector) in an BLOBfield as GeoJSON in may
DB.
Then i use some AJAX to load the data but it only adds the last feature.
I'm just using som simple modified examples from the exampelsite.
The function i use to deserialize the GEOJSON and add it to the map is this:
function deserialize(element) {
var type = "GeoJSON";
var features = new OpenLayers.Format.GeoJSON().read(element);
var bounds;
if(features) {
if(features.constructor != Array) {
features = [features];
}
for(var i=0; i<features.length; ++i) {
if (!bounds) {
bounds = features[i].geometry.getBounds();
} else {
bounds.extend(features[i].geometry.getBounds());
}
}
polygonLayer.addFeatures(features);
map.zoomToExtent(bounds);
} else {
element.value = 'Bad input ' + type;
}
}
The GEJSON data that i recieved from db looks like:
{"type":"Feature", "id":"OpenLayers.Feature.Vector_153", "properties":{},
"geometry":{"type":"Polygon", "coordinates":[[[1914938.6508478164,
8682482.041704558], [1914709.339762993, 8682587.142618435],
[1914136.062050934, 8682654.025018176], [1914002.2972514534,
8682778.235189123], [1913916.3055946445, 8682988.437016882],
[1913792.0954236984, 8683074.428673694], [1913276.1454828454,
8683083.98330222], [1913113.7167977619, 8683179.529587565],
[1912970.397369747, 8683189.084216107], [1912569.1029713058,
8683208.193473162], [1912607.3214854433, 8683504.386957731],
[1912502.2205715657, 8684029.891527118], [1912846.1871988012,
8684584.05998211], [1913486.3473106003, 8684784.707181333],
[1913476.7926820659, 8684517.177582372], [1913610.5574815464,
8684173.210955132], [1914336.7092501544, 8683791.02581376],
[1914346.263878689, 8683752.807299623], [1914823.9953054048,
8683542.605471866], [1914862.213819542, 8682806.899074728],
[1914986.423990488, 8682625.361132573], [1914938.6508478164,
8682482.041704558]]]}, "crs":{"type":"EPSG", "properties":{"code":900913}}}
What do i do wrong or do i have to do something else?
http://www.itmedia.se/soft/maps/show.php (press "Ladda Ajax" to test my
solution)
--
View this message in context: http://www.nabble.com/How-do-i-add-multiple-GeoJson-features-to-same-layer-tp16834653p16834653.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list