[OpenLayers-Users] How to overwrite OpenLayers.Format.KML

Arnd Wippermann arnd.wippermann at web.de
Thu Oct 4 09:15:31 EDT 2007


I want to display kml-files in SphericalMercator on google maps. kml-files
works with lon-lat-values, so I have to reproject the data. With the
functionality of OpenLayers it's no problem.

Problem is:

I don't know how to overwrite the OpenLayers.Format.KML-class before
creating the layer. I want to change the functions 

point: function(node) {...
linestring: function(node, ring) {...

to insert some stuff for reprojecting the data from EPSG:4326 to
EPSG:900913. Also I need 2 new properties in the Class:

fromEPSG, toEPSG.

OpenLayers.Format.KML.prototype.point = function(){... didn't work, neither
set a new property with OpenLayers.Format.KML.fromEPSG.

So I have copied the whole class, changed the name of the class, entered my
stuff. To choose between klmns 2.0 and 2.1 I have a second copy with only
change for the klmns.

My code to call the functions looks like

if(kmlVersion==20)
    var parseKMLx = OpenLayers.Format.KMLx;
else
    var parseKMLx = OpenLayers.Format.KMLx21;

map.addLayer(new OpenLayers.Layer.GML("KML " + (++kmlCounter), mykml,
{format: parseKMLx}));

The loading of KML-files in EPSG:4326 and reprojecting them to EPSG:900913
works great! 

Question : Is there a better way to establish this behaviour without copy
the class two times.

Mit freundlichen Grüssen

Arnd Wippermann
http://gis.ibbeck.de/ginfo/





More information about the Users mailing list