javascript - Export geoJSON data from Google Maps -
Is there a library to export the built-in support or google
geoJSON
data from google. Maps.Data layer or google.maps.Data.Feature
or google.maps.Data.Gemometry
or even marker
, polyline
and polygon
. I have a code, for example:
var point = new google.maps.Data.Point (m.getPosition ()); ActiveFeature.setGeometry (point); Console.log (activeFeature.getGeometry ()); EquiLayer.add (activeFeature);
I want to export this data as a geojson on the server. toGeoJson
method in the sheet
?
A sample-function:
google.maps.Map. Prototype.getGeoJson = function (callback) {var geo = {"type": "FeatureCollection", "FEATURES": []}, fx = function (g, t) {var that = [], arr, f = {MultiLineString : 'LineString', linestrings: 'point', multipolision: 'polygon', polygon: 'linering', linearization: 'point', multipoint: 'point'}; Switch (t) {case 'point': g = (gta)? G. FT (): G; Return ([g.lng (), g.lat ()]); break; Default: arr = g.getArray (); For (var i = 0; i & lt; arr.length; ++ i) {that.push (fx (are [i], f [t])); } If (t == 'linering' amp; amp; amp; amp; amp; amp; amp;; that] [that Length-1]) {that.push ([[[0] [0], [0] [1]]); } That back; }}; This is Dita. Year (function) {var _feature = {type: 'feature', property: {}} _id = feature.getId (), _geometry = feature.getGeometry (), _type = _geometry.getType (), _cordinate = fx _geometry, _type); _feature.geometry = {type: _type, coordinate: _cordinate}; if (typef _id === 'string') {_feature.id = _id;} geo.features.push (_feature); feature. ECaporty (Function (V, K) {_feature.properties [k] = v;})}}}; If (callback === 'type of function') {callback (geo); } Return to Geo; }
Function creates an object with data You can pass a callback as the argument that the object will be executed in the form of arguments.
Sample Call:
// map google.maps.Map-instance is map.getGeoJson (function (o) {console.log (o)}); DEMO: Note: The demo also stores the circles, but the coordinates are not supported in Geojosan. As a workaround, it stores the circle as a POINT with radius-property. When a POINT with a radius-property is loaded into the data-level, the demo hides the marker and creates a circle based on the geometry
& lt; Edit & gt;
: An underlying method is now available for geo-export:
See for an example
Comments
Post a Comment