mxn.microsoft.core.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. mxn.register('microsoft', {
  2. Mapstraction: {
  3. init: function(element, api) {
  4. var me = this;
  5. if (VEMap){
  6. this.maps[api] = new VEMap(element.id);
  7. this.maps[api].AttachEvent('onclick', function(event){
  8. me.clickHandler();
  9. var x = event.mapX;
  10. var y = event.mapY;
  11. var pixel = new VEPixel(x,y);
  12. me.click.fire({'location': new mxn.LatLonPoint(pixel.Latitude, pixel.Longitude)});
  13. });
  14. this.maps[api].AttachEvent('onendzoom', function(event){
  15. me.moveendHandler(me);
  16. me.changeZoom.fire();
  17. });
  18. this.maps[api].AttachEvent('onendpan', function(event){
  19. me.moveendHandler(me);
  20. me.endPan.fire();
  21. });
  22. this.maps[api].AttachEvent('onchangeview', function(event){
  23. me.endPan.fire();
  24. });
  25. this.maps[api].LoadMap();
  26. document.getElementById("MSVE_obliqueNotification").style.visibility = "hidden";
  27. //removes the bird's eye pop-up
  28. this.loaded[api] = true;
  29. me.load.fire();
  30. }
  31. else{
  32. alert(api + ' map script not imported')
  33. }
  34. },
  35. applyOptions: function(){
  36. var map = this.maps[this.api];
  37. if(this.options.enableScrollWheelZoom){
  38. map.enableContinuousZoom();
  39. map.enableScrollWheelZoom();
  40. }
  41. },
  42. resizeTo: function(width, height){
  43. this.maps[this.api].Resize(width, height);
  44. },
  45. addControls: function( args ) {
  46. var map = this.maps[this.api];
  47. if (args.pan) {
  48. map.SetDashboardSize(VEDashboardSize.Normal);
  49. }
  50. else {
  51. map.SetDashboardSize(VEDashboardSize.Tiny)
  52. }
  53. if (args.zoom == 'large') {
  54. map.SetDashboardSize(VEDashboardSize.Small)
  55. }
  56. else if ( args.zoom == 'small' ) {
  57. map.SetDashboardSize(VEDashboardSize.Tiny)
  58. }
  59. else {
  60. map.HideDashboard();
  61. map.HideScalebar();
  62. }
  63. },
  64. addSmallControls: function() {
  65. var map = this.maps[this.api];
  66. map.SetDashboardSize(VEDashboardSize.Tiny);
  67. },
  68. addLargeControls: function() {
  69. var map = this.maps[this.api];
  70. map.SetDashboardSize(VEDashboardSize.Normal);
  71. this.addControlsArgs.pan=true;
  72. this.addControlsArgs.zoom = 'large';
  73. },
  74. addMapTypeControls: function() {
  75. var map = this.maps[this.api];
  76. map.addTypeControl();
  77. },
  78. dragging: function(on) {
  79. var map = this.maps[this.api];
  80. if(on){
  81. map.enableDragMap();
  82. }
  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 vzoom = zoom;
  91. map.SetCenterAndZoom(new VELatLong(point.lat,point.lon), vzoom)
  92. },
  93. addMarker: function(marker, old) {
  94. var map = this.maps[this.api];
  95. marker.pinID = "mspin-"+new Date().getTime()+'-'+(Math.floor(Math.random()*Math.pow(2,16)));
  96. var pin = marker.toProprietary(this.api);
  97. map.AddShape(pin);
  98. //give onclick event
  99. //give on double click event
  100. //give on close window
  101. //return the marker
  102. return pin;
  103. },
  104. removeMarker: function(marker) {
  105. var map = this.maps[this.api];
  106. var id = marker.proprietary_marker.GetID();
  107. var microsoftShape = map.GetShapeByID(id);
  108. map.DeleteShape(microsoftShape);
  109. },
  110. removeAllMarkers: function() {
  111. var map = this.maps[this.api];
  112. // TODO: Add provider code
  113. },
  114. declutterMarkers: function(opts) {
  115. var map = this.maps[this.api];
  116. // TODO: Add provider code
  117. },
  118. addPolyline: function(polyline, old) {
  119. var map = this.maps[this.api];
  120. var pl = polyline.toProprietary(this.api);
  121. pl.HideIcon();//hide the icon VE automatically displays
  122. map.AddShape(pl);
  123. return pl;
  124. },
  125. removePolyline: function(polyline) {
  126. var map = this.maps[this.api];
  127. var id = polyline.proprietary_polyline.GetID();
  128. var microsoftShape = map.GetShapeByID(id);
  129. map.DeleteShape(microsoftShape);
  130. },
  131. getCenter: function() {
  132. var map = this.maps[this.api];
  133. var LL = map.GetCenter();
  134. var point = new mxn.LatLonPoint(LL.Latitude, LL.Longitude);
  135. return point;
  136. },
  137. setCenter: function(point, options) {
  138. var map = this.maps[this.api];
  139. var pt = point.toProprietary(this.api);
  140. map.SetCenter(new VELatLong(point.lat, point.lon));
  141. },
  142. setZoom: function(zoom) {
  143. var map = this.maps[this.api];
  144. map.SetZoomLevel(zoom);
  145. },
  146. getZoom: function() {
  147. var map = this.maps[this.api];
  148. var zoom = map.GetZoomLevel();
  149. return zoom;
  150. },
  151. getZoomLevelForBoundingBox: function( bbox ) {
  152. var map = this.maps[this.api];
  153. // NE and SW points from the bounding box.
  154. var ne = bbox.getNorthEast();
  155. var sw = bbox.getSouthWest();
  156. var zoom;
  157. // TODO: Add provider code
  158. return zoom;
  159. },
  160. setMapType: function(type) {
  161. var map = this.maps[this.api];
  162. switch(type) {
  163. case mxn.Mapstraction.ROAD:
  164. map.SetMapStyle(VEMapStyle.Road);
  165. break;
  166. case mxn.Mapstraction.SATELLITE:
  167. map.SetMapStyle(VEMapStyle.Aerial);
  168. break;
  169. case mxn.Mapstraction.HYBRID:
  170. map.SetMapStyle(VEMapStyle.Hybrid);
  171. break;
  172. default:
  173. map.SetMapStyle(VEMapStyle.Road);
  174. }
  175. },
  176. getMapType: function() {
  177. var map = this.maps[this.api];
  178. var mode = map.GetMapStyle();
  179. switch(mode){
  180. case VEMapStyle.Aerial:
  181. return mxn.Mapstraction.SATELLITE;
  182. case VEMapStyle.Road:
  183. return mxn.Mapstraction.ROAD;
  184. case VEMapStyle.Hybrid:
  185. return mxn.Mapstraction.HYBRID;
  186. default:
  187. return null;
  188. }
  189. },
  190. getBounds: function () {
  191. var map = this.maps[this.api];
  192. view = map.GetMapView();
  193. var topleft = view.TopLeftLatLong;
  194. var bottomright = view.BottomRightLatLong;
  195. return new mxn.BoundingBox(bottomright.Latitude,topleft.Longitude,topleft.Latitude, bottomright.Longitude );
  196. },
  197. setBounds: function(bounds){
  198. var map = this.maps[this.api];
  199. var sw = bounds.getSouthWest();
  200. var ne = bounds.getNorthEast();
  201. var rec = new VELatLongRectangle(new VELatLong(ne.lat, ne.lon), new VELatLong(sw.lat, sw.lon));
  202. map.SetMapView(rec);
  203. },
  204. addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
  205. var map = this.maps[this.api];
  206. // TODO: Add provider code
  207. },
  208. setImagePosition: function(id, oContext) {
  209. var map = this.maps[this.api];
  210. var topLeftPoint; var bottomRightPoint;
  211. // TODO: Add provider code
  212. // oContext.pixels.top = ...;
  213. // oContext.pixels.left = ...;
  214. // oContext.pixels.bottom = ...;
  215. // oContext.pixels.right = ...;
  216. },
  217. addOverlay: function(url, autoCenterAndZoom) {
  218. var map = this.maps[this.api];
  219. var layer = new VEShapeLayer();
  220. var mlayerspec = new VEShapeSourceSpecification(VEDataType.GeoRSS, url, layer);
  221. map.AddShapeLayer(layer);
  222. },
  223. addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
  224. throw 'Not implemented';
  225. },
  226. toggleTileLayer: function(tile_url) {
  227. throw 'Not implemented';
  228. },
  229. getPixelRatio: function() {
  230. throw 'Not implemented';
  231. },
  232. mousePosition: function(element) {
  233. var locDisp = document.getElementById(element);
  234. if (locDisp != null) {
  235. var map = this.maps[this.api];
  236. map.AttachEvent("onmousemove", function(veEvent){
  237. var latlon = map.PixelToLatLong(new VEPixel(veEvent.mapX, veEvent.mapY));
  238. var loc = latlon.Latitude.toFixed(4) + " / " + latlon.Longitude.toFixed(4);
  239. locDisp.innerHTML = loc;
  240. });
  241. locDisp.innerHTML = "0.0000 / 0.0000";
  242. }
  243. }
  244. },
  245. LatLonPoint: {
  246. toProprietary: function() {
  247. return new VELatLong(this.lat, this.lon);
  248. },
  249. fromProprietary: function(mpoint) {
  250. this.lat =mpoint.Latitude;
  251. this.lon =mpoint.Longitude;
  252. }
  253. },
  254. Marker: {
  255. toProprietary: function() {
  256. var mmarker = new VEShape(VEShapeType.Pushpin, this.location.toProprietary('microsoft'));
  257. return mmarker;
  258. },
  259. openBubble: function() {
  260. var mmarker = this.proprietary_marker;
  261. map.ClearInfoBoxStyles();
  262. mmarker.SetTitle(this.infoBubble);
  263. },
  264. hide: function() {
  265. this.proprietary_marker.hide();
  266. },
  267. show: function() {
  268. this.proprietary_marker_unhide();
  269. },
  270. update: function() {
  271. throw 'Not implemented';
  272. }
  273. },
  274. Polyline: {
  275. toProprietary: function() {
  276. var mpoints =[];
  277. for(var i =0, length = this.points.length; i < length; i++)
  278. {
  279. mpoints.push(this.points[i].toProprietary('microsoft'));
  280. }
  281. var mpolyline = new VEShape(VEShapeType.Polyline, mpoints);
  282. if(this.color){
  283. var color = new mxn.util.Color(this.color);
  284. var opacity = (typeof(this.opacity) == 'undefined' || this.opacity === null) ? 1.0 : this.opacity;
  285. var vecolor = new VEColor(color.red, color.green, color.blue, opacity);
  286. mpolyline.SetLineColor(vecolor);
  287. }
  288. // TODO ability to change line width
  289. return mpolyline;
  290. },
  291. show: function() {
  292. this.proprietary_polyline.Show();
  293. },
  294. hide: function() {
  295. this.proprietary_polyline.Hide();
  296. }
  297. }
  298. });