flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - JavaScript version of maps.google.Map now dynamically/asynchrously loads the Google Map API so there is no need to include the <script> tag in the index.html any longer.
Date Wed, 14 May 2014 20:21:49 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop 5c12cc72d -> c9d4b2f4a


JavaScript version of maps.google.Map now dynamically/asynchrously loads the Google Map API
so there is no need to include the <script> tag in the index.html any longer.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c9d4b2f4
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c9d4b2f4
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c9d4b2f4

Branch: refs/heads/develop
Commit: c9d4b2f4a597fc0b61be0e8fd06cb9c728e6912e
Parents: 5c12cc7
Author: Peter Ent <pent@apache.org>
Authored: Wed May 14 16:21:38 2014 -0400
Committer: Peter Ent <pent@apache.org>
Committed: Wed May 14 16:21:38 2014 -0400

----------------------------------------------------------------------
 .../src/org/apache/flex/maps/google/Map.as      |  2 ++
 .../apache/flex/maps/google/beads/MapView.as    |  2 ++
 .../src/org/apache/flex/maps/google/Map.js      | 32 +++++++++++++++-----
 3 files changed, 29 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9d4b2f4/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as
index 56ab358..1ada5f7 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as
@@ -23,6 +23,8 @@ package org.apache.flex.maps.google
 	import org.apache.flex.core.ValuesManager;
 	import org.apache.flex.maps.google.beads.MapView;
 	
+	[Event(name="ready", type="org.apache.flex.events.Event")]
+	
 	/**
 	 *  The Map class displays a Google Map centered on lat/lng coordinates. The Map uses
 	 *  the following bead type:

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9d4b2f4/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as
b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as
index 879a9fb..05e5f49 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as
@@ -78,6 +78,7 @@ package org.apache.flex.maps.google.beads
 			
 			if (page) {
 				_loader.loadString(page);
+				IEventDispatcher(_strand).dispatchEvent(new Event("ready"));
 			}
 		}
 		
@@ -100,6 +101,7 @@ package org.apache.flex.maps.google.beads
 			
 			if (_loader) {
 				_loader.loadString(page);
+				IEventDispatcher(_strand).dispatchEvent(new Event("ready"));
 			}
 		}
 		

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c9d4b2f4/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js b/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js
index 23c622d..b10d1a2 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js
@@ -27,6 +27,7 @@ goog.provide('org.apache.flex.maps.google.Map');
  */
 org.apache.flex.maps.google.Map = function() {
   goog.base(this);
+  this.initialized = false;
 };
 goog.inherits(org.apache.flex.maps.google.Map,
     org.apache.flex.core.UIBase);
@@ -54,8 +55,23 @@ org.apache.flex.maps.google.Map.prototype.createElement =
  * @param {String} value Google API dev token.
  */
 org.apache.flex.maps.google.Map.prototype.set_token = function(value) {
-  // not used in JavaScript version as Google API token is processed
-  // in the main HTML index file.
+  var script = document.createElement('script');
+  script.type = 'text/javascript';
+  script.src = 'https://maps.googleapis.com/maps/api/js?key=' + value + '&sensor=false'
+
+              '&callback=mapInit';
+  window.mapView = this;
+  window.mapInit = function() {
+      this.mapView.finishInitalization();
+    };
+  document.body.appendChild(script);
+};
+
+
+/**
+ */
+org.apache.flex.maps.google.Map.prototype.finishInitalization = function() {
+  this.initialized = true;
+  this.dispatchEvent('ready');
 };
 
 
@@ -67,9 +83,11 @@ org.apache.flex.maps.google.Map.prototype.set_token = function(value) {
  */
 org.apache.flex.maps.google.Map.prototype.loadMap =
     function(centerLat, centerLong, zoom) {
-  var mapOptions = {
-    center: new google.maps.LatLng(centerLat, centerLong),
-    zoom: zoom
-  };
-  this.map = new google.maps.Map(this.element, mapOptions);
+  if (this.initialized) {
+    var mapOptions = {
+      center: new google.maps.LatLng(centerLat, centerLong),
+      zoom: zoom
+    };
+    this.map = new google.maps.Map(this.element, mapOptions);
+  }
 };


Mime
View raw message