mxn.yahoo.core.js 9.1 KB

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