what want:
- extract lat,lon values json new variable build geojson
- load new variable googlemap , create polygon
this json, contains needed lat, lon values:
{ "rangemap": { "rangemaps": [ { "polyline": [ { "lat": 48.1914210319519, "lon": 11.3745188713074 }, { "lat": 48.1789970397949, "lon": 11.3705492019653 }, ... , on this variable want load map:
var rangemap_eco = { "type": "featurecollection", "features": [ { "type": "feature", "geometry": { "type": "polygon", "coordinates": [ ] } } ] }; with code extract coordinates json "coordinates"-array in variable:
$scope.parserm_eco = function(){ var first; var last; for(var z=0; z < vm.rangespider.rangemap.rangemaps[0].polyline.length; z++) { first = vm.rangespider.rangemap.rangemaps[0].polyline[z].lon; last = vm.rangespider.rangemap.rangemaps[0].polyline[z].lat; arr[z] = '['+first+','+last+']'; } rangemap_eco.features[0].geometry.coordinates.push(arr); console.log(rangemap_eco); } with map.data.addgeojson(rangemap_eco); load variable map.
but error "error: in property "features": @ index 0: in property "geometry": in property "coordinates": @ index 0: @ index 0: not array"
i don't know where's mistake....
arr[z] = '['+first+','+last+']'; should be
arr[z] = [first, last]; or better
arr.push([first, last]); i.e. "coordinates" array of arrays
coordinates: [ [lon, lat], [lon, lat], ... etc ]
Comments
Post a Comment