Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Event Listener within a Google Maps info window

Posted on 2011-09-06
5
Medium Priority
?
381 Views
Last Modified: 2012-05-12
Here is a link to a page containing a Google Map http://www.soundsairpark.com/sandpit/mapTest.html

As it stands I have a zoom event occurring when the marker is clicked. I would like to change this so the zoom event only occurs only when the "zoom" link within the info window is clicked.
Assistance appreciated.
Regards,
N
0
Comment
Question by:Neil_Bradley
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36496005
It's because you have:

function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
             
             map.setZoom(15);
        });

Do you see the issue? You call "map.setZoom(15)" when the marker is clicked. Change it to:

function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
0
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 36498991
Removing the Zoom from the marker click is straight forward I know and yes your answer would do this. However my question relates to how to add an event listener to the word "zoom" inside the info window so that when it is clicked the zoom occurs.
N
0
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 total points
ID: 36502330
When you create the link, add a javascript onclick event that will call "map.setZoom(15)"
0
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 36506300
That is the crux of my question and what I having difficulty achieving. The attached code is the info window set up or the full script can be found via the link.
http://www.soundsairpark.com/sandpit/mapTest.html
N

// Set up marker with info windows 
    
      var point = new GLatLng(-41.34204, 173.957801);
      var marker = createMarker(point,'<div style="width:240px; font-family:Arial; font-size:14px"><img src="http://www.soundsairpark.com/sandpit/images/structure/logo-icon.png" width="66" height="48"  style="float:left; margin-right:10px">Marlborough Sounds <br>Air Park<br>SH1, Picton. NZ<br> <a id=zoom" href="#">Zoom<\/a><\/div>')
      map.addOverlay(marker);

Open in new window

0
 
LVL 5

Author Closing Comment

by:Neil_Bradley
ID: 36506586
Ok, it looks like I have it! Many thanks for pointing me in the right direction. If you are interested I am about to post a related question asking how to create a toggle effect on my button.
Cheers
N

My solution:<input type="button" id="zoom" value="Zoom" onclick="map.setZoom(15)"/>
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question