Created
November 21, 2017 11:50
-
-
Save javymarmol/8f42d01f81f965eced520e9d5270d8d7 to your computer and use it in GitHub Desktop.
Extract drawingManager polygon path Google Maps on click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map; // Global declaration of the map | |
var iw = new google.maps.InfoWindow(); // Global declaration of the infowindow | |
var lat_longs = new Array(); | |
var markers = new Array(); | |
var drawingManager; | |
function initialize() { | |
var myLatlng = new google.maps.LatLng(40.9403762, -74.1318096); | |
var myOptions = { | |
zoom: 13, | |
center: myLatlng, | |
mapTypeId: google.maps.MapTypeId.ROADMAP} | |
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); | |
drawingManager = new google.maps.drawing.DrawingManager({ | |
drawingMode: google.maps.drawing.OverlayType.POLYGON, | |
drawingControl: true, | |
drawingControlOptions: { | |
position: google.maps.ControlPosition.TOP_CENTER, | |
drawingModes: [google.maps.drawing.OverlayType.POLYGON] | |
}, | |
polygonOptions: { | |
editable: true | |
} | |
}); | |
drawingManager.setMap(map); | |
google.maps.event.addListener(drawingManager, "overlaycomplete", function(event) { | |
var newShape = event.overlay; | |
newShape.type = event.type; | |
}); | |
google.maps.event.addListener(drawingManager, "overlaycomplete", function(event){ | |
overlayClickListener(event.overlay); | |
//textboxt de formulario | |
$('#vertices').val(event.overlay.getPath().getArray()); | |
}); | |
} | |
function overlayClickListener(overlay) { | |
google.maps.event.addListener(overlay, "mouseup", function(event){ | |
//textboxt de formulario | |
$('#vertices').val(overlay.getPath().getArray()); | |
}); | |
} | |
initialize(); | |
$(function(){ | |
//button para guardar | |
$('#save').click(function(){ | |
//iterate polygon vertices? | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment