Created
December 19, 2011 00:09
-
-
Save shaneshifflett/1494897 to your computer and use it in GitHub Desktop.
Fusion Tables GMAP Layer Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type='text/javascript' src='http://media.baycitizen.org/js/jquery-1.4.2.min.js'></script> | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
<script type="text/javascript" charset="utf-8"> | |
var ft_id = INSERT_FUSION_TABLE_ID; | |
function Legend(controlDiv, name, title) { | |
// Set CSS for the control border | |
var controlUI = document.createElement('DIV'); | |
controlUI.style.cursor = 'default'; | |
controlUI.style.textAlign = 'left'; | |
controlUI.title = title; | |
controlDiv.appendChild(controlUI); | |
var legendIcon = document.createElement('IMG'); | |
legendIcon.style.marginRight = '4px'; | |
legendIcon.src = 'PATH_TO_PNG_FILE'; | |
controlUI.appendChild(legendIcon); | |
// Set CSS for the control interior | |
var controlText = document.createElement('SPAN'); | |
controlText.style.fontfamily = 'Arial,sans-serif'; | |
controlText.style.fontSize = '12px'; | |
controlText.innerHTML = name; | |
controlUI.appendChild(controlText); | |
} | |
$(document).ready(function() { | |
var sf = new google.maps.LatLng(37.768137,-122.437649); | |
map = new google.maps.Map(document.getElementById('map'), { | |
center: sf, | |
zoom: 9, | |
mapTypeId: 'roadmap' | |
}); | |
layer = new google.maps.FusionTablesLayer(ft_id, { | |
//specify where clause to filter out empty rows | |
query: "SELECT 'geometry' FROM "+ft_id+" " | |
}); | |
layer.setOptions({suppressInfoWindows: false}); | |
layer.setMap(map); | |
legend = document.createElement('DIV'); | |
legend.style.padding = '5px'; | |
legend.style.marginRight = '5px'; | |
legend.style.backgroundColor = 'white'; | |
legend.style.borderStyle = 'solid'; | |
legend.style.borderWidth = '2px'; | |
var legendAtFault = document.createElement('DIV'); | |
new Legend(legendAtFault, '', 'legned'); | |
legend.appendChild(legendAtFault); | |
legend.index = 1; | |
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(legend); | |
//SPECIFY YOUR BOUNDARIES | |
var defaultSW = new google.maps.LatLng(37.068328,-122.536011) | |
var defaultNE = new google.maps.LatLng(38.573938,-121.49231) | |
var allowedBounds = new google.maps.LatLngBounds(defaultSW,defaultNE); | |
google.maps.event.addListener(map,'center_changed',function() { checkBounds(); }); | |
function checkBounds() { | |
if(! allowedBounds.contains(map.getCenter())) { | |
var C = map.getCenter(); | |
var X = C.lng(); | |
var Y = C.lat(); | |
var AmaxX = allowedBounds.getNorthEast().lng(); | |
var AmaxY = allowedBounds.getNorthEast().lat(); | |
var AminX = allowedBounds.getSouthWest().lng(); | |
var AminY = allowedBounds.getSouthWest().lat(); | |
if (X < AminX) {X = AminX;} | |
if (X > AmaxX) {X = AmaxX;} | |
if (Y < AminY) {Y = AminY;} | |
if (Y > AmaxY) {Y = AmaxY;} | |
map.setCenter(new google.maps.LatLng(Y,X)); | |
} | |
}//endfunc | |
}); | |
</script> | |
<div id="map" style="height:620px; width:550px;"></div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment