How to add KML data but from variable - not from url?

How to add KML data but from variable - not from url?

I have a working map that retrieves KML from a url, but now I need to get the KML data from a local variable instead. Is there support for this, and if so what is the syntax. Searched the api and various sites but no luck finding anything about this. Thanks!


map = new OpenLayers.Map({ div: "map", layers: [ new OpenLayers.Layer.WMS( "WMS", "", {layers: "basic"} ), new OpenLayers.Layer.Vector("KML", { strategies: [new OpenLayers.Strategy.Fixed()], protocol: new OpenLayers.Protocol.HTTP({ url: "kml_large.kml", format: new OpenLayers.Format.KML({ extractStyles: true, extractAttributes: true, maxDepth: 2 }) }) }) ], center: new OpenLayers.LonLat(-81, 28), zoom: 7 });

This will create OpenLayers.Feature.Vector Features from the KML string.

You might need to modify the projection info to fit your needs:

function GetFeaturesFromKMLString (strKML) { var format = new OpenLayers.Format.KML({ 'internalProjection': myMapObject.baseLayer.projection, 'externalProjection': new OpenLayers.Projection("EPSG:4326") }); return; };

Then you can do something like: