Reputation: 5
Is there a way to read geojson in openlayers and convert to WKT format , my problem is that when i add more than one geojson as vector layer , they don't appear as one layer , kindly tell me how to display multiple geojson as part of a single vector layer , my code is
for (var i = 0; i < content.GeoJsonFiles.length; i++) {
//color = content.Settings.BreakStyles[totalcolor].Color;
//totalcolor++;
var id = content.GeoJsonFiles[i];
// alert(content.GeoJsonFiles[i]);
var geojson_layer = new OpenLayers.Layer.Vector("GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url:'i.geojson' ,
format: new OpenLayers.Format.GeoJSON({})
}), renderers: ["Canvas", "SVG", "VML"]
});
map.addLayer(geojson_layer);
}
Upvotes: 0
Views: 928
Reputation: 13181
'i.geojson'
will always evaluate to "i.geojson" string, no matter what the value of i
is. You probably wanted content.GeoJsonFile[i].content
, assuming content
actually contains URLs, not raw GeoJSON dataHigh-level outline of what needs to be done instead (assuming .content
contains raw GeoJSON, I suspect this is the case):
var geoJsonLayer = new OpenLayers.Layer.Vector("GeoJSON", {
// layer options
});
for (var i = 0; i < content.GeoJsonFiles.length; i++) {
var feature = content.GeoJsonFiles[i].content;
geojsonLayer.addFeatures([feature]);
}
map.addLayer(geoJsonLayer);
You'd need to clarify what content.GeoJsonFiles
actually contains and what WKT has to do with all this for a more precise answer.
Upvotes: 1