Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 11 — Building a Community Site 221


var newlng = lngpoints[0] + ((lngpoints[lngpoints.length-1] - ;
lngpoints[0])/2);


var newpoint = new GPoint(parseFloat(newlng),parseFloat(newlat));

var idealspan = new GSize(parseFloat(Math.abs(lngpoints ;
[lngpoints.length-1]-lngpoints[0])),
parseFloat(Math.abs(latpoints ;
[latpoints.length-1]-latpoints[0])));


map.zoomTo(1);
var idealzoom = 1;

for(var i=1;i<16;i++) {
var currentsize = map.getSpanLatLng();
if ((currentsize.width < idealspan.width) ||
(currentsize.height < idealspan.height)) {
map.zoomTo(i);
idealzoom = i;
} else {
break;
}
}

map.centerAndZoom(newpoint,idealzoom);
}


One of the benefits of the using the global array of all the objects on the map is that the map is
recentered according to all of the entities displayed, not just the most recently added entities to
the map.


Closing HTML


The closing HTML provides the structure for the page, incorporating the same map-on-the-
right, info-panel-on-the-left structure used before:


//]]>












Free download pdf