I'm new to OpenLayers (2.13). I saw in the example section that it is possible to draw features like lines, points and polygons.


Quite interesting. But there is no export feature with it. I mean drawing features on the map is useless if I can't export it in KML or GML or GeoJSON.

Is there any example about exporting features in KML?

1 Answer 1


Well, you have several options, depending on what you actually want to do.

  1. You can add a featureAdded call to your draw control (doc)
  2. You can listen to the 'featureadded' event on the Vector layer you are drawing on (doc)
  3. You can have a button to trigger some functionality to get the features from the vector layer using 'features' array of the layer

Once you have the added feature (or the array of features), you can use one of the 'formats', maybe the KML format, and write the features:

var format = new OpenLayers.Format.KML();
var kmlData = format.write(features);
  • Ok, that's a start, thanks. I am not very good at javascript. Is there any complete example I can find over the Internet which "writes" the features in a KML (or GML, GeoJSON...) file like you describe?
    – user27382
    Commented Feb 26, 2014 at 16:29
  • 1
    To be completely honest: Learn JavaScript before you try to make a solution like this by following tutorials and such. There is a ton of bad map applications made by people that doesn't know JavaScript (or web development). Do invest the time (or hire someone who knows) if you are making something that should be used as more than a one-off for your own personal use.
    – atlefren
    Commented Feb 26, 2014 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.