diff options
Diffstat (limited to 'node_modules/montage-google')
-rw-r--r-- | node_modules/montage-google/map.reel/map.js | 82 |
1 files changed, 46 insertions, 36 deletions
diff --git a/node_modules/montage-google/map.reel/map.js b/node_modules/montage-google/map.reel/map.js index fc104df5..879a80d4 100644 --- a/node_modules/montage-google/map.reel/map.js +++ b/node_modules/montage-google/map.reel/map.js | |||
@@ -20,8 +20,9 @@ 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 | |||
24 | this._latLng = this.defaultLatLng; | ||
23 | window.initialize = function initialize() { | 25 | window.initialize = function initialize() { |
24 | console.log('google maps api loaded'); | ||
25 | self._mapLoaded = true; | 26 | self._mapLoaded = true; |
26 | self._geoCoder = new google.maps.Geocoder(); | 27 | self._geoCoder = new google.maps.Geocoder(); |
27 | self.needsDraw = true; | 28 | self.needsDraw = true; |
@@ -32,7 +33,10 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
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: { |
37 | serializable: true, | ||
38 | value: null | ||
39 | }, | ||
36 | 40 | ||
37 | _mapLoaded: { | 41 | _mapLoaded: { |
38 | enumerable: false, | 42 | enumerable: false, |
@@ -49,9 +53,9 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
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 | }, |
@@ -78,10 +83,12 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
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 | } |
@@ -101,15 +108,17 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
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._mapLoaded && this.latLng) { |
112 | this.needsDraw = true; | 119 | this._getPlaces(this._category); |
120 | this.needsDraw = true; | ||
121 | } | ||
113 | } | 122 | } |
114 | } | 123 | } |
115 | }, | 124 | }, |
@@ -159,12 +168,12 @@ 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 | }, |
@@ -252,35 +261,36 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
252 | }; | 261 | }; |
253 | 262 | ||
254 | this._map = new window.google.maps.Map(this.mapEl, myOptions); | 263 | this._map = new window.google.maps.Map(this.mapEl, myOptions); |
255 | } else { | 264 | this.center = this._center; |
256 | var map = this._map; | 265 | this.category = this._category; |
257 | map.setZoom(10); | 266 | } |
258 | var latLng = new window.google.maps.LatLng(latLng.lat, latLng.lng); | 267 | |
259 | map.setCenter(latLng); | 268 | var map = this._map; |
260 | var marker = new google.maps.Marker({ | 269 | map.setZoom(10); |
261 | map: map, | 270 | var latLng = new window.google.maps.LatLng(latLng.lat, latLng.lng); |
262 | position: latLng | 271 | map.setCenter(latLng); |
263 | }); | 272 | var marker = new google.maps.Marker({ |
264 | 273 | map: map, | |
265 | var places = this._places; | 274 | position: latLng |
266 | if(places && places.length > 0) { | 275 | }); |
267 | map.setZoom(13); | 276 | |
268 | this._removeAllMarkers(); | 277 | var places = this._places; |
269 | for (var i = 0; i < places.length; i++) { | 278 | if(places && places.length > 0) { |
270 | this._createMarker(places[i]); | 279 | map.setZoom(13); |
271 | } | 280 | this._removeAllMarkers(); |
272 | } | 281 | for (var i = 0; i < places.length; i++) { |
273 | 282 | this._createMarker(places[i]); | |
274 | if(this.traffic === true) { | 283 | } |
275 | this.trafficLayer = new google.maps.TrafficLayer(); | ||
276 | this.trafficLayer.setMap(map); | ||
277 | } else { | ||
278 | if(this.trafficLayer) { | ||
279 | this.trafficLayer.setMap(null); | ||
280 | } | ||
281 | } | ||
282 | } | 284 | } |
283 | 285 | ||
286 | if(this.traffic === true) { | ||
287 | this.trafficLayer = new google.maps.TrafficLayer(); | ||
288 | this.trafficLayer.setMap(map); | ||
289 | } else { | ||
290 | if(this.trafficLayer) { | ||
291 | this.trafficLayer.setMap(null); | ||
292 | } | ||
293 | } | ||
284 | } | 294 | } |
285 | 295 | ||
286 | //window.google.maps.event.addDomListener(window, 'load', initialize); | 296 | //window.google.maps.event.addDomListener(window, 'load', initialize); |
@@ -294,4 +304,4 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ | |||
294 | serializer.set("center", this.center); | 304 | serializer.set("center", this.center); |
295 | } | 305 | } |
296 | } | 306 | } |
297 | }); | 307 | }); \ No newline at end of file |