From e09e4a8e24e5daf899d24314d0ffc218bbb2a97d Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 1 Jun 2012 11:51:16 -0700 Subject: Fixing Google Map component Pulled in from components branch. --- node_modules/montage-google/map.reel/map.js | 82 ++++++++++++++++------------- 1 file changed, 46 insertions(+), 36 deletions(-) (limited to 'node_modules/montage-google') 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/ didCreate: { value: function() { var self = this; + + this._latLng = this.defaultLatLng; window.initialize = function initialize() { - console.log('google maps api loaded'); self._mapLoaded = true; self._geoCoder = new google.maps.Geocoder(); self.needsDraw = true; @@ -32,7 +33,10 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ _geoCoder: {value: null}, // HTMLElement to load the Map into - mapEl: {value: null}, + mapEl: { + serializable: true, + value: null + }, _mapLoaded: { enumerable: false, @@ -49,9 +53,9 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ }, _latLng: { - value: this.defaultLatLng, - distinct: true + value: null }, + latLng: { get: function() { return this._latLng; @@ -67,6 +71,7 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ // {lat, lon} Or a String representing the location (eg: Paris, France) center: { + serializable: true, get: function() { return this._center; }, @@ -78,10 +83,12 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ if(String.isString(value)) { // geocode + self.LatLng = null; geocoder.geocode( { 'address': value}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var loc = results[0].geometry.location; self.latLng = {lat: loc.lat(), lng: loc.lng()}; + self.category = self._category; } else { console.log('Geocode was not successful : ' + status); } @@ -101,15 +108,17 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ }, category: { + serializable: true, get: function() { return this._category; }, set: function(value) { - console.log('category set: ' + value); if(value) { this._category = value; - this._getPlaces(this._category); - this.needsDraw = true; + if (this._mapLoaded && this.latLng) { + this._getPlaces(this._category); + this.needsDraw = true; + } } } }, @@ -159,12 +168,12 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ } var service = new google.maps.places.PlacesService(this._map); service.search(request, function(results, status) { - console.log('got places for ', self.category, status, results); if (status == google.maps.places.PlacesServiceStatus.OK) { self._places = results; } else { self._places = []; } + self.needsDraw = true; }); } }, @@ -252,35 +261,36 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ }; this._map = new window.google.maps.Map(this.mapEl, myOptions); - } else { - var map = this._map; - map.setZoom(10); - var latLng = new window.google.maps.LatLng(latLng.lat, latLng.lng); - map.setCenter(latLng); - var marker = new google.maps.Marker({ - map: map, - position: latLng - }); - - var places = this._places; - if(places && places.length > 0) { - map.setZoom(13); - this._removeAllMarkers(); - for (var i = 0; i < places.length; i++) { - this._createMarker(places[i]); - } - } - - if(this.traffic === true) { - this.trafficLayer = new google.maps.TrafficLayer(); - this.trafficLayer.setMap(map); - } else { - if(this.trafficLayer) { - this.trafficLayer.setMap(null); - } - } + this.center = this._center; + this.category = this._category; + } + + var map = this._map; + map.setZoom(10); + var latLng = new window.google.maps.LatLng(latLng.lat, latLng.lng); + map.setCenter(latLng); + var marker = new google.maps.Marker({ + map: map, + position: latLng + }); + + var places = this._places; + if(places && places.length > 0) { + map.setZoom(13); + this._removeAllMarkers(); + for (var i = 0; i < places.length; i++) { + this._createMarker(places[i]); + } } + if(this.traffic === true) { + this.trafficLayer = new google.maps.TrafficLayer(); + this.trafficLayer.setMap(map); + } else { + if(this.trafficLayer) { + this.trafficLayer.setMap(null); + } + } } //window.google.maps.event.addDomListener(window, 'load', initialize); @@ -294,4 +304,4 @@ var Map = exports.Map = Montage.create(Component, /** @lends module:"montage/ui/ serializer.set("center", this.center); } } -}); +}); \ No newline at end of file -- cgit v1.2.3