RUBY
internal_grids.outlet_ares_line_boundary.map(&:to_json)
# second way
def get_line_json(id)
return unless id
polygons = JSON.parse(OutletServiceArea.select('st_asgeojson(service_area) as polygon').find(id)["polygon"])["coordinates"]
puts polygons.map{ |polygon| polygon.map{ |point| { lng: point[0], lat: point[1] } } }.to_json
end
JS
line_coords_json = ["[]", "[]"]
line_coords_json.map(polygon_line_json => {
lines = JSON.parse(polygon_line_json);
prev_line = lines[lines.length - 1];
lines.forEach((line) => {
var flightPlanCoordinates = [prev_line, line];
prev_line = line;
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(Y);
})
});
// second way
function draw_poly(polygon) {
polygon.map(lines => {
prev_line = lines[lines.length - 1];
lines.forEach((line) => {
var flightPlanCoordinates = [prev_line, line];
prev_line = line;
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(X);
})
});
}