Skip to content

Instantly share code, notes, and snippets.

@jlivni
Last active August 29, 2015 13:56
Show Gist options
  • Save jlivni/8868244 to your computer and use it in GitHub Desktop.
Save jlivni/8868244 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[0].push([o.latlngs[i].lng + o.reflng, o.latlngs[i].lat + o.reflat])
}
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