]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Mapstraction/js/mxn.yahoo.core.js
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / plugins / Mapstraction / js / mxn.yahoo.core.js
1 mxn.register('yahoo', { \r
2 \r
3 Mapstraction: {\r
4         \r
5         init: function(element,api) {           \r
6                 var me = this;\r
7                 if (YMap) {\r
8                         this.maps[api] = new YMap(element);\r
9 \r
10                         YEvent.Capture(this.maps[api], EventsList.MouseClick, function(event,location) {\r
11                                 me.clickHandler(location.Lat, location.Lon, location, me);\r
12                                 me.click.fire({'location': new mxn.LatLonPoint(location.Lat, location.Lon)});\r
13                         });\r
14                         YEvent.Capture(this.maps[api], EventsList.changeZoom, function() {\r
15                                 me.moveendHandler(me);\r
16                                 me.changeZoom.fire();\r
17                         });\r
18                         YEvent.Capture(this.maps[api], EventsList.endPan, function() {\r
19                                 me.moveendHandler(me);\r
20                                 me.endPan.fire();\r
21                         });\r
22                         YEvent.Capture(this.maps[api], EventsList.endAutoPan, function() {\r
23                                 me.endPan.fire();\r
24                         });\r
25                         \r
26                         this.loaded[api] = true;\r
27                         me.load.fire();\r
28                 }\r
29                 else {\r
30                         alert(api + ' map script not imported');\r
31                 }  \r
32         },\r
33         \r
34         applyOptions: function(){\r
35                 \r
36                 /*\r
37                 if (this.options.enableDragging) {\r
38                         map.enableDragMap();\r
39                 } else {\r
40                         map.disableDragMap();\r
41                 }*/\r
42                 \r
43         },\r
44 \r
45         resizeTo: function(width, height){      \r
46                 this.maps[this.api].resizeTo(new YSize(width,height));\r
47         },\r
48 \r
49         addControls: function( args ) {\r
50                 var map = this.maps[this.api];\r
51                 \r
52                 if (args.pan) {\r
53                         map.addPanControl();\r
54                 }\r
55                 else {\r
56                         // Yahoo doesn't check the pan control is there before trying to remove it\r
57                         // so throws an exception :(\r
58                         map.addPanControl();\r
59                         map.removePanControl();\r
60                 }\r
61                 \r
62                 if (args.zoom == 'large') {\r
63                         map.addZoomLong();\r
64                 }\r
65                 else if ( args.zoom == 'small' ) {\r
66                         map.addZoomShort();\r
67                 }\r
68                 else {\r
69                         map.removeZoomScale();\r
70                 }\r
71         },\r
72 \r
73         addSmallControls: function() {\r
74                 var map = this.maps[this.api];\r
75                 map.addPanControl();\r
76                 map.addZoomShort();\r
77                 this.addControlsArgs.pan = true;\r
78                 this.addControlsArgs.zoom = 'small';\r
79         },\r
80 \r
81         addLargeControls: function() {\r
82                 var map = this.maps[this.api];\r
83                 map.addPanControl();\r
84                 map.addZoomLong();\r
85                 this.addControlsArgs.pan = true;  // keep the controls in case of swap\r
86                 this.addControlsArgs.zoom = 'large';\r
87         },\r
88 \r
89         addMapTypeControls: function() {\r
90                 var map = this.maps[this.api];\r
91                 map.addTypeControl();\r
92         },\r
93 \r
94         dragging: function(on) {\r
95                 var map = this.maps[this.api];\r
96                 if (on) {\r
97                         map.enableDragMap();\r
98                 } else {\r
99                         map.disableDragMap();\r
100                 }\r
101         },\r
102 \r
103         setCenterAndZoom: function(point, zoom) { \r
104                 var map = this.maps[this.api];\r
105                 var pt = point.toProprietary(this.api);\r
106                 \r
107                 var yzoom = 18 - zoom; // maybe?\r
108         map.drawZoomAndCenter(pt,yzoom);\r
109         },\r
110         \r
111         addMarker: function(marker, old) {\r
112                 var map = this.maps[this.api];\r
113                 var pin = marker.toProprietary(this.api);\r
114                 map.addOverlay(pin);\r
115                 YEvent.Capture(pin, EventsList.MouseClick, function() {\r
116                         marker.click.fire();\r
117                 });\r
118                 YEvent.Capture(pin, EventsList.openSmartWindow, function() {\r
119                         marker.openInfoBubble.fire();\r
120                 });\r
121                 YEvent.Capture(pin, EventsList.closeSmartWindow, function() {\r
122                         marker.closeInfoBubble.fire();\r
123                 });\r
124                 return pin;\r
125         },\r
126 \r
127         removeMarker: function(marker) {\r
128                 var map = this.maps[this.api];\r
129                 map.removeOverlay(marker.proprietary_marker);\r
130         },\r
131 \r
132         removeAllMarkers: function() {\r
133                 var map = this.maps[this.api];\r
134                 map.removeMarkersAll();\r
135         },\r
136         \r
137         declutterMarkers: function(opts) {\r
138                 throw 'Not implemented';\r
139         },\r
140 \r
141         addPolyline: function(polyline, old) {\r
142                 var map = this.maps[this.api];\r
143                 var pl = polyline.toProprietary(this.api);\r
144                 map.addOverlay(pl);\r
145                 return pl;\r
146         },\r
147 \r
148         removePolyline: function(polyline) {\r
149                 var map = this.maps[this.api];\r
150                 map.removeOverlay(polyline.proprietary_polyline);\r
151         },\r
152         \r
153         getCenter: function() {\r
154                 var map = this.maps[this.api];\r
155                 var pt = map.getCenterLatLon();\r
156         var point = new mxn.LatLonPoint(pt.Lat, pt.Lon);\r
157                 return point;\r
158         },\r
159 \r
160         setCenter: function(point, options) {\r
161                 var map = this.maps[this.api];\r
162                 var pt = point.toProprietary(this.api);\r
163                 map.panToLatLon(pt);\r
164         },\r
165 \r
166         setZoom: function(zoom) {\r
167                 var map = this.maps[this.api];\r
168                 var yzoom = 18 - zoom; // maybe?\r
169                 map.setZoomLevel(yzoom);                  \r
170         },\r
171         \r
172         getZoom: function() {\r
173                 var map = this.maps[this.api];\r
174                 return 18 - map.getZoomLevel();\r
175         },\r
176 \r
177         getZoomLevelForBoundingBox: function( bbox ) {\r
178                 throw 'Not implemented';\r
179         },\r
180 \r
181         setMapType: function(type) {\r
182                 var map = this.maps[this.api];\r
183                 \r
184                 switch(type) {\r
185                         case mxn.Mapstraction.ROAD:\r
186                                 map.setMapType(YAHOO_MAP_REG);\r
187                                 break;\r
188                         case mxn.Mapstraction.SATELLITE:\r
189                                 map.setMapType(YAHOO_MAP_SAT);\r
190                                 break;\r
191                         case mxn.Mapstraction.HYBRID:\r
192                                 map.setMapType(YAHOO_MAP_HYB);\r
193                                 break;\r
194                         default:\r
195                                 map.setMapType(YAHOO_MAP_REG);\r
196                 }\r
197         },\r
198 \r
199         getMapType: function() {\r
200                 var map = this.maps[this.api];\r
201                 var type = map.getCurrentMapType();\r
202                 switch(type) {\r
203                         case YAHOO_MAP_REG:\r
204                                 return mxn.Mapstraction.ROAD;\r
205                         case YAHOO_MAP_SAT:\r
206                                 return mxn.Mapstraction.SATELLITE;\r
207                         case YAHOO_MAP_HYB:\r
208                                 return mxn.Mapstraction.HYBRID;\r
209                         default:\r
210                                 return null;\r
211                 }\r
212         },\r
213 \r
214         getBounds: function () {\r
215                 var map = this.maps[this.api];\r
216                 var ybox = map.getBoundsLatLon();\r
217         return new mxn.BoundingBox(ybox.LatMin, ybox.LonMin, ybox.LatMax, ybox.LonMax);\r
218         },\r
219 \r
220         setBounds: function(bounds){\r
221                 var map = this.maps[this.api];\r
222                 var sw = bounds.getSouthWest();\r
223                 var ne = bounds.getNorthEast();\r
224                                                 \r
225                 if(sw.lon > ne.lon) {\r
226                         sw.lon -= 360;\r
227                 }\r
228                 var center = new YGeoPoint((sw.lat + ne.lat)/2, (ne.lon + sw.lon)/2);\r
229                 \r
230                 var container = map.getContainerSize();\r
231                 for(var zoom = 1 ; zoom <= 17 ; zoom++){\r
232                         var sw_pix = mxn.util.convertLatLonXY_Yahoo(sw,zoom);\r
233                         var ne_pix = mxn.util.convertLatLonXY_Yahoo(ne,zoom);\r
234                         if(sw_pix.x > ne_pix.x) {\r
235                                 sw_pix.x -= (1 << (26 - zoom)); //earth circumference in pixel\r
236                         }\r
237                         if(Math.abs(ne_pix.x - sw_pix.x) <= container.width\r
238                                 && Math.abs(ne_pix.y - sw_pix.y) <= container.height){\r
239                                 map.drawZoomAndCenter(center, zoom); //Call drawZoomAndCenter here: OK if called multiple times anyway\r
240                                 break;\r
241                         }\r
242                 }               \r
243         },\r
244         \r
245         addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {\r
246                 throw 'Not implemented';\r
247         },\r
248 \r
249         setImagePosition: function(id) {\r
250            throw 'Not implemented';\r
251         },      \r
252         \r
253         addOverlay: function(url, autoCenterAndZoom) {\r
254                 var map = this.maps[this.api];\r
255                 map.addOverlay(new YGeoRSS(url));\r
256         },\r
257         \r
258         addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {\r
259                 throw 'Not implemented';\r
260         },\r
261 \r
262         toggleTileLayer: function(tile_url) {\r
263                 throw 'Not implemented';\r
264         },\r
265         \r
266         getPixelRatio: function() {\r
267                 throw 'Not implemented';        \r
268         },\r
269         \r
270         mousePosition: function(element) {\r
271                 throw 'Not implemented';\r
272         }\r
273         \r
274 },\r
275 \r
276 LatLonPoint: {\r
277         \r
278         toProprietary: function() {\r
279                 return new YGeoPoint(this.lat,this.lon);\r
280         },\r
281 \r
282         fromProprietary: function(yahooPoint) {\r
283                 this.lat = yahooPoint.Lat;\r
284                 this.lon = yahooPoint.Lon;\r
285         }\r
286         \r
287 },\r
288 \r
289 Marker: {\r
290         \r
291         toProprietary: function() {\r
292                 var ymarker, size;\r
293                 var infoBubble, event_action, infoDiv, div;\r
294                 \r
295             if(this.iconSize) {\r
296                 size = new YSize(this.iconSize[0], this.iconSize[1]);\r
297             }\r
298             if(this.iconUrl) {\r
299                 if(this.iconSize){\r
300                     ymarker = new YMarker(this.location.toProprietary('yahoo'), new YImage(this.iconUrl, size));\r
301                         }\r
302                 else {\r
303                     ymarker = new YMarker(this.location.toProprietary('yahoo'), new YImage(this.iconUrl));\r
304                         }\r
305             }\r
306             else {\r
307                 if(this.iconSize) {\r
308                     ymarker = new YMarker(this.location.toProprietary('yahoo'), null, size);\r
309                         }\r
310                 else {\r
311                     ymarker = new YMarker(this.location.toProprietary('yahoo'));\r
312                         }\r
313             }\r
314 \r
315             if(this.labelText) {\r
316                 ymarker.addLabel(this.labelText);\r
317             }\r
318 \r
319             if(this.infoBubble) {\r
320                 infoBubble = this.infoBubble;\r
321                 if(this.hover) {\r
322                     event_action = EventsList.MouseOver;\r
323                 }\r
324                 else {\r
325                     event_action = EventsList.MouseClick;\r
326                 }\r
327                 YEvent.Capture(ymarker, event_action, function() {\r
328                     ymarker.openSmartWindow(infoBubble);\r
329                 });\r
330 \r
331             }\r
332 \r
333             if(this.infoDiv) {\r
334                 infoDiv = this.infoDiv;\r
335                 div = this.div;\r
336                 if(this.hover) {\r
337                     event_action = EventsList.MouseOver;\r
338                 }\r
339                 else {\r
340                     event_action = EventsList.MouseClick;\r
341                 }\r
342                 YEvent.Capture(ymarker, event_action, function() {\r
343                     document.getElementById(div).innerHTML = infoDiv;\r
344                 });\r
345             }\r
346 \r
347             return ymarker;\r
348         },\r
349 \r
350         openBubble: function() {\r
351                 var ypin = this.proprietary_marker;\r
352         ypin.openSmartWindow(this.infoBubble);\r
353         },\r
354 \r
355         hide: function() {\r
356                 this.proprietary_marker.hide();\r
357         },\r
358 \r
359         show: function() {\r
360                 this.proprietary_marker.unhide();\r
361         },\r
362 \r
363         update: function() {\r
364                 throw 'Not implemented';\r
365         }\r
366         \r
367 },\r
368 \r
369 Polyline: {\r
370 \r
371         toProprietary: function() {             \r
372                 var ypolyline;\r
373             var ypoints = [];\r
374             for (var i = 0, length = this.points.length ; i< length; i++){\r
375                 ypoints.push(this.points[i].toProprietary('yahoo'));\r
376             }\r
377             ypolyline = new YPolyline(ypoints,this.color,this.width,this.opacity);\r
378             return ypolyline;\r
379         },\r
380         \r
381         show: function() {\r
382                 throw 'Not implemented';\r
383         },\r
384 \r
385         hide: function() {\r
386                 throw 'Not implemented';\r
387         }\r
388         \r
389 }\r
390 \r
391 });