Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This page shows one way of connecting a sidebar link to your markers </p> <p><a href="http://www.wolfpil.de/v3/toggle-cats.html" rel="nofollow">http://www.wolfpil.de/v3/toggle-cats.html</a></p> <p>Copying this page's patterns to your case, you need a <code>gmarkers</code> global variable</p> <pre><code>//&lt;![CDATA[ var map = null; var gmarkers = []; function initialize() { </code></pre> <p>The order in which markers are added matters, they should match the order of the businesses in the sidebar. <code>gmarkers</code> will be updated in <code>createMarker</code>.</p> <pre><code>var point = new google.maps.LatLng(37.984798,-121.312094); var marker = createMarker(point,'&lt;div style="width:205px"&gt;&lt;center&gt;&lt;img src="images/sampleuopsign.jpg" /&gt;&lt;/center&gt;&lt;h2&gt;University of the Pacific&lt;/h2&gt;3601 Pacific Avenue&lt;br&gt;Stockton, California 95211&lt;br&gt;209.946.2011&lt;br&gt;&lt;small&gt;On the web visit: &lt;a href="http://www.pacific.edu"&gt;www.Pacific.edu&lt;\/a&gt;&lt;/small&gt;&lt;\/div&gt;') ... function createMarker(latlng, html) { var contentString = html; var marker = new google.maps.Marker({ position: latlng, map: map, zIndex: Math.round(latlng.lat()*-100000)&lt;&lt;5 }); google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(contentString); infowindow.open(map,marker); }); gmarkers.push(marker); } </code></pre> <p>With the array in place, we can address them by index. Wolfpil simply triggers a click event when a sidebar entry (link) is clicked:</p> <pre><code>function triggerClick(i) { google.maps.event.trigger(gmarkers[i],"click"); } </code></pre> <p>And each link can be written like this, replacing 0 and 1 with the order each marker was added:</p> <pre><code>&lt;a href="javascript:triggerClick(0)"&gt;Bank of America&lt;/a&gt; &lt;a href="javascript:triggerClick(1)"&gt;Bank of Stockton&lt;/a&gt; </code></pre> <p>About the marker hover showing a title, the easiest way is adding a <code>title</code> option when creating your markers, but it would mean adding a new parameter to your createMarkers function: </p> <pre><code> function createMarker(latlng, storeName, html) { var contentString = html; var marker = new google.maps.Marker({ position: latlng, map: map, title: storeName, zIndex: Math.round(latlng.lat()*-100000)&lt;&lt;5 }); </code></pre> <p>A better alternative in the long run is to use an object for <code>gmarkers</code> instead of the array, because adding an item in the middle of the list will disorganize the existing items in the HTML.</p> <p>Then, places can be called by a string ID, such as <code>gmarkers['safeway']</code>. Instead of pushing a marker to the array in <code>createMarker</code>, we assign the id to the marker:</p> <pre><code>gmarkers[id] = marker; </code></pre> <p>If you run into trouble write comments below please! I didn't test the code above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload