-
-
Save anonymous/3516bda53dfa41ce49f4 to your computer and use it in GitHub Desktop.
My Js code for the v2 site.
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
$(document).ready(function () { | |
function getJSON(name) { | |
var json = null; | |
$.ajax({ | |
'async': false, | |
'global': false, | |
'url': "static/data/" + name, | |
'dataType': "json", | |
'success': function (data) { | |
json = data; | |
} | |
}); | |
return json; | |
} | |
var locationJson; | |
var localS = localStorage; | |
if (localS && localS.getItem("locationjson") !== null) { | |
locationJson = $.parseJSON(localS.getItem("locationjson")); | |
} else { | |
locationJson = getJSON("newLocations.json"); | |
localS.setItem("locationjson", JSON.stringify(locationJson)); | |
} | |
var Locationlat = 40.522446; | |
var Locationlon = -74.45574; | |
$(".typeahead").typeahead({ | |
name: "Locations", | |
prefetch: "static/data/locationList.json", | |
limit: 15 | |
}); | |
$(".typeahead.input-sm").siblings("input.tt-hint").addClass("hint-small"); | |
$(".typeahead.input-lg").siblings("input.tt-hint").addClass("hint-large"); | |
$(".typeahead").bind("typeahead:selected", function (e, t) { | |
v2LocationSearch(t.value); | |
}); | |
function v2LocationSearch(Location) { | |
alert(Location); | |
$.each(locationJson.Locations.Location, function (i, data) { | |
var locName = data.LocationName; | |
if (locName === Location) { | |
Locationlat = parseFloat(data.LocationLat); | |
Locationlon = parseFloat(data.LocationLon); | |
} | |
}); | |
resetLayer(); | |
} | |
var overlay, cartoDBImageMapType, map, user = "willkara", | |
table = "locations", | |
table1 = "lotcsv", | |
radius = 350, | |
radDeg = 0, | |
zoom = 14, | |
lat = Locationlat, | |
lng = Locationlon; | |
var sql = "SELECT * FROM " + table1 + " WHERE ST_Intersects( the_geom, ST_Buffer( ST_SetSRID('POINT(" + lng + " " + lat + ")'::geometry , 4326)" | |
var cartoDBLayer = { | |
getTileUrl: function (coord, zoom) { | |
return "https://" + user + ".cartodb.com/tiles/" + table1 + "/" + zoom + "/" + coord.x + "/" + coord.y + ".png?sql=" + sql + "," + radDeg + "))"; | |
}, | |
tileSize: new google.maps.Size(256, 256) | |
}; | |
var resetLayer = function () { | |
cartoDBImageMapType = new google.maps.ImageMapType(cartoDBLayer); | |
map.overlayMapTypes.insertAt(0, cartoDBImageMapType); | |
map.overlayMapTypes.pop(1); | |
}; | |
var drawCircle = function () { | |
if (overlay) | |
overlay.setMap(null); | |
overlay = new google.maps.Circle({ | |
map: map, | |
center: new google.maps.LatLng(lat, lng), | |
radius: radius, | |
strokeColor: "#FF0000", | |
strokeOpacity: 0.35, | |
strokeWeight: 3, | |
fillColor: "#FF0000", | |
fillOpacity: 0.050, | |
}); | |
} | |
var updateRadDeg = function (dist) { | |
var | |
deg = 180, | |
brng = deg * Math.PI / 180, | |
dist = dist / 6371000, | |
lat1 = lat * Math.PI / 180, | |
lon1 = lng * Math.PI / 180; | |
var lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist) + | |
Math.cos(lat1) * Math.sin(dist) * Math.cos(brng)); | |
var lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(dist) * Math.cos(lat1), Math.cos(dist) - | |
Math.sin(lat1) * Math.sin(lat2)); | |
if (isNaN(lat2) || isNaN(lon2)) | |
return null; | |
radDeg = lat - (lat2 * 180 / Math.PI); | |
} | |
updateRadDeg(radius); | |
$(function () { | |
var cartodbMapOptions = { | |
zoom: zoom, | |
disableDefaultUI: true, | |
center: new google.maps.LatLng(lat, lng), | |
mapTypeId: google.maps.MapTypeId.SATELLITE | |
}; | |
map = new google.maps.Map(document.getElementById("map"), cartodbMapOptions); | |
var mapStyle = [{ | |
stylers: [{ | |
saturation: -65 | |
}, { | |
gamma: 1.52 | |
}] | |
}, { | |
featureType: "administrative", | |
stylers: [{ | |
saturation: -95 | |
}, { | |
gamma: 2.26 | |
}] | |
}, { | |
featureType: "water", | |
elementType: "labels", | |
stylers: [{ | |
visibility: "off" | |
}] | |
}, { | |
featureType: "administrative.locality", | |
stylers: [{ | |
visibility: 'off' | |
}] | |
}, { | |
featureType: "road", | |
stylers: [{ | |
visibility: "simplified" | |
}, { | |
saturation: -99 | |
}, { | |
gamma: 2.22 | |
}] | |
}, { | |
featureType: "poi", | |
elementType: "labels", | |
stylers: [{ | |
visibility: "off" | |
}] | |
}, { | |
featureType: "road.arterial", | |
stylers: [{ | |
visibility: 'off' | |
}] | |
}, { | |
featureType: "road.local", | |
elementType: "labels", | |
stylers: [{ | |
visibility: 'off' | |
}] | |
}, { | |
featureType: "transit", | |
stylers: [{ | |
visibility: 'off' | |
}] | |
}, { | |
featureType: "road", | |
elementType: "labels", | |
stylers: [{ | |
visibility: 'off' | |
}] | |
}, { | |
featureType: "poi", | |
stylers: [{ | |
saturation: -55 | |
}] | |
}]; | |
map.setOptions({ | |
styles: mapStyle | |
}); | |
drawCircle(); | |
map.overlayMapTypes.insertAt(0, new google.maps.ImageMapType(cartoDBLayer)); | |
$('.distance').mouseup(function () { | |
radius = parseInt($(this).val()); | |
updateRadDeg(radius); | |
resetLayer(); | |
drawCircle(); | |
}); | |
$('.distance').change(function () { | |
radius = parseInt($(this).val()); | |
updateRadDeg(radius); | |
drawCircle(); | |
}); | |
}); | |
}); | |
$(document).ready(function () { | |
$("body").raptorize(); | |
}); | |
(function ($) { | |
jQuery.browser = {}; | |
jQuery.browser.mozilla = /mozilla/.test(navigator.userAgent.toLowerCase()) && !/webkit/.test(navigator.userAgent.toLowerCase()); | |
jQuery.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase()); | |
$.fn.raptorize = function (options) { | |
var defaults = { | |
enterOn: 'konami-code' | |
}; | |
var options = $.extend(defaults, options); | |
return this.each(function () { | |
var _this = $(this); | |
var audioSupported = false; | |
if ($.browser.mozilla || $.browser.webkit) { | |
audioSupported = true; | |
} | |
var raptorImageMarkup = '<img id="elRaptor" style="display: none" src="static/raptor/raptor.png" />' | |
var raptorAudioMarkup = '<audio id="elRaptorShriek" preload="auto"><source src="static/raptor/raptor-sound.mp3" /><source src="static/raptor/raptor-sound.ogg" /></audio>'; | |
var locked = false; | |
$('body').append(raptorImageMarkup); | |
if (audioSupported) { | |
$('body').append(raptorAudioMarkup); | |
} | |
var raptor = $('#elRaptor').css({ | |
"position": "fixed", | |
"bottom": "-300px", | |
"right": "0", | |
"display": "none" | |
}); | |
function init() { | |
$('body').css('bgcolor', 'black !important'); | |
locked = true; | |
$(window).scrollTop(9999999); | |
var raptor = $('#elRaptor').css({ | |
"display": "block" | |
}); | |
if (audioSupported) { | |
function playSound() { | |
document.getElementById('elRaptorShriek').play(); | |
} | |
playSound(); | |
} | |
raptor.animate({ | |
"bottom": "0px" | |
}, function () { | |
$(this).animate({ | |
"bottom": "0px" | |
}, 100, function () { | |
var offset = (($(this).position().left) + 400); | |
$(this).delay(300).animate({ | |
"right": offset | |
}, 2200, function () { | |
locked = false; | |
}) | |
}); | |
}); | |
} | |
if (options.enterOn == 'timer') { | |
setTimeout(init, options.delayTime); | |
} else if (options.enterOn == 'click') { | |
_this.bind('click', function (e) { | |
e.preventDefault(); | |
if (!locked) { | |
init(); | |
} | |
}) | |
} else if (options.enterOn == 'konami-code') { | |
var kkeys = [], | |
konami = "38,38,40,40,37,39,37,39,66,65"; | |
$(window).bind("keydown.raptorz", function (e) { | |
kkeys.push(e.keyCode); | |
if (kkeys.toString().indexOf(konami) >= 0) { | |
init(); | |
$(window).unbind('keydown.raptorz'); | |
} | |
}); | |
} | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment