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 bb...@apache.org on 2006/11/02 22:17:27 UTC
svn commit: r470556 -
/incubator/xap/trunk/src/xap/bridges/google/GoogleMapBridge.js
Author: bbuffone
Date: Thu Nov 2 14:17:27 2006
New Revision: 470556
URL: http://svn.apache.org/viewvc?view=rev&rev=470556
Log:
I have updated the starting process of the XAP engine with the HTML page.
This changes is defined in emails from me on the 8/29.
This changes break compatibilty with existing samples.
To see how the new process works check out the new samples in
the startup folder.
Modified:
incubator/xap/trunk/src/xap/bridges/google/GoogleMapBridge.js (contents, props changed)
Modified: incubator/xap/trunk/src/xap/bridges/google/GoogleMapBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/google/GoogleMapBridge.js?view=diff&rev=470556&r1=470555&r2=470556
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/google/GoogleMapBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/google/GoogleMapBridge.js Thu Nov 2 14:17:27 2006
@@ -1,151 +1,239 @@
-/*
- * Copyright 2006 The Apache Software Foundation.
- *
- * 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.
- *
- */
-
-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.
- */
-
-/**
- * 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 );
-}
-
-xap.bridges.google.GoogleMapBridge.prototype = new xap.bridges.google.GoogleBridge;
-
-xap.bridges.google.GoogleMapBridge.s_log = xap.util.LogFactory.getLog( "xap.bridges.google.GoogleMapBridge" );
-
-xap.bridges.google.GoogleMapBridge.prototype.toString = function() {
- return "xap.bridges.google.GoogleMapBridge";
-}
-
-/**
- * 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();
-
- if ( parentPeer instanceof DwtComposite ) {
- try {
- htmlEl = document.getElementById(parentPeer._htmlElId)
- this.gMap = new GMap2(htmlEl);
- var thisPeer = this;
-
- GEvent.addListener(this.gMap, "click", function(marker, point) {
- //let the peer know there is was a google event.
- thisPeer.onMapClickEvent(marker, point, thisPeer.gMap);
- });
-
- this.setPeer(this.gMap);
- } catch ( e ) {
- alert(e);
- }
- } else {
- xap.bridges.google.GoogleMapBridge.s_log.error("Bogus parent peer:" + parentPeer );
- }
-}
-
-/**
- * Handles the clicking of a marker.
- *
- */
-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.point = marker.getPoint();
- }else{
- //add the point, only seems to be there is the user didn't click on a marker
- clientEvent.point = point;
- }
-
- clientEvent.map = map;
- clientEvent.source = mapHandler;
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+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.
+ */
+
+/**
+ * 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 );
+}
+
+xap.bridges.google.GoogleMapBridge.prototype = new xap.bridges.google.GoogleBridge;
+
+xap.bridges.google.GoogleMapBridge.s_log = xap.util.LogFactory.getLog( "xap.bridges.google.GoogleMapBridge" );
+
+xap.bridges.google.GoogleMapBridge.prototype.toString = function() {
+ return "xap.bridges.google.GoogleMapBridge";
+}
+
+/**
+ * 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);
+ }
+}
+
+/**
+ * Handles the clicking of a marker.
+ *
+ */
+xap.bridges.google.GoogleMapBridge.prototype.onZoomEndEvent = function() {
+ if (this.trapZoom == true) return;
+
+ 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);
+ }
+}
+
+/**
+ * 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("onClick", null, null, clientEvent);
-}
-
-
-/**
- * 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 (name=="zoom") {
- this.gMap.setZoom( value * 1.0 );
- }else if ( name=="center"){
- //Parse the value into the lat and long that will be used to
- //set the center position.
- var center = this.convertStringToGLatLng(value);
- this.gMap.setCenter( center );
-
- }else if (name=="mapControl"){
- if (value=="small"){
- this.gMap.addControl(new GSmallMapControl());
- }else if (value=="large"){
- this.gMap.addControl(new GLargeMapControl());
- }
- }else if (name=="mapTypeControl" && value=="true"){
- this.gMap.addControl(new GMapTypeControl());
- }else if (name=="zoomControl" && value=="true"){
- this.gMap.addControl(new GSmallZoomControl());
- }else if (name=="scaleControl" && value=="true"){
- this.gMap.addControl(new GScaleControl());
- }else if (name=="mapType"){
- if (value=="G_NORMAL_MAP"){
- this.gMap.setMapType(G_NORMAL_MAP);
- }else if (value=="G_SATELLITE_MAP"){
- this.gMap.setMapType(G_SATELLITE_MAP);
- }else if (value=="G_HYBRID_MAP"){
- this.gMap.setMapType(G_HYBRID_MAP);
- }
- }else{
- xap.bridges.google.GoogleBridge.prototype.attributeSet.call( this, event );
- }
-}
+ this.fireEvent("onMoveEnd", null, null, clientEvent);
+}
+
+/**
+ * Handles the clicking of a marker.
+ *
+ */
+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);
+}
+
+/**
+ * Handles the clicking of a marker.
+ *
+ */
+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);
+}
+
+/**
+ * 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 );
+ }
+}
+
+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";
+ }
+}
+
Propchange: incubator/xap/trunk/src/xap/bridges/google/GoogleMapBridge.js
('svn:eol-style' removed)