Skip to content

Instantly share code, notes, and snippets.

@wboykinm
Forked from jlivni/jsv2 polygons to geojson
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wboykinm/8868428 to your computer and use it in GitHub Desktop.
Save wboykinm/8868428 to your computer and use it in GitHub Desktop.
// gmaps js api v2 polygon overlays -> geojson
overlayToGeoJSON = function(o){
var feature={type:'Feature', geometry:{ type:'Polygon', coordinates:[]}};
for (var i=0; i < o.latlngs.length; i++){
feature.geometry.coordinates.push([o.latlngs[i].lng, o.latlngs[i].lat])
}
feature.properties = {hint:o.hint, html: o.infohtml}
return feature;
}
var results={type: "FeatureCollection", features: []};
var os=map.overlays;
for (var i=0;i<os.length;i++){results.features.push(overlayToGeoJSON(os[i]))}
JSON.stringify(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment