[OpenLayers-Users] specifying a Format object w/ parameters for a GML Layer

Christopher Schmidt crschmidt at metacarta.com
Mon Oct 1 16:07:39 EDT 2007


On Mon, Oct 01, 2007 at 03:44:00PM -0400, Brian Hatchl wrote:
> Hey List,
> 
> So I was modifying the kml-layer-linestring.html example to load the output
> of my flight track to FOSS4G exported as KML from my GPS using GPSBabel...
> GPSBabel puts out KML with the 2.1 KML Namespace.
> 
> I was trying to figure out how instantiate the KML Format object with a 2.1
> kmlns parameter using this syntax:
> 
> gmllayer = new OpenLayers.Layer.GML("KML", "kml/traklog.kml", {format: new
> OpenLayers.Format.KML({kmlns: "http://earth.google.com/kml/2.1"})});
> 
> ...but OL was throwing this error:
> 
> this.format is not a constructor
> 
> var gml = this.format ? new this.format() : new OpenLayers.Format.GML();
> 
> GML.js (line 115)
> 
> 
> So my question is, is there a way in javascript to pass a Format class name
> such as OpenLayers.Format.KML to the GML Layer constructor along with an
> initialization parameter?

No, but you could do this, before you instantiate your layer:

OpenLayers.Format.KML.prototype.kmlns = "http://earth.google.com/kml/2.1";

> Or should the format parameter of the GML Layer constructor be an
> instantiated Format object?  Which would require GML.js line 115 to change
> like this:

I wish I could tell if something was a classname or an instantited
object. This was a bad API decision on my part, and now I don't want to
mess with backwards compatibility.

> var gml = this.format ? this.format : new OpenLayers.Format.GML();

I'll ponder this for a bit. Any other OL hackers have any opinions?

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list