forked from xando/commitcoffee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
113 lines (87 loc) · 2.47 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var places = _.filter(places, "coordinates");
var App = angular
.module('CommitCoffee', [])
.config(['$locationProvider',function ($locationProvider) {
$locationProvider.html5Mode(true);
}]);
App.controller('Controller', function ($scope, $location, $anchorScroll) {
var mapOptions = {
center: new google.maps.LatLng(40, -10),
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(
document.getElementById("map-canvas"),
mapOptions
);
google.maps.event.addListener(map, 'tilesloaded', function() {
var lat0 = map.getBounds().getNorthEast().lat();
var lng0 = map.getBounds().getNorthEast().lng();
var lat1 = map.getBounds().getSouthWest().lat();
var lng1 = map.getBounds().getSouthWest().lng();
var locationPlaces = _.filter(places, function(p) {
if (lat1 <= parseFloat(p.coordinates[0]) &&
parseFloat(p.coordinates[0]) <= lat0 &&
lng1 <= parseFloat(p.coordinates[1]) &&
parseFloat(p.coordinates[1]) <= lng0) {
return true
}
return false
});
$scope.$apply(function(){
$scope.results = locationPlaces;
});
_.each(locationPlaces, function(location) {
var position = new google.maps.LatLng(
location.coordinates[0],
location.coordinates[1]
);
var marker = new google.maps.Marker({
map: map,
position: position,
location: location
});
google.maps.event.addListener(marker, 'click', function() {
self = this;
$scope.$apply(function(){
$scope.locationDetails = marker.location;
$scope.showDetails = 2;
$scope.mapsURL = encodeURIComponent(marker.location.coordinates.join(', '));
});
});
});
});
$scope.search = function () {
$location.hash('search');
// $anchorScroll();
var geocoder = new google.maps.Geocoder();
$scope.disabled = true;
geocoder.geocode({'address': $scope.location}, function(results, status) {
if (results.length > 0) {
map.panTo(results[0].geometry.location);
map.setZoom(14);
}
$scope.$apply(function(){
$scope.disabled = false;
});
});
}
$scope.clickedSomewhereElse = function($event) {
if ($scope.showDetails > 0) {
--$scope.showDetails;
}
}
});
App.directive('clickAnywhereButHere', function($document){
return {
restrict: 'A',
link: function(scope, elem, attr, ctrl) {
elem.bind('click', function(e) {
e.stopPropagation();
});
$document.bind('click', function() {
scope.$apply(attr.clickAnywhereButHere);
})
}
}
})