Skip to content

Instantly share code, notes, and snippets.

@amelialaundy
Created September 19, 2014 04:31
Show Gist options
  • Save amelialaundy/4188b3e6c9d9e34236e0 to your computer and use it in GitHub Desktop.
Save amelialaundy/4188b3e6c9d9e34236e0 to your computer and use it in GitHub Desktop.
unrefactored_js
function View() {
this.searchButton = document.querySelector(".search-button")
this.tagSpace = document.querySelector("#tag-space")
this.map = null
this.lat = 51.5072
this.lng = 0.1275
this.zoom = 2
this.address = null
}
View.prototype = {
// initialize function is given by google maps
initialize: function() {
mapOptions = {
center: new google.maps.LatLng(this.lat, this.lng),
zoom: this.zoom
}
this.map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
},
renderMarkers: function(image) {
var markerOneOptions = {
map: this.map,
zoom: 8,
position: new google.maps.LatLng(image.lat, image.lng),
clickable: true,
title: image.url
};
var contentString = "<div id='img-info'><img src='"+image.url+"'/><p>"+image.username+"</p></div>";
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var markerOne = new google.maps.Marker( markerOneOptions)
google.maps.event.addListener(markerOne, 'click', function() {
infowindow.open(this.map,markerOne);
});
},
getLatLng: function(lat, lng) {
this.lat = lat;
this.lng = lng;
this.map.setCenter({lat: this.lat, lng: this.lng})
this.map.setZoom(15)
return {
lat: this.lat,
lng: this.lng
};
},
getAddress: function() {
this.address = $('#address-search-bar').val();
return {
address: this.address
};
},
renderTags: function(tags) {
$.each(tags, function(i, tag){
string = "<p>"+tag+"</p>"
$(this.tagSpace).append(string);
}.bind(this))
},
renderClassifiedResult: function(results) {
$(this.tagSpace).html("");
var topics = results["cls1"]
// below returns the largest value, not the key in the topics hash
var max = Math.max.apply(null,
Object.keys(topics).map(function(k) {
return topics[k];
}));
// console.log(max)
var max_key = null
$.each(topics, function(i, topic){
if (topic === max) {
max_key = i
}
})
var stringMaxKey = ("<h3>The current most popular type of tag at this location is:</h3><p>"+ max_key+"</p>")
$(this.tagSpace).append(stringMaxKey);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment