Algo así
Código HTML:
Ver original<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> *{ margin: 0; padding: 0; }
html, body, #map{
width: 100%;
height: 100%;
}
#menu{
width: 200px;
margin: 0 auto;
border: 1px solid #333333;
position: relative;
top: -50px;
text-align: center;
padding: 5px;
}
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=es"></script> <script type="text/javascript"> /**
* Listener para el formulario
*/
function addListener(element, type, expression, bubbling)
{
bubbling = bubbling || false;
if(element.addEventListener) { // Standard
element.addEventListener(type, expression, bubbling);
return true;
}else if(element.attachEvent) { // IE
element.attachEvent('on' + type, expression);
return true;
}else return false;
}
window.onload = function(){
var fooArr = [], barArr = [], bazArr = [];
var options = {
zoom: 9
, center: new google.maps.LatLng(18.2, -66.3)
, mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), options);
var southWest = new google.maps.LatLng(17.85, -67.35);
var northEast = new google.maps.LatLng(18.55, -65.2);
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
for(var i=1; i<=1000; i++){
var lat = southWest.lat() + latSpan * Math.random();
var lng = southWest.lng() + lngSpan * Math.random();
var latlng = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
position: latlng
});
if((i%3) == 0){ bazArr.push(marker); }
else if((i%2) == 0){ barArr.push(marker); }
else{ fooArr.push(marker); }
}
document.getElementById('foo').checked = true;
for(var i in fooArr){
fooArr[i].setMap(map);
}
addListener(document.getElementById('foo'), 'click', function(){
if(this.checked){
for(var i in fooArr){
fooArr[i].setMap(map);
}
}else{
for(var i in fooArr){
fooArr[i].setMap(null);
}
}
});
addListener(document.getElementById('bar'), 'click', function(){
if(this.checked){
for(var i in barArr){
barArr[i].setMap(map);
}
}else{
for(var i in barArr){
barArr[i].setMap(null);
}
}
});
addListener(document.getElementById('baz'), 'click', function(){
if(this.checked){
for(var i in bazArr){
bazArr[i].setMap(map);
}
}else{
for(var i in bazArr){
bazArr[i].setMap(null);
}
}
});
};
<form action="index.html" method="get"> <input type="checkbox" id="foo" name="fooBarBaz" /> <label for="foo">Foo
</label> <input type="checkbox" id="bar" name="fooBarBaz" /> <label for="bar">Bar
</label> <input type="checkbox" id="baz" name="fooBarBaz" /> <label for="baz">Baz
</label>