Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The given solution didn't work for me, because the overlying div creates a dead spot in the map. A better solution for my project, using the Google Maps JavaScript API V3, was to create the reticle on the map as a marker with a 1 pixel rectangle shape. Then use the maps bounds_changed event to recenter the marker.</p> <p>Reticle image is 63 x 63 png. (images/reticle.png)</p> <p>Define the marker image and shape...</p> <pre><code> var reticleImage = new google.maps.MarkerImage( 'images/reticle.png', // marker image new google.maps.Size(63, 63), // marker size new google.maps.Point(0,0), // marker origin new google.maps.Point(32, 32)); // marker anchor point var reticleShape = { coords: [32,32,32,32], // 1px type: 'rect' // rectangle }; </code></pre> <p>After creation of our map (main_map) we add the marker...</p> <pre><code> reticleMarker = new google.maps.Marker({ position: latlng, map: main_map, icon: reticleImage, shape: reticleShape, optimized: false, zIndex: 5 }); </code></pre> <p>Here the var latlng is the same LatLng object used to create main_map. The zIndex should be greater than any other marker zIndex's, to keep the reticle on top.</p> <p>Then we add an event handler to be called when the map bounds_changed is fired.</p> <pre><code> google.maps.event.addListener(main_map, 'bounds_changed', centerReticle); </code></pre> <p>and finally we have the centerReticle() function.</p> <pre><code> function centerReticle(){ reticleMarker.setPosition(main_map.getCenter()); } </code></pre> <p>Since we're not doing anything else with the 'bounds_changed' event we can tidy up the code by passing an anonymous function to the addListener call... This keeps us from having to define the centerReticle() function. </p> <pre><code> google.maps.event.addListener(main_map, 'bounds_changed', function(){reticleMarker.setPosition(main_map.getCenter());}); </code></pre> <p>It actually works pretty slick. I hope this helps others.</p> <p>Thanks.</p> <p>Skip</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.
    3. 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