]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Mapstraction/js/mxn.microsoft.core.js
first pass at Mapstraction plugin
[quix0rs-gnu-social.git] / plugins / Mapstraction / js / mxn.microsoft.core.js
diff --git a/plugins/Mapstraction/js/mxn.microsoft.core.js b/plugins/Mapstraction/js/mxn.microsoft.core.js
new file mode 100644 (file)
index 0000000..292e45d
--- /dev/null
@@ -0,0 +1,402 @@
+mxn.register('microsoft', {    \r
+\r
+Mapstraction: {\r
+       \r
+       init: function(element, api) {          \r
+               var me = this;\r
+               if (VEMap){\r
+                       this.maps[api] = new VEMap(element.id);\r
+        \r
+                       \r
+                       \r
+                       this.maps[api].AttachEvent('onclick', function(event){\r
+                               me.clickHandler();\r
+                               var x = event.mapX;\r
+                               var y = event.mapY;\r
+                           var pixel = new VEPixel(x,y);\r
+                               me.click.fire({'location': new mxn.LatLonPoint(pixel.Latitude, pixel.Longitude)});\r
+                       \r
+                               \r
+                       });\r
+                       this.maps[api].AttachEvent('onendzoom', function(event){\r
+                               me.moveendHandler(me);\r
+                               me.changeZoom.fire();\r
+                               \r
+                               \r
+                       });\r
+                       this.maps[api].AttachEvent('onendpan', function(event){\r
+                               me.moveendHandler(me);\r
+                               me.endPan.fire();\r
+                               \r
+                               \r
+                       });\r
+                       this.maps[api].AttachEvent('onchangeview', function(event){\r
+                               me.endPan.fire();\r
+                               \r
+                               \r
+                       });\r
+                       this.maps[api].LoadMap();\r
+                       document.getElementById("MSVE_obliqueNotification").style.visibility = "hidden"; \r
+               \r
+                       //removes the bird's eye pop-up\r
+                       this.loaded[api] = true;\r
+                       me.load.fire(); \r
+               }\r
+               else{\r
+                       alert(api + ' map script not imported')\r
+                       \r
+               }\r
+       \r
+       },\r
+       \r
+       applyOptions: function(){\r
+               var map = this.maps[this.api];\r
+               if(this.options.enableScrollWheelZoom){\r
+                       map.enableContinuousZoom();\r
+                       map.enableScrollWheelZoom();    \r
+               \r
+               }\r
+               \r
+       },\r
+\r
+       resizeTo: function(width, height){      \r
+               this.maps[this.api].Resize(width, height);\r
+       },\r
+\r
+       addControls: function( args ) {\r
+               var map = this.maps[this.api];\r
+        \r
+       if (args.pan) {\r
+                       map.SetDashboardSize(VEDashboardSize.Normal);\r
+               }\r
+               else {\r
+                       map.SetDashboardSize(VEDashboardSize.Tiny)\r
+               }\r
+\r
+       if (args.zoom == 'large') {\r
+                       map.SetDashboardSize(VEDashboardSize.Small)\r
+               }\r
+               else if ( args.zoom == 'small' ) {\r
+                       map.SetDashboardSize(VEDashboardSize.Tiny)\r
+               }\r
+               else {\r
+                       map.HideDashboard();\r
+                       map.HideScalebar();\r
+               }\r
+               \r
+               \r
+       },\r
+\r
+       addSmallControls: function() {\r
+               var map = this.maps[this.api];\r
+               map.SetDashboardSize(VEDashboardSize.Tiny);\r
+               \r
+       },\r
+\r
+       addLargeControls: function() {\r
+               var map = this.maps[this.api];\r
+               map.SetDashboardSize(VEDashboardSize.Normal);\r
+               this.addControlsArgs.pan=true;\r
+               this.addControlsArgs.zoom = 'large';\r
+       },\r
+\r
+       addMapTypeControls: function() {\r
+               var map = this.maps[this.api];\r
+               map.addTypeControl();\r
+       \r
+       },\r
+\r
+       dragging: function(on) {\r
+               var map = this.maps[this.api];\r
+               if(on){\r
+                       map.enableDragMap();\r
+               }\r
+               else{\r
+                       map.disableDragMap();\r
+                       \r
+               }\r
+       },\r
+\r
+       setCenterAndZoom: function(point, zoom) { \r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               var vzoom =  zoom;\r
+               map.SetCenterAndZoom(new VELatLong(point.lat,point.lon), vzoom)\r
+               \r
+       },\r
+       \r
+       addMarker: function(marker, old) {\r
+               var map = this.maps[this.api];\r
+                marker.pinID = "mspin-"+new Date().getTime()+'-'+(Math.floor(Math.random()*Math.pow(2,16)));\r
+               var pin = marker.toProprietary(this.api);\r
+               map.AddShape(pin);\r
+               //give onclick event\r
+               //give on double click event\r
+               //give on close window\r
+               //return the marker\r
+               \r
+               \r
+               return pin;\r
+       },\r
+\r
+       removeMarker: function(marker) {\r
+               var map = this.maps[this.api];\r
+               var id = marker.proprietary_marker.GetID();\r
+               var microsoftShape = map.GetShapeByID(id);\r
+               map.DeleteShape(microsoftShape);\r
+       },\r
+\r
+       removeAllMarkers: function() {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+       \r
+       declutterMarkers: function(opts) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       addPolyline: function(polyline, old) {\r
+               var map = this.maps[this.api];\r
+               var pl = polyline.toProprietary(this.api);\r
+               pl.HideIcon();//hide the icon VE automatically displays\r
+               map.AddShape(pl);\r
+               \r
+               return pl;\r
+       },\r
+\r
+       removePolyline: function(polyline) {\r
+               var map = this.maps[this.api];\r
+               var id = polyline.proprietary_polyline.GetID();\r
+               var microsoftShape = map.GetShapeByID(id);\r
+               map.DeleteShape(microsoftShape);\r
+       },\r
+       \r
+       getCenter: function() {\r
+               var map = this.maps[this.api];\r
+               var LL = map.GetCenter();\r
+               var point = new mxn.LatLonPoint(LL.Latitude, LL.Longitude);\r
+               return point;\r
+               \r
+       },\r
\r
+       setCenter: function(point, options) {\r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               map.SetCenter(new VELatLong(point.lat, point.lon));\r
+               \r
+               \r
+       },\r
+\r
+       setZoom: function(zoom) {\r
+               var map = this.maps[this.api];\r
+               map.SetZoomLevel(zoom);\r
+               \r
+               \r
+       },\r
+       \r
+       getZoom: function() {\r
+               var map = this.maps[this.api];\r
+               var zoom = map.GetZoomLevel();\r
+               \r
+               return zoom;\r
+       },\r
+\r
+       getZoomLevelForBoundingBox: function( bbox ) {\r
+               var map = this.maps[this.api];\r
+               // NE and SW points from the bounding box.\r
+               var ne = bbox.getNorthEast();\r
+               var sw = bbox.getSouthWest();\r
+               var zoom;\r
+               \r
+               // TODO: Add provider code\r
+               \r
+               return zoom;\r
+       },\r
+\r
+       setMapType: function(type) {\r
+               var map = this.maps[this.api];\r
+               switch(type) {\r
+                       case mxn.Mapstraction.ROAD:\r
+                               map.SetMapStyle(VEMapStyle.Road);\r
+                               break;\r
+                       case mxn.Mapstraction.SATELLITE:\r
+                               map.SetMapStyle(VEMapStyle.Aerial);\r
+                               break;\r
+                       case mxn.Mapstraction.HYBRID:\r
+                               map.SetMapStyle(VEMapStyle.Hybrid);\r
+                               break;\r
+                       default:\r
+                               map.SetMapStyle(VEMapStyle.Road);\r
+               }        \r
+       },\r
+\r
+       getMapType: function() {\r
+               var map = this.maps[this.api];\r
+               var mode = map.GetMapStyle();\r
+               switch(mode){\r
+                       case VEMapStyle.Aerial:\r
+                               return mxn.Mapstraction.SATELLITE;\r
+                       case VEMapStyle.Road:\r
+                               return mxn.Mapstraction.ROAD;\r
+                       case VEMapStyle.Hybrid:\r
+                               return mxn.Mapstraction.HYBRID;\r
+                       default:\r
+                               return null;\r
+                       \r
+               }\r
+       \r
+\r
+       },\r
+\r
+       getBounds: function () {\r
+               var map = this.maps[this.api];\r
+               view = map.GetMapView();\r
+               var topleft = view.TopLeftLatLong;\r
+               var bottomright = view.BottomRightLatLong;\r
+               \r
+               return new mxn.BoundingBox(bottomright.Latitude,topleft.Longitude,topleft.Latitude, bottomright.Longitude );\r
+       },\r
+\r
+       setBounds: function(bounds){\r
+               var map = this.maps[this.api];\r
+               var sw = bounds.getSouthWest();\r
+               var ne = bounds.getNorthEast();\r
+               \r
+               var rec = new VELatLongRectangle(new VELatLong(ne.lat, ne.lon), new VELatLong(sw.lat, sw.lon));\r
+               map.SetMapView(rec);\r
+               \r
+               \r
+               \r
+       },\r
+\r
+       addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       setImagePosition: function(id, oContext) {\r
+               var map = this.maps[this.api];\r
+               var topLeftPoint; var bottomRightPoint;\r
+\r
+               // TODO: Add provider code\r
+\r
+       //      oContext.pixels.top = ...;\r
+       //      oContext.pixels.left = ...;\r
+       //      oContext.pixels.bottom = ...;\r
+       //      oContext.pixels.right = ...;\r
+       },\r
+       \r
+       addOverlay: function(url, autoCenterAndZoom) {\r
+               var map = this.maps[this.api];\r
+           var layer = new VEShapeLayer(); \r
+           var mlayerspec = new VEShapeSourceSpecification(VEDataType.GeoRSS, url, layer);\r
+               map.AddShapeLayer(layer);\r
+         \r
+       \r
+               \r
+       },\r
+\r
+       addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       toggleTileLayer: function(tile_url) {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       getPixelRatio: function() {\r
+               throw 'Not implemented';\r
+       },\r
+       \r
+       mousePosition: function(element) {\r
+               var locDisp = document.getElementById(element);\r
+               if (locDisp != null) {\r
+                       var map = this.maps[this.api];\r
+                       map.AttachEvent("onmousemove", function(veEvent){\r
+                               var latlon = map.PixelToLatLong(new VEPixel(veEvent.mapX, veEvent.mapY));\r
+                               var loc = latlon.Latitude.toFixed(4) + " / " + latlon.Longitude.toFixed(4);\r
+                               locDisp.innerHTML = loc;\r
+\r
+                       });\r
+                       locDisp.innerHTML = "0.0000 / 0.0000";\r
+               }\r
+       }\r
+},\r
+\r
+LatLonPoint: {\r
+       \r
+       toProprietary: function() {\r
+               return  new VELatLong(this.lat, this.lon);\r
+       },\r
+\r
+       fromProprietary: function(mpoint) {\r
+               this.lat =mpoint.Latitude;\r
+               this.lon =mpoint.Longitude;\r
+       }\r
+       \r
+},\r
+\r
+Marker: {\r
+       \r
+       toProprietary: function() {\r
+               var mmarker = new VEShape(VEShapeType.Pushpin, this.location.toProprietary('microsoft'));\r
+       \r
+       \r
+               return mmarker;\r
+               \r
+       },\r
+\r
+       openBubble: function() {                \r
+               var mmarker = this.proprietary_marker;\r
+               map.ClearInfoBoxStyles();\r
+               mmarker.SetTitle(this.infoBubble);\r
+       },\r
+\r
+       hide: function() {\r
+               this.proprietary_marker.hide();\r
+       },\r
+\r
+       show: function() {\r
+               this.proprietary_marker_unhide();\r
+       },\r
+\r
+       update: function() {\r
+               throw 'Not implemented';\r
+       }\r
+       \r
+},\r
+\r
+Polyline: {\r
+\r
+       toProprietary: function() {\r
+               var mpoints =[];\r
+               for(var i =0, length = this.points.length; i < length; i++)\r
+               {\r
+                       mpoints.push(this.points[i].toProprietary('microsoft'));\r
+               }\r
+               var mpolyline = new VEShape(VEShapeType.Polyline, mpoints);\r
+               if(this.color){\r
+                       var color = new mxn.util.Color(this.color);\r
+                       var opacity = (typeof(this.opacity) == 'undefined' || this.opacity === null) ? 1.0 : this.opacity;\r
+                       var vecolor = new VEColor(color.red, color.green, color.blue, opacity);\r
+                       mpolyline.SetLineColor(vecolor);\r
+               }\r
+               //      TODO ability to change line width\r
+               return mpolyline;\r
+       },\r
+               \r
+       show: function() {\r
+                       this.proprietary_polyline.Show();\r
+       },\r
+\r
+       hide: function() {\r
+                       this.proprietary_polyline.Hide();\r
+       }\r
+       \r
+}\r
+\r
+});\r