You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2007/04/26 02:43:24 UTC

svn commit: r532579 - in /incubator/xap/trunk/codebase/src/xap/bridges/google: GoogleMapBridge.js XapGoogleMap.js

Author: mturyn
Date: Wed Apr 25 19:43:23 2007
New Revision: 532579

URL: http://svn.apache.org/viewvc?view=rev&rev=532579
Log:
From: Rob Gagne

Updated map code; still todo - handle the children, some misc resize issues

What's new: derived form dojoWidget and therefore supports the default attributes and layout

Added:
    incubator/xap/trunk/codebase/src/xap/bridges/google/XapGoogleMap.js
Modified:
    incubator/xap/trunk/codebase/src/xap/bridges/google/GoogleMapBridge.js

Modified: incubator/xap/trunk/codebase/src/xap/bridges/google/GoogleMapBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/google/GoogleMapBridge.js?view=diff&rev=532579&r1=532578&r2=532579
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/google/GoogleMapBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/google/GoogleMapBridge.js Wed Apr 25 19:43:23 2007
@@ -5,7 +5,7 @@
  *  regarding copyright ownership.  The ASF licenses this file
  *  to you 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
+ *  with the License.  You may obtain a copy of the License at 
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -16,226 +16,174 @@
  *  limitations under the License.
  *
  */
-
-Xap.provide("xap.bridges.google.GoogleMapBridge"); 
-// Auto-added---o.k.?
-Xap.require("xap.session.ClientEvent");
-
-Xap.require("xap.bridges.google.GoogleBridge"); 
  
  /**
  * @fileoverview
- * 
- * A bridge class that controls a GMap2 peer.
+ * @author Rob Gagne
+ *
+ * A bridge class that provides animations effects
  */
 
-/**
- * Creates a xap.bridges.google.GoogleMapBridge.
- * 
- * 
- * @class xap.bridges.google.GoogleMapBridge is the bridge between an XML element
- * representing a google map and GMap2 class.
- * 
- * @constructor
- * 
- * @author bbuffone
- */
-xap.bridges.google.GoogleMapBridge = function() {
-	xap.bridges.google.GoogleBridge.call( this );
+/*
+ * this library requires Scriptaculous to be loaded
+ *
+ */
+
+Xap.provide("xap.bridges.google.GoogleMapBridge"); 
+Xap.require("xap.bridges.dojo.DojoWidgetBridge");
+Xap.require("xap.bridges.google.XapGoogleMap"); 
+Xap.require("dojo.style"); 
+
+xap.bridges.google.GoogleMapBridge= function() { 
+	xap.bridges.dojo.DojoWidgetBridge.call(this);
 }
 
-xap.bridges.google.GoogleMapBridge.prototype = new xap.bridges.google.GoogleBridge;
+Xap.setupClassAsSubclassOf(
+	"xap.bridges.google.GoogleMapBridge",
+	"xap.bridges.dojo.DojoWidgetBridge"						
+);
 
-xap.bridges.google.GoogleMapBridge.s_log = xap.log.Logger.getLogger( "xap.bridges.google.GoogleMapBridge" );
+xap.bridges.google.GoogleMapBridge.prototype.init = function() {
+	xap.bridges.dojo.DojoWidgetBridge.prototype.init.call(this);
+	//dojo.event.connect (this.getPeer(), "onResized", this, "checkResize");
+	dojo.lang.setTimeout(this, this.checkResize, 0);
+}
 
-xap.bridges.google.GoogleMapBridge.prototype.toString = function() {
-	return "xap.bridges.google.GoogleMapBridge";
+xap.bridges.google.GoogleMapBridge.prototype.obtainPeer = function() {
+	xap.bridges.dojo.DojoWidgetBridge.prototype.obtainPeer.call(this);	
+	this.map = new GMap2(this.getPeer().domNode);	
 }
 
-/**
- * Creates the peer component that this bridge controls.
- */
-xap.bridges.google.GoogleMapBridge.prototype.createPeer = function() {
-	var parent = this.getElement().getParent();
-	var handler = this.getUiContentHandler().getHandlerForElement( parent );
-	var parentPeer = handler.getPeer();
-	var	htmlElement = null;
-			
- 	if ( handler.getRootDomNode != null ) {
-		htmlElement = handler.getRootDomNode();
-	} else {
-		xap.bridges.google.GoogleMapBridge.s_log.error("Bogus parent peer:" + parentPeer );
-	}
-   try {
-    	this.map = new GMap2(htmlElement);
-    	var thisPeer = this;
-    	
-    	GEvent.addListener(this.map, "click", function(marker, point) {    		                
-            //let the peer know there is was a google event.                
-            thisPeer.onMapClickEvent(marker, point, thisPeer.map);                
-        });
-        
-    	GEvent.addListener(this.map, "maptypechanged", function() {    		                
-            //let the peer know there is was a google event.                
-            thisPeer.onMapTypeChangeEvent();                
-        });
-
-    	GEvent.addListener(this.map, "zoomend", function() {    		                
-            //let the peer know there is was a google event.                
-            thisPeer.onZoomEndEvent();                
-        });
-
-    	GEvent.addListener(this.map, "moveend", function() {    		                
-            //let the peer know there is was a google event.                
-            thisPeer.onMoveEndEvent();                
-        });
-        
-     	this.setPeer(this.map);
-    } catch ( e ) {
-        alert(e);
-    }
+xap.bridges.google.GoogleMapBridge.prototype.getPeerString = function(){
+	return "XapGoogleMap" ;
+}
+ 
+xap.bridges.google.GoogleMapBridge.prototype.checkResize = function(){
+	this.map.checkResize();
+	var center = this.getElement().getAttribute ("center");
+	if (center) this.setCenterAttribute (center);
 }
 
+xap.bridges.google.GoogleMapBridge.prototype.addChild = function( childHandler ){
+	// check instance of and then handle them
+	/*
+	if ( childHandler instanceof xap.bridges.google.GoogleMarkerBridge ) {
+		this.map.addMarker (childHandler.getPeer());
+	}
+	*/
+}
+ 
 /**
- *    Handles the clicking of a marker. 
- * 
- */
-xap.bridges.google.GoogleMapBridge.prototype.onZoomEndEvent = function() {
-	if (this.trapZoom == true) return;
+ * Attribute definitions
+ */ 
+ 
+xap.bridges.google.GoogleMapBridge.prototype.getNewAllowedAttributes = function(){
+	return ["center","zoom","mapType","mapTypeControl","zoomControl","scaleControl", "mapControl"];
+}	
+
+xap.bridges.google.GoogleMapBridge.prototype.setCenterAttribute = function(value){
+	this.trapMove = true;
+	//Parse the value into the lat and long that will be used to 
+	//set the center position.   
+	var center = this.convertStringToGLatLng(value);    
+	this.map.setCenter( center );
+} 
+
+xap.bridges.google.GoogleMapBridge.prototype.setZoomAttribute = function(value){
+	this.trapZoom = true;
+	this.map.setZoom( value * 1.0 );
+} 
+
+xap.bridges.google.GoogleMapBridge.prototype.setMapControlAttribute = function(value){
+	if (value=="small"){
+		this.map.addControl(new GSmallMapControl());
+	}
+	else if (value=="large"){
+		this.map.addControl(new GLargeMapControl());
+	}
+
+} 
+
+xap.bridges.google.GoogleMapBridge.prototype.setMapTypeAttribute = function(value){
+	if (this.getMapType() == value) return;
+	this.trapType = true;
 	
-    var clientEvent = new xap.session.ClientEvent(this.getElement(), this.getSession());
-    
-    clientEvent.map = this.map;  
-    clientEvent.zoom = this.map.getZoom();
-    if (clientEvent.zoom != 0){
-	    //this method will handle the firing of all event handlers
-	    this.fireEvent("onZoomEnd", null, null, clientEvent);  
-    }	
+	if (value=="NORMAL_MAP"){
+		this.map.setMapType(G_NORMAL_MAP);      
+	}
+	else if (value=="SATELLITE_MAP"){
+		this.map.setMapType(G_SATELLITE_MAP);      
+	}
+	else if (value=="HYBRID_MAP"){
+		this.map.setMapType(G_HYBRID_MAP);      
+	}
+} 
+
+xap.bridges.google.GoogleMapBridge.prototype.setMapTypeControlAttribute = function(value){
+	if (value ==="true") this.map.addControl(new GMapTypeControl());
+} 
+xap.bridges.google.GoogleMapBridge.prototype.setZoomControlAttribute = function(value){
+	if (value ==="true") this.map.addControl(new GSmallZoomControl());
+} 
+xap.bridges.google.GoogleMapBridge.prototype.setScaleControlAttribute = function(value){
+	if (value ==="true") this.map.addControl(new GScaleControl());
+} 
+
+xap.bridges.google.GoogleMapBridge.prototype.getMapType = function() {
+  	var mapType = this.map.getCurrentMapType();      
+	if (mapType == G_NORMAL_MAP){
+		return "NORMAL_MAP";
+	}
+	else if (mapType == G_SATELLITE_MAP){
+		return "SATELLITE_MAP";
+	}
+	else if (mapType == G_HYBRID_MAP){
+		return "HYBRID_MAP";
+	}
 }
 
 /**
- *    Handles the clicking of a marker. 
- * 
- */
-xap.bridges.google.GoogleMapBridge.prototype.onMoveEndEvent = function() {
-	if (this.trapMove == true) return;
-	
-    var clientEvent = new xap.session.ClientEvent(this.getElement(), this.getSession());
-    clientEvent.map = this.map;  
-    clientEvent.latitude = this.map.getCenter().lat();
-    clientEvent.longitude = this.map.getCenter().lng();
-    clientEvent.center = this.map.getCenter().lat() + ", " + this.map.getCenter().lng();
-    
-    //this method will handle the firing of all event handlers
-    this.fireEvent("onMoveEnd", null, null, clientEvent);  	
-}
+ * Helpers
+ */ 
 
 /**
- *    Handles the clicking of a marker. 
- * 
+ * Parse the value into the lat and long that will be used to 
+ * set the center position.
+ * takes a string that is comma seperated latitude and longitude "37.23232, -80.0000"
+ * and returns a GLatLng object.  
  */
-xap.bridges.google.GoogleMapBridge.prototype.onMapTypeChangeEvent = function() {
-	if (this.trapType == true) return;
-    var clientEvent = new xap.session.ClientEvent(this.getElement(), this.getSession());
-    
-    clientEvent.map = this.map;  
-    clientEvent.mapType = this.getMapType();
-    
-    //this method will handle the firing of all event handlers
-    this.fireEvent("onMapTypeChange", null, null, clientEvent);  	
+xap.bridges.google.GoogleMapBridge.prototype.convertStringToGLatLng = function(value) {
+    var lat = value.substring(0, value.indexOf(",")) * 1.0;
+    var lng = value.substring(value.indexOf(",") + 1) * 1.0;
+    return new GLatLng(lat, lng);   
 }
 
 /**
- *    Handles the clicking of a marker. 
- * 
+ * takes a string that is comma seperated x and y "37, 80"
+ * and returns a CPoint object.  
  */
-xap.bridges.google.GoogleMapBridge.prototype.onMapClickEvent = function( marker, point, map ) {
-	
-    var clientEvent = new xap.session.ClientEvent(this.getElement(), this.getSession());
-    var mapHandler = this.getUiContentHandler().getHandlerForPeer(map);
-
-    //add the marker if the user clicked on it if not do nothing.
-    if (marker != null){
-        var markerHandler = this.getUiContentHandler().getHandlerForPeer(marker);
-        clientEvent.marker = markerHandler;
-        clientEvent.latitude = marker.getPoint().lat();
-        clientEvent.longitude = marker.getPoint().lng();
-    }else{
-         //add the point, only seems to be there is the user didn't click on a marker
-        clientEvent.latitude = point.lat();
-        clientEvent.longitude = point.lng();
-    }
-    
-    clientEvent.map = map;  
-    
-    //this method will handle the firing of all event handlers
-    this.fireEvent("onClick", null, null, clientEvent);  	
+xap.bridges.google.GoogleMapBridge.prototype.convertStringToGPoint = function(value) {
+    var x = value.substring(0, value.indexOf(",")) * 1.0;
+    var y = value.substring(value.indexOf(",") + 1) * 1.0;
+    return new GPoint(x, y);   
 }
 
 /**
- * This method is called whenever an attribute
- * on the XML element that maps to this bridge class
- * is changed. DwtControlBridge handles the following attributes:
- * 
- * Attributes not handled here are are passed to the 
- * superclass attributeSet method.
- */
-xap.bridges.google.GoogleMapBridge.prototype.attributeSet = function( event ) {
-	var name = event.getName();
-	var value = event.getNewValue();
-	
-	if (this.map == null) return;
-    
-	if (name=="zoom") {
-    	try{
-			this.trapZoom = true;
-			this.map.setZoom( value * 1.0 );
-		}finally{this.trapZoom=false;}
-	}else if ( name=="center"){	 
-    	try{
-			this.trapMove = true;
-		    //Parse the value into the lat and long that will be used to 
-		    //set the center position.   
-		    var center = this.convertStringToGLatLng(value);    
-			this.map.setCenter( center );
-		}finally{this.trapMove=false;}		
-	}else if (name=="mapControl"){
-	    if (value=="small"){
-	        this.map.addControl(new GSmallMapControl());
-	    }else if (value=="large"){
-	        this.map.addControl(new GLargeMapControl());
-	    }
-	}else if (name=="mapTypeControl" && value=="true"){
-    	this.map.addControl(new GMapTypeControl());
-	}else if (name=="zoomControl" && value=="true"){
-    	this.map.addControl(new GSmallZoomControl());
-	}else if (name=="scaleControl" && value=="true"){
-    	this.map.addControl(new GScaleControl());
-    }else if (name=="mapType"){
-    	try{
-    		if (this.getMapType() == value)return;
-			this.trapType = true;
-	        if (value=="NORMAL_MAP"){
-	            this.map.setMapType(G_NORMAL_MAP);      
-	        }else if (value=="SATELLITE_MAP"){
-	            this.map.setMapType(G_SATELLITE_MAP);      
-	        }else if (value=="HYBRID_MAP"){
-	            this.map.setMapType(G_HYBRID_MAP);      
-	        }
-		}finally{this.trapType=false;}
-	}else{
-		xap.bridges.google.GoogleBridge.prototype.attributeSet.call( this, event );
-	}
+ * takes a string that is comma seperated width and height "37, 80"
+ * and returns a GSize object.  
+ */
+xap.bridges.google.GoogleMapBridge.prototype.convertStringToGSize = function(value) {
+    var width = value.substring(0, value.indexOf(",")) * 1.0;
+    var height = value.substring(value.indexOf(",") + 1) * 1.0;
+    return new GSize(width, height);   
 }
 
-xap.bridges.google.GoogleMapBridge.prototype.getMapType = function() {
-  	var mapType = this.map.getCurrentMapType();      
-	if (mapType == G_NORMAL_MAP){
-		return "NORMAL_MAP";
-	}else if (mapType == G_SATELLITE_MAP){
-		return "SATELLITE_MAP";
-	}else if (mapType == G_HYBRID_MAP){
-		return "HYBRID_MAP";
+
+/*
+xap.bridges.google.GoogleMapBridge.prototype.addChild = function(childHandler, index) {
+	var childPeer = this.getDojoWidgetPeer(childHandler);
+	if (childPeer) {
+		this.getPeer().addChild(childPeer, null, 'insertAtIndex', null, index);
 	}
 }
-
+*/ 
\ No newline at end of file

Added: incubator/xap/trunk/codebase/src/xap/bridges/google/XapGoogleMap.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/google/XapGoogleMap.js?view=auto&rev=532579
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/google/XapGoogleMap.js (added)
+++ incubator/xap/trunk/codebase/src/xap/bridges/google/XapGoogleMap.js Wed Apr 25 19:43:23 2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ *
+ */
+ 
+ /**
+ * @fileoverview
+ * @author Rob Gagne
+ *
+ * A pane class that provides animations effects
+ */
+
+Xap.provide("xap.bridges.google.XapGoogleMap");
+
+dojo.require("dojo.widget.*");
+dojo.require("dojo.widget.HtmlWidget");
+dojo.require("dojo.dom");
+dojo.require("dojo.html");
+dojo.require("dojo.style");
+dojo.require("dojo.event");
+
+dojo.widget.manager.registerWidgetPackage("xap.bridges.google");
+dojo.widget.tags.addParseTreeHandler("dojo:XapGoogleMap");
+
+xap.bridges.google.XapGoogleMap = function(){
+	dojo.widget.HtmlWidget.call(this);
+}
+dojo.inherits(xap.bridges.google.XapGoogleMap, dojo.widget.HtmlWidget);
+
+dojo.lang.extend(xap.bridges.google.XapGoogleMap, {	
+	templateString: '<div></div>',
+	templateCssPath: null ,
+	widgetType: "XapGoogleMap",
+	isContainer: true	
+	/*
+	addChild: function(child, overrideContainerNode, pos, ref, insertIndex){
+		xap.bridges.google.XapGoogleMap.superclass.addChild.call(this,child, overrideContainerNode, pos, ref, insertIndex);
+	}
+	*/
+}
+);
+