aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage-google/map.reel
diff options
context:
space:
mode:
authorValerio Virgillito2012-06-05 13:49:59 -0700
committerValerio Virgillito2012-06-05 13:49:59 -0700
commit9a429f22a958fe372309e241c480923b7462d426 (patch)
tree56273e3769c18c5623f9e8671f73189a75ad372a /node_modules/montage-google/map.reel
parent73a62c95b5635fee903457279f0f5b57f164e0b5 (diff)
parentfe376077b6e24bb01905cd83226912e25b043308 (diff)
downloadninja-9a429f22a958fe372309e241c480923b7462d426.tar.gz
Merge pull request #263 from joseeight/Components
Saving Google Components (reel components)
Diffstat (limited to 'node_modules/montage-google/map.reel')
-rw-r--r--node_modules/montage-google/map.reel/map.js96
1 files changed, 57 insertions, 39 deletions
diff --git a/node_modules/montage-google/map.reel/map.js b/node_modules/montage-google/map.reel/map.js
index fc104df5..4e3a6d70 100644
--- a/node_modules/montage-google/map.reel/map.js
+++ b/node_modules/montage-google/map.reel/map.js
@@ -20,10 +20,11 @@ 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 }
@@ -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._map && this.latLng) {
112 this.needsDraw = true; 119 this._getPlaces(this._category);
120 this.needsDraw = true;
121 }
113 } 122 }
114 } 123 }
115 }, 124 },
@@ -130,7 +139,7 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/
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},
@@ -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 },
@@ -240,9 +249,17 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/
240 draw: { 249 draw: {
241 enumerable: false, 250 enumerable: false,
242 value: function () { 251 value: function () {
243
244 if(this._mapLoaded) { 252 if(this._mapLoaded) {
245 var latLng = this.latLng || this.defaultLatLng; 253 var latLng = this.latLng;
254
255 if (!latLng) {
256 if (this._center) {
257 return;
258 } else {
259 latLng = this.defaultLatLng;
260 }
261 }
262
246 if(!this._map) { 263 if(!this._map) {
247 var map; 264 var map;
248 var myOptions = { 265 var myOptions = {
@@ -252,35 +269,36 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/
252 }; 269 };
253 270
254 this._map = new window.google.maps.Map(this.mapEl, myOptions); 271 this._map = new window.google.maps.Map(this.mapEl, myOptions);
255 } else { 272 this.center = this._center;
256 var map = this._map; 273 this.category = this._category;
257 map.setZoom(10);
258 var latLng = new window.google.maps.LatLng(latLng.lat, latLng.lng);
259 map.setCenter(latLng);
260 var marker = new google.maps.Marker({
261 map: map,
262 position: latLng
263 });
264
265 var places = this._places;
266 if(places && places.length > 0) {
267 map.setZoom(13);
268 this._removeAllMarkers();
269 for (var i = 0; i < places.length; i++) {
270 this._createMarker(places[i]);
271 }
272 }
273
274 if(this.traffic === true) {
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 } 274 }
283 275
276 var map = this._map;
277 //map.setZoom(10);
278 var latLng = new window.google.maps.LatLng(latLng.lat, latLng.lng);
279 map.setCenter(latLng);
280 var marker = new google.maps.Marker({
281 map: map,
282 position: latLng
283 });
284
285 var places = this._places;
286 if(places && places.length > 0) {
287 //map.setZoom(13);
288 this._removeAllMarkers();
289 for (var i = 0; i < places.length; i++) {
290 this._createMarker(places[i]);
291 }
292 }
293
294 if(this.traffic === true) {
295 this.trafficLayer = new google.maps.TrafficLayer();
296 this.trafficLayer.setMap(map);
297 } else {
298 if(this.trafficLayer) {
299 this.trafficLayer.setMap(null);
300 }
301 }
284 } 302 }
285