javascript - Replicate Google Maps Overlay Panel / Legend -


the google maps javascript api has nice legend / panel updates middle point of map based on click / touch events. in documentation go detail on how create such styled legend / overlay.

**please see example trying replicate before down vote question, thanks!

here link panel trying replicate: https://developers.google.com/maps/documentation/javascript/

(top right 'base maps' panel)

is way it? printing every line content.push? seems dirty.

var legend = document.createelement('div');     legend.id = 'legend';     var content = [];     content.push('<h3>butterflies*</h3>');     content.push('<p><div class="color red"></div>battus</p>');     content.push('<p><div class="color yellow"></div>speyeria</p>');     content.push('<p><div class="color green"></div>papilio</p>');     content.push('<p><div class="color blue"></div>limenitis</p>');     content.push('<p><div class="color purple"></div>myscelia</p>');     content.push('<p>*data fictional</p>');     legend.innerhtml = content.join('');     legend.index = 1;     map.controls[google.maps.controlposition.right_bottom].push(legend); 

here ended doing. using html , css style box/legend , using map.panto change center lat , long.

<div id="panel" class="open visible">                           <div class="mtam-title">                             <a href="#" id="minimize"></a>                             <div id="panel-title">change location</div>                           </div>                           <div id="panel-body">                             <div>                                 <h2>go further</h2>                                     <ul style="display: block;">                                     <li><a id="north_america">north america</a></li>                                         <li><a id="central_america">central america</a></li>                                         <li><a id="south_america">south america</a></li>                                         <li><a id="australia">australia</a></li>                                         <li><a id="africa">africa</a></li>                                         <li><a id="asia">asia</a></li>                                         <li><a id="europe">europe</a></li>                                         <li><a id="middle_east">middle east</a></li>                                     </ul>                             </div>                         </div>                      </div> 

and

//pan area         jquery("#panel-body").on("click", "li a", function (event) {             var id = event.target.id;              switch(id) {                 case 'central_america' :                     var lalatlng = new google.maps.latlng(18,-96);                     break;                 case 'africa' :                     var lalatlng = new google.maps.latlng(1.0,24.25);                     break;                 case 'north_america' :                     var lalatlng = new google.maps.latlng(50,-100);                     break;                 case 'asia' :                     var lalatlng = new google.maps.latlng(32.39,112.32);                     break;                 case 'south_america' :                     var lalatlng = new google.maps.latlng(-33,-69.6);                     break;                 case 'europe' :                     var lalatlng = new google.maps.latlng(48.69,14.67);                     break;                 case 'australia' :                     var lalatlng = new google.maps.latlng(-25.16,134.56);                     break;                 case 'middle_east' :                     var lalatlng = new google.maps.latlng(26.19,45.26);                     break;                 default:                     var lalatlng = new google.maps.latlng(38.3,-99);             }              map.setzoom(4);             map.panto(lalatlng);         }); 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -