]> git.openstreetmap.org Git - rails.git/blob - public/lib/OpenLayers/Layer/Yahoo.js
Booleans should be true/false - coding style comments welcome
[rails.git] / public / lib / OpenLayers / Layer / Yahoo.js
1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
2  * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
3  * text of the license. */
4 // @require: OpenLayers/Layer.js\r
5 \r
6 // load Yahoo map control script\r
7 document.write("<script src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers'></script>");\r
8 \r
9 /**\r
10  * @class\r
11  */\r
12 OpenLayers.Layer.Yahoo = Class.create();\r
13 OpenLayers.Layer.Yahoo.prototype = Object.extend( new OpenLayers.Layer(), {\r
14 \r
15     /** @type Boolean */\r
16     viewPortLayer: true,\r
17 \r
18     /** @type GMap2 gmap stores the Google Map element */\r
19     ymap:null,\r
20    \r
21     /** @type Boolean */\r
22     dragging:false,\r
23     \r
24     /** \r
25      * @constructor\r
26      * \r
27      * @param {String} name\r
28      */\r
29     initialize: function(name) {\r
30         OpenLayers.Layer.prototype.initialize.apply(this, [name]);\r
31     },\r
32     \r
33      /** \r
34      * @param {OpenLayers.Map} map\r
35      */\r
36     setMap:function(map) {\r
37         OpenLayers.Layer.prototype.setMap.apply(this, arguments);\r
38 \r
39         // once our layer has been added to the map, we can create the vemap\r
40         this.map.events.register("addlayer", this, this.loadYMap);\r
41     },\r
42 \r
43     /** Yahoo layer is always a base class.\r
44      * @type Boolean\r
45      */\r
46     isBaseLayer: function() {\r
47         return true;\r
48     },\r
49     \r
50     /** \r
51      * @param {OpenLayers.Bounds} bounds\r
52      * @param {int} zoomChanged\r
53      */\r
54     moveTo:function(bounds,zoomChanged) {\r
55 \r
56         if ((this.ymap != null) && (!this.dragging)) {\r
57 \r
58             var olCenter = this.map.getCenter();\r
59             var yCenter = this.getYMapCenter();\r
60             \r
61             var olZoom = this.map.getZoom();\r
62             var yZoom = this.ymap.getZoomLevel();\r
63             \r
64             if ((!olCenter.equals(yCenter)) || (( 16 - olZoom) != yZoom)) {\r
65                 this.ymap.drawZoomAndCenter(new YGeoPoint(olCenter.lat, olCenter.lon), \r
66                                     16 - olZoom);\r
67             }\r
68         }\r
69     },\r
70 \r
71     /**\r
72      * \r
73      */\r
74     loadYMap:function() {\r
75         // create div and set to same size as map\r
76         var yDiv = OpenLayers.Util.createDiv(this.name);\r
77         var sz = this.map.getSize();\r
78         yDiv.style.width = sz.w;\r
79         yDiv.style.height = sz.h;\r
80         this.div.appendChild(yDiv);\r
81 \r
82         // create GMap, hide nav controls\r
83         this.ymap = new YMap(this.div);\r
84 \r
85         // catch pans and zooms from GMap\r
86         YEvent.Capture(this.ymap, \r
87                        EventsList.endPan, \r
88                        this.catchPanZoom, \r
89                        this); \r
90 \r
91         // catch pans and zooms from GMap\r
92         YEvent.Capture(this.ymap, \r
93                        EventsList.endAutoPan, \r
94                        this.catchPanZoom, \r
95                        this); \r
96 \r
97 \r
98         // attach to the drag start and end and we´ll set a flag so that\r
99         //  we dont get recursivity. this is because the events fall through\r
100         //  the gmaps div and into the main layer div\r
101         YEvent.Capture(this.ymap, \r
102                        EventsList.startPan, \r
103                        this.dragStart,\r
104                        this); \r
105 \r
106     },\r
107 \r
108     /** \r
109      * @private\r
110      */\r
111     dragStart: function() {\r
112         this.dragging = true;\r
113     },\r
114     \r
115     /**\r
116      * @private \r
117      * \r
118      * @param {event} e\r
119      */\r
120     catchPanZoom: function(e) { \r
121         this.dragging = false;\r
122 \r
123         var olCenter = this.getYMapCenter();\r
124         var yZoom = this.ymap.getZoomLevel();\r
125 \r
126         this.map.setCenter(olCenter, 16 - yZoom);\r
127         \r
128     },\r
129 \r
130     /**\r
131      * @private\r
132      * \r
133      * @returns An OpenLayers.LonLat with the center of the ymap, or null if \r
134      *           the YMap has not been centered yet\r
135      * @type OpenLayers.LonLat\r
136      */\r
137     getYMapCenter:function() {\r
138         var olCenter = null;\r
139         var yCenter = this.ymap.getCenterLatLon();\r
140         if (yCenter != null) {\r
141             olCenter = new OpenLayers.LonLat(yCenter.Lon, yCenter.Lat);\r
142         }\r
143         return olCenter;\r
144     },\r
145  \r
146     \r
147     /** @final @type String */\r
148     CLASS_NAME: "OpenLayers.Layer.Yahoo"\r
149 });\r