Created
October 2, 2013 16:33
-
-
Save tmcw/6796537 to your computer and use it in GitHub Desktop.
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
var YelpOn = false; | |
$(document).on('touchstart', 'li#Yelp', YelpEvent); | |
$("li#Yelp").on("touchstart click", function (e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
YelpEvent(); | |
}); | |
function YelpEvent(){ | |
if (YelpOn == true) { | |
$("li#Yelp").removeClass('active'); // Mark all as inactive | |
YelpOn = false; | |
ClearYelpResult(); | |
} | |
else { | |
$("li#Yelp").addClass('active'); // Mark link as active | |
YelpOn = true; | |
//ContactYelp(); | |
Yelpmarkers(); | |
} | |
} | |
var markerYelpLayer = L.mapbox.markerLayer() | |
.addTo(map); | |
markerYelpLayer.on('layeradd', function(e) { | |
var Yelpmarker = e.layer, | |
Yelpfeature = Yelpmarker.feature; | |
Yelpmarker.setIcon(L.icon(Yelpfeature.properties.icon)); | |
var popupYelp = '<h2>' + Yelpfeature.properties.name + '</h2>'; | |
markerYelpLayer.bindPopup(popupYelp,{ | |
closeButton: false, | |
minWidth: 75, | |
maxWidth: 100 | |
}); | |
}); | |
function Yelpmarkers() { | |
var term = "museum"; | |
var Bounds = map.getBounds().toBBoxString(); //produces a string with 4 values 'southwest_lng,southwest_lat,northeast_lng,northeast_lat | |
var north_lat = Bounds.substring(0,18); //substring used to get the value we need from Bounds. | |
var west_lng = Bounds.substring(19,36); | |
var south_lat = Bounds.substring(37,55); | |
var east_lng = Bounds.substring(56,75); | |
ContactYelp(term, north_lat, west_lng, south_lat, east_lng); | |
} | |
function ContactYelp(term, north_lat, west_lng, south_lat, east_lng) { | |
//showProgress("div#spinner"); | |
$.getJSON('http://api.yelp.com/business_review_search?term=' + term + '&tl_lat=' + west_lng + '&tl_long=' + north_lat + '&br_lat=' + east_lng + '&br_long=' + south_lat + '&limit=30&ywsid=7bX0EJj3ZMuwfumUQUyXrw&callback=?', | |
function (d) { | |
if (d.businesses.length == 0) { | |
alert("No Yelp result for this area."); | |
$("li#Yelp").removeClass('active'); // Mark all as inactive | |
YelpOn = false; | |
} else { | |
parseYelpResult(d); | |
//hideProgress("div#spinner"); | |
} | |
}); | |
} | |
function parseYelpResult(d) { | |
var newYelp = { | |
type: "FeatureCollection", | |
features: [] | |
}; | |
$.each(d.businesses, function (i, item) { | |
newYelp.features.push({ | |
type: "Feature", | |
geometry: { | |
type: "Point", | |
coordinates: [item.longitude, item.latitude] | |
}, | |
properties: { | |
name: item.name, | |
address1: item.address1, | |
city: item.city, | |
state: item.state, | |
rating_img_url: item.rating_img_url_small, | |
mobile_url: item.mobile_url, | |
review_count: item.review_count , | |
"icon": { | |
"iconUrl": "http://placekitten.com/100/100", | |
"iconSize": [50, 50], | |
"iconAnchor": [25, 25], | |
"popupAnchor": [0, -25] | |
} | |
} | |
}); | |
}); | |
markerYelpLayer.setGeoJSON(newYelp); | |
}; | |
function ClearYelpResult() { | |
markerYelpLayer.clearLayers(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment