diff options
Diffstat (limited to 'node_modules/montage-google/map.reel/map.js')
-rw-r--r-- | node_modules/montage-google/map.reel/map.js | 150 |
1 files changed, 88 insertions, 62 deletions
diff --git a/node_modules/montage-google/map.reel/map.js b/node_modules/montage-google/map.reel/map.js index 3ba7fff7..4e3a6d70 100644 --- a/node_modules/montage-google/map.reel/map.js +++ b/node_modules/montage-google/map.reel/map.js | |||
@@ -20,20 +20,24 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
20 | didCreate: { | 20 | didCreate: { |
21 | value: function() { | 21 | value: function() { |
22 | var self = this; | 22 | var self = this; |
23 | |||
23 | window.initialize = function initialize() { | 24 | window.initialize = function initialize() { |
24 | console.log('google maps api loaded'); | ||
25 | self._mapLoaded = true; | 25 | self._mapLoaded = true; |
26 | self._geoCoder = new google.maps.Geocoder(); | 26 | self._geoCoder = new google.maps.Geocoder(); |
27 | self.center = self._center; | ||
27 | self.needsDraw = true; | 28 | self.needsDraw = true; |
28 | }; | 29 | }; |
29 | } | 30 | } |
30 | }, | 31 | }, |
31 | 32 | ||
32 | _geoCoder: {value: null}, | 33 | _geoCoder: {value: null}, |
33 | 34 | ||
34 | // HTMLElement to load the Map into | 35 | // HTMLElement to load the Map into |
35 | mapEl: {value: null}, | 36 | mapEl: { |
36 | 37 | serializable: true, | |
38 | value: null | ||
39 | }, | ||
40 | |||
37 | _mapLoaded: { | 41 | _mapLoaded: { |
38 | enumerable: false, | 42 | enumerable: false, |
39 | value: false | 43 | value: false |
@@ -42,16 +46,16 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
42 | enumerable: false, | 46 | enumerable: false, |
43 | value: false | 47 | value: false |
44 | }, | 48 | }, |
45 | 49 | ||
46 | // Sunnyvale, CA | 50 | // Sunnyvale, CA |
47 | defaultLatLng: { | 51 | defaultLatLng: { |
48 | value: {lat: 37.37, lng: -122.03} | 52 | value: {lat: 37.37, lng: -122.03} |
49 | }, | 53 | }, |
50 | 54 | ||
51 | _latLng: { | 55 | _latLng: { |
52 | value: this.defaultLatLng, | 56 | value: null |
53 | distinct: true | ||
54 | }, | 57 | }, |
58 | |||
55 | latLng: { | 59 | latLng: { |
56 | get: function() { | 60 | get: function() { |
57 | return this._latLng; | 61 | return this._latLng; |
@@ -67,6 +71,7 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
67 | 71 | ||
68 | // {lat, lon} Or a String representing the location (eg: Paris, France) | 72 | // {lat, lon} Or a String representing the location (eg: Paris, France) |
69 | center: { | 73 | center: { |
74 | serializable: true, | ||
70 | get: function() { | 75 | get: function() { |
71 | return this._center; | 76 | return this._center; |
72 | }, | 77 | }, |
@@ -75,13 +80,15 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
75 | var self = this, geocoder = this._geoCoder; | 80 | var self = this, geocoder = this._geoCoder; |
76 | this._center = value; | 81 | this._center = value; |
77 | if(this._mapLoaded) { | 82 | if(this._mapLoaded) { |
78 | 83 | ||
79 | if(String.isString(value)) { | 84 | if(String.isString(value)) { |
80 | // geocode | 85 | // geocode |
86 | self.LatLng = null; | ||
81 | geocoder.geocode( { 'address': value}, function(results, status) { | 87 | geocoder.geocode( { 'address': value}, function(results, status) { |
82 | if (status == google.maps.GeocoderStatus.OK) { | 88 | if (status == google.maps.GeocoderStatus.OK) { |
83 | var loc = results[0].geometry.location; | 89 | var loc = results[0].geometry.location; |
84 | self.latLng = {lat: loc.lat(), lng: loc.lng()}; | 90 | self.latLng = {lat: loc.lat(), lng: loc.lng()}; |
91 | self.category = self._category; | ||
85 | } else { | 92 | } else { |
86 | console.log('Geocode was not successful : ' + status); | 93 | console.log('Geocode was not successful : ' + status); |
87 | } | 94 | } |
@@ -92,28 +99,30 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
92 | // default location | 99 | // default location |
93 | this.latLng = this.defaultLatLng; | 100 | this.latLng = this.defaultLatLng; |
94 | } | 101 | } |
95 | 102 | ||
96 | } | 103 | } |
97 | 104 | ||
98 | } | 105 | } |
99 | 106 | ||
100 | } | 107 | } |
101 | }, | 108 | }, |
102 | 109 | ||
103 | category: { | 110 | category: { |
111 | serializable: true, | ||
104 | get: function() { | 112 | get: function() { |
105 | return this._category; | 113 | return this._category; |
106 | }, | 114 | }, |
107 | set: function(value) { | 115 | set: function(value) { |
108 | console.log('category set: ' + value); | ||
109 | if(value) { | 116 | if(value) { |
110 | this._category = value; | 117 | this._category = value; |
111 | this._getPlaces(this._category); | 118 | if (this._map && this.latLng) { |
112 | this.needsDraw = true; | 119 | this._getPlaces(this._category); |
120 | this.needsDraw = true; | ||
121 | } | ||
113 | } | 122 | } |
114 | } | 123 | } |
115 | }, | 124 | }, |
116 | 125 | ||
117 | trafficLayer: {value: null}, | 126 | trafficLayer: {value: null}, |
118 | _traffic: {value: null}, | 127 | _traffic: {value: null}, |
119 | traffic: { | 128 | traffic: { |
@@ -127,12 +136,12 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
127 | } | 136 | } |
128 | } | 137 | } |
129 | }, | 138 | }, |
130 | 139 | ||
131 | 140 | ||
132 | zoomValue: { | 141 | zoomValue: { |
133 | value: 8 | 142 | value: 13 |
134 | }, | 143 | }, |
135 | 144 | ||
136 | __places: {value: null}, | 145 | __places: {value: null}, |
137 | _places: { | 146 | _places: { |
138 | get: function() { | 147 | get: function() { |
@@ -145,11 +154,11 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
145 | } | 154 | } |
146 | } | 155 | } |
147 | }, | 156 | }, |
148 | 157 | ||
149 | _getPlaces: { | 158 | _getPlaces: { |
150 | value: function(type, keyword) { | 159 | value: function(type, keyword) { |
151 | var self = this; | 160 | var self = this; |
152 | var request = { | 161 | var request = { |
153 | location: new window.google.maps.LatLng(this.latLng.lat, this.latLng.lng), | 162 | location: new window.google.maps.LatLng(this.latLng.lat, this.latLng.lng), |
154 | radius: 5000, | 163 | radius: 5000, |
155 | types: [type] | 164 | types: [type] |
@@ -159,16 +168,16 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
159 | } | 168 | } |
160 | var service = new google.maps.places.PlacesService(this._map); | 169 | var service = new google.maps.places.PlacesService(this._map); |
161 | service.search(request, function(results, status) { | 170 | service.search(request, function(results, status) { |
162 | console.log('got places for ', self.category, status, results); | ||
163 | if (status == google.maps.places.PlacesServiceStatus.OK) { | 171 | if (status == google.maps.places.PlacesServiceStatus.OK) { |
164 | self._places = results; | 172 | self._places = results; |
165 | } else { | 173 | } else { |
166 | self._places = []; | 174 | self._places = []; |
167 | } | 175 | } |
176 | self.needsDraw = true; | ||
168 | }); | 177 | }); |
169 | } | 178 | } |
170 | }, | 179 | }, |
171 | 180 | ||
172 | _infoWindow: {value: null}, | 181 | _infoWindow: {value: null}, |
173 | _markers: {value: null}, | 182 | _markers: {value: null}, |
174 | _createMarker: { | 183 | _createMarker: { |
@@ -192,20 +201,20 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
192 | icon = '41-picture-frame.png'; | 201 | icon = '41-picture-frame.png'; |
193 | break; | 202 | break; |
194 | case 'gas_station': | 203 | case 'gas_station': |
195 | icon = '47-fuel.png'; | 204 | icon = '47-fuel.png'; |
196 | break; | 205 | break; |
197 | }; | 206 | }; |
198 | if(icon) { | 207 | if(icon) { |
199 | image = new google.maps.MarkerImage('images/' + icon); | 208 | image = new google.maps.MarkerImage('images/' + icon); |
200 | } | 209 | } |
201 | var options = { | 210 | var options = { |
202 | map: map, | 211 | map: map, |
203 | position: place.geometry.location | 212 | position: place.geometry.location |
204 | }; | 213 | }; |
205 | if(image) { | 214 | if(image) { |