Skip to content

Instantly share code, notes, and snippets.

@raghavgarg1257
Last active October 28, 2019 17:04
Show Gist options
  • Save raghavgarg1257/c52e88134d5c8043637210c8394e57dd to your computer and use it in GitHub Desktop.
Save raghavgarg1257/c52e88134d5c8043637210c8394e57dd to your computer and use it in GitHub Desktop.

RUBY

internal_grids.outlet_ares_line_boundary_pluscodes.to_json

JS

coord_json = "[]"
grids = JSON.parse(coord_json);
grids.forEach(grid => {
    bounds = new google.maps.LatLngBounds(
        new google.maps.LatLng(Number(grid.lat), Number(grid.lng)),
        new google.maps.LatLng(Number(grid.lat) + 0.000125, Number(grid.lng) + 0.000125)
    );
    
    new google.maps.Rectangle({
        bounds: bounds,
        fillColor: 'black',
        fillOpacity: 0.5,
        strokeWeight: 0,
        map: Y
    });
})

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);
        })
    });    
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment