flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [3/3] git commit: [flex-asjs] [refs/heads/develop] - tweak map demo so token not required
Date Mon, 19 May 2014 04:43:54 GMT
tweak map demo so token not required


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

Branch: refs/heads/develop
Commit: 7dd59490f9f5dd7ea8cb3363aa28d3e551900647
Parents: d76d60e
Author: Alex Harui <aharui@apache.org>
Authored: Fri May 16 13:56:01 2014 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Fri May 16 13:56:01 2014 -0700

----------------------------------------------------------------------
 examples/DesktopMap/src/MyInitialView.mxml      |  2 +-
 frameworks/as/projects/FlexJSUI/defaults.css    |  5 ++
 .../src/org/apache/flex/maps/google/Map.as      | 18 ++---
 .../apache/flex/maps/google/beads/MapView.as    | 45 +++++-------
 .../src/org/apache/flex/maps/google/Map.js      | 32 +++++----
 .../apache/flex/maps/google/beads/MapView.js    | 73 ++++++++++++++++++++
 6 files changed, 123 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7dd59490/examples/DesktopMap/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/examples/DesktopMap/src/MyInitialView.mxml b/examples/DesktopMap/src/MyInitialView.mxml
index ede8f81..4cdfa10 100644
--- a/examples/DesktopMap/src/MyInitialView.mxml
+++ b/examples/DesktopMap/src/MyInitialView.mxml
@@ -97,6 +97,6 @@ limitations under the License.
 							dataProvider="{MyModel(applicationModel).cities}" />
 	</basic:Container>
 
-	<basic:Map id="map" x="150" y="25" width="300" height="300" token="--put your Google
API dev token here--" />
+	<basic:Map id="map" x="150" y="25" width="300" height="300" />
 
 </basic:ViewBase>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7dd59490/frameworks/as/projects/FlexJSUI/defaults.css
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/defaults.css b/frameworks/as/projects/FlexJSUI/defaults.css
index a36c6c5..d084258 100644
--- a/frameworks/as/projects/FlexJSUI/defaults.css
+++ b/frameworks/as/projects/FlexJSUI/defaults.css
@@ -99,6 +99,11 @@ List
     IItemRenderer: ClassReference("org.apache.flex.html.supportClasses.StringItemRenderer");
 }
 
+Map
+{
+    IBeadView: ClassReference("org.apache.flex.maps.google.beads.MapView");
+}
+
 SimpleList
 {
     IBeadModel: ClassReference("org.apache.flex.html.beads.models.ArraySelectionModel");

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7dd59490/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 1ada5f7..44ca927 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
@@ -64,13 +64,13 @@ package org.apache.flex.maps.google
 		public function set token(value:String):void
 		{
 			_token = value; 
-			
-			var viewBead:MapView = getBeadByType(IBeadView) as MapView;
-			if (viewBead == null) {
-				viewBead = new MapView();
-				viewBead.token = value;
-				addBead(viewBead);
-			}
+		}
+		/**
+		 * @private
+		 */
+		public function get token():String
+		{
+			return _token; 
 		}
 		
 		/**
@@ -85,10 +85,6 @@ package org.apache.flex.maps.google
 		public function loadMap( centerLat:Number, centerLong:Number, zoom:Number ) : void
 		{
 			var viewBead:MapView = getBeadByType(IBeadView) as MapView;
-			if (viewBead == null) {
-				viewBead = new MapView();
-				addBead(viewBead);
-			}
 			if (viewBead) {
 				viewBead.mapit(centerLat, centerLong, zoom);
 			}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7dd59490/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 05e5f49..e7d6eb6 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
@@ -26,6 +26,7 @@ package org.apache.flex.maps.google.beads
 	import org.apache.flex.core.IStrand;
 	import org.apache.flex.core.UIBase;
 	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.maps.google.Map;
 	
 	/**
 	 *  The MapView bead class displays a Google Map using HTMLLoader.
@@ -76,35 +77,19 @@ package org.apache.flex.maps.google.beads
 						
 			(_strand as UIBase).addChild(_loader);
 			
-			if (page) {
-				_loader.loadString(page);
-				IEventDispatcher(_strand).dispatchEvent(new Event("ready"));
-			}
-		}
-		
-		private var _token:String;
-		
-		/**
-		 *  Sets the API token and modifies the pageTemplate so that a proper
-		 *  HTML DOM can be constructed to house the Google Map.
-		 *  
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion FlexJS 0.0
-		 */
-		public function set token(value:String):void
-		{
-			_token = value;
+			var token:String = Map(_strand).token;
+			if (token)
+				page = pageTemplateStart + "&key=" + token + pageTemplateEnd;
+			else
+				page = pageTemplateStart + pageTemplateEnd;
 			
-			page = pageTemplate.replace("{Your-Google-Token-Here}",_token);
-			
-			if (_loader) {
+			if (page) {
 				_loader.loadString(page);
+				_loader.addEventListener(Event.COMPLETE, completeHandler);
 				IEventDispatcher(_strand).dispatchEvent(new Event("ready"));
 			}
 		}
-		
+				
 		private var page:String;
 		
 		/**
@@ -136,7 +121,7 @@ package org.apache.flex.maps.google.beads
 		 * This page definition is used with HTMLLoader to bring in the Google Maps
 		 * API (a Google APP token is required).
 		 */
-		private static var pageTemplate:String = '<!DOCTYPE html>'+
+		private static var pageTemplateStart:String = '<!DOCTYPE html>'+
 			'<html>'+
 			'  <head>'+
 			'    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />'+
@@ -146,7 +131,9 @@ package org.apache.flex.maps.google.beads
 			'      #map-canvas { height: 100% }'+
 			'    </style>'+
 			'    <script type="text/javascript"'+
-			'      src="https://maps.googleapis.com/maps/api/js?key={Your-Google-Token-Here}&sensor=false">'+
+			'      src="https://maps.googleapis.com/maps/api/js?v=3.exp';
+		
+		private static var pageTemplateEnd:String = '&sensor=false">'+
 			'    </script>'+
 			'    <script type="text/javascript">'+
 			'      function mapit(lat, lng, zoomLevel) {'+
@@ -167,5 +154,11 @@ package org.apache.flex.maps.google.beads
 			'    <div id="map-canvas"/>'+
 			'  </body>'+
 			'</html>';
+		
+		private function completeHandler(event:Event):void
+		{
+			trace("htmlLoader complete");
+		}
 	}
+	
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7dd59490/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 b10d1a2..9ac51b6 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
@@ -34,6 +34,18 @@ goog.inherits(org.apache.flex.maps.google.Map,
 
 
 /**
+ * Metadata
+ *
+ * @type {Object.<string, Array.<Object>>}
+ */
+org.apache.flex.maps.google.Map.prototype.
+FLEXJS_CLASS_INFO =
+{ names: [{ name: 'Map',
+           qName: 'org.apache.flex.maps.google.Map' }],
+    interfaces: [] };
+
+
+/**
  * @override
  * @protected
  * @return {Object} The actual element to be parented.
@@ -42,6 +54,7 @@ org.apache.flex.maps.google.Map.prototype.createElement =
     function() {
 
   this.element = document.createElement('div');
+  this.set_className('Map');
 
   this.positioner = this.element;
   this.element.flexjs_wrapper = this;
@@ -55,15 +68,7 @@ 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) {
-  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);
+  this.token = value;
 };
 
 
@@ -84,10 +89,9 @@ org.apache.flex.maps.google.Map.prototype.finishInitalization = function()
{
 org.apache.flex.maps.google.Map.prototype.loadMap =
     function(centerLat, centerLong, zoom) {
   if (this.initialized) {
-    var mapOptions = {
-      center: new google.maps.LatLng(centerLat, centerLong),
-      zoom: zoom
-    };
-    this.map = new google.maps.Map(this.element, mapOptions);
+    var mapOptions = {};
+    mapOptions['center'] = new window['google']['maps']['LatLng'](centerLat, centerLong);
+    mapOptions['zoom'] = zoom;
+    this.map = new window['google']['maps']['Map'](this.element, mapOptions);
   }
 };

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7dd59490/frameworks/js/FlexJS/src/org/apache/flex/maps/google/beads/MapView.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/maps/google/beads/MapView.js b/frameworks/js/FlexJS/src/org/apache/flex/maps/google/beads/MapView.js
new file mode 100644
index 0000000..1adc969
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/maps/google/beads/MapView.js
@@ -0,0 +1,73 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the 'License');
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an 'AS IS' BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/* MapView isn't really the view, but is a bead used to trigger
+   the loading of the map JS files */
+
+goog.provide('org.apache.flex.maps.google.beads.MapView');
+
+
+
+/**
+ * @constructor
+ */
+org.apache.flex.maps.google.beads.MapView = function() {
+};
+
+
+/**
+ * Metadata
+ *
+ * @type {Object.<string, Array.<Object>>}
+ */
+org.apache.flex.maps.google.beads.MapView.prototype.
+FLEXJS_CLASS_INFO =
+{ names: [{ name: 'MapView',
+           qName: 'org.apache.flex.maps.google.beads.MapView' }],
+    interfaces: [org.apache.flex.core.IBeadView] };
+
+
+/**
+ * @expose
+ * @param {Object} value The new host.
+ */
+org.apache.flex.maps.google.beads.MapView.prototype.set_strand =
+function(value) {
+
+  this.strand_ = value;
+
+  var token = this.strand_.token;
+  var src = 'https://maps.googleapis.com/maps/api/js?v=3.exp';
+  if (token)
+    src += '&key=' + token;
+  src += '&sensor=false&callback=mapInit';
+
+  var script = document.createElement('script');
+  script.type = 'text/javascript';
+  script.src = src;
+
+  window.mapView = this;
+  window['mapInit'] = function() {
+      this.mapView.finishInitalization();
+    };
+  document.body.appendChild(script);
+};
+
+
+/**
+ */
+org.apache.flex.maps.google.beads.MapView.prototype.finishInitalization = function() {
+  this.strand_.initialized = true;
+  this.strand_.dispatchEvent('ready');
+};
+


Mime
View raw message