I had an OpenLayers map that reads in and displayed a kml like this:
var vector_format = new OpenLayers.Format.KML({extractAttributes: true});
var vector_protocol = new OpenLayers.Protocol.HTTP({
url: 'http://www.geos.ed.ac.uk/~s0825955/thomlines.kml',
format: vector_format
});
var vector_strategies = [new OpenLayers.Strategy.Fixed()];
vector_Layer = new OpenLayers.Layer.Vector('More Advanced Vector Layer',{
protocol: vector_protocol,
strategies: vector_strategies
});
I am producing the with a perl file and have the kml as a variable. Can I replace the url ({ url: 'http://www.geos.ed.ac.uk/~s0825955/thomlines.kml',
) with the actual kml text as stored in my scalar variable $newkml
? and if so how?
Answer
I've never used scalar before, but if you can store the kml text as a javascript string, then you can just use an OpenLayers.Format.KML
object to read geometries from the kml text.
Some thing like this:
var kml_string = "..."; // you kml text stored as a javascript string
var kmlParser = new OpenLayers.Format.KML(); // Initialize with options if necessary
var feature_list = kmlParser.read(kml_string);
The feature_list
is the vector features from kml text.
No comments:
Post a Comment