javascript - Extend Google Maps Bounds so that div overlay doesn't cover any markers -


in google maps mashup i'm working on, map 100% wide , pretty 100% tall , have horizontal transparent div overlays left side of map using z-index , css.

when dynamically add markers, start empty bounds object , extend 1 one contain new latlngs. markers appear under transparent div contains other elements.

let's transparent div 250 pixels wide.

what i'd once bounds show markers established, i'd extend them 1 more time expand viewport of google map when fit bounds, these markers appear @ least 250 pixels away left border not covered transparent div.

i tried playing mapprojection.frompointtolatlng , mapcanvasprojection.fromdivpointtolatlng wasn't able achieve predictable results.

any advice or examples appreciated.

hopefully quick , dirty solution (it api v3)

<html>  <head>  <style> #over { position: absolute; z-index:99999; width: 250px; height: 600px; opacity: 0.7; top: 0px; border: 2px solid black; left: 0px; background: white; } </style>  <meta http-equiv="content-type" content="text/html; charset=utf-8"/>  <title>google maps bounds</title>  <script src="http://code.jquery.com/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>  <script type="text/javascript">  var map; var bounds; var  overlay; //the witdh of overlay (probably should dynamically var overlaywidth = 250;  function initialize() {   var chicago = new google.maps.latlng(41.875696,-87.624207);   var myoptions = {     zoom: 11,     center: chicago,     maptypeid: google.maps.maptypeid.roadmap   }   map = new google.maps.map(document.getelementbyid("map_canvas"),         myoptions);          overlay = new google.maps.overlayview();      overlay.draw = function() {};      overlay.setmap(map);   } function addmarker() {  maywood = new google.maps.latlng(41.8823,-87.8487);  var marker = new google.maps.marker({       position: maywood,        map: map   });  bounds = map.getbounds();  point = overlay.getprojection().fromlatlngtocontainerpixel(maywood); //point under overlay if (point.x<overlaywidth) { //calculate offset extend  offset = new google.maps.point((point.x-overlaywidth),0); extendbyx = overlay.getprojection().fromcontainerpixeltolatlng(offset); //here might want check if existing markers fit new bounds before applying new bounds newbounds = new google.maps.latlngbounds(extendbyx,bounds.getnortheast()); map.fitbounds(newbounds); }   }  </script>  </head>  <body onload="initialize()">  <div id="over">overlay</div>   <div id="map_canvas" style="width: 900px;height: 600px;"></div>  <input type="button" value="add marker & expand bounds" onclick="addmarker()"> </body>  </html>  

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -