Skip to content

Instantly share code, notes, and snippets.

@wboykinm
Created October 31, 2012 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wboykinm/3988690 to your computer and use it in GitHub Desktop.
Save wboykinm/3988690 to your computer and use it in GitHub Desktop.
switchmap.g.js
//Wax loads Layers into a GMaps wrapper:
var geocoder, map, interaction;
//Directs the click to the appropriate layer
$('td a').click(function() {
//Removes all button highlights then adds it to the active layer button
$('td a').removeClass('pressed')
$(this).addClass('pressed')
//Updates the legend with the new layer label:
$('div.switch-title').text("Marketing Scores for " + $(this).text())
//Pulls in the TileJSON of the selected layer
wax.tilejson($(this).attr('rel'), function(tilejson) {
//Defines the "search by address" function
geocoder = new google.maps.Geocoder();
//Sets map object parameters
var latlng = new google.maps.LatLng(39.0, -95);
var myOptions = {
zoom: 5,
maxZoom: 13,
center: latlng,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.HYBRID
};
//Adds selected layer overlay to map, with interaction (popups) included
if (!map) {
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
map.overlayMapTypes.insertAt(0, new wax.g.connector(tilejson));
// OLD // interaction = wax.g.interaction(map, tilejson);
interaction = wax.g.interaction().map(map).tilejson(tilejson).on(wax.tooltip().parent(map.getDiv()).events());
//Removes tiles and interactions of the previously-loaded layer
} else {
map.overlayMapTypes.setAt(0, new wax.g.connector(tilejson));
interaction.remove();
// OLD // interaction = wax.g.interaction(map, tilejson);
interaction = wax.g.interaction().map(map).tilejson(tilejson).on(wax.tooltip().parent(map.getDiv()).events());
}
});
});
//"Search by address" function:
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode({
address: address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(10);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
//"Clicks" on the first TileJSON entry when the page loads
$('td a.first').click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment