I am working with the Drawing Manager in the Drawing Library and a question arose. Any help would be greatly appreciated. Thanks in advance.
Question: After an object (marker, circle, etc...) is created, how would I call it? An example would be that I placed a marker. I now want to attach an info window to it. In the function to assign an info window, I need the "name" of the marker that i just placed.
Let me know if you need any more clarification.
-Seth
Add line or shape.Select a layer and click where to start drawing. A layer can have 2,000 lines, shapes or places. Click each corner or bend of your line or shape. To move the map, click and hold the mouse.
To draw a route, click "Add directions," choose transportation mode, and enter start and end points. You can draw lines and shapes on maps by clicking "Draw a line" and selecting "Add line or shape."
You can use an event listener to obtain a reference to the created object (event.overlay
). In this demo, the created markers are made to open the InfoWindow with content stored in the marker itself.
Click to create markers, then switch to the "Hand" icon mode and click on markers to open the InfoWindow.
var markers = [];
var infowindow = new google.maps.InfoWindow();
function initialize() {
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, 'overlaycomplete', function(event) {
if(event.type == google.maps.drawing.OverlayType.POLYLINE) {
alert("polyline complete");
}
else if(event.type == google.maps.drawing.OverlayType.MARKER) {
var newMarker = event.overlay;
newMarker.content = "marker #" + markers.length;
google.maps.event.addListener(newMarker, 'click', function() {
infowindow.setContent(this.content);
infowindow.open(map, this);
});
markers.push(newMarker);
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With