codesite-noreply at google.com
2009-May-28 04:54 UTC
[Mapstraction] [mapstraction commit] r6 - First pass at Microsoft Virtual Earth functionality
Author: k8chapman Date: Wed May 27 21:53:20 2009 New Revision: 6 Added: trunk/source/mxn.microsoft.core.js Log: First pass at Microsoft Virtual Earth functionality Added: trunk/source/mxn.microsoft.core.js =============================================================================--- (empty file) +++ trunk/source/mxn.microsoft.core.js Wed May 27 21:53:20 2009 @@ -0,0 +1,384 @@ +mxn.register(''microsoft'', { + +Mapstraction: { + + init: function(element, api) { + var me = this; + if (VEMap){ + this.maps[api] = new VEMap(element.id); + + this.maps[api].AttachEvent(''onclick'', function(event){ + me.clickHandler(); + var x = event.mapX; + var y = event.mapY; + var pixel = new VEPixel(x,y); + var ll= map.PixelTolatLong(pixel); + me.click.fire({''location'': new mxn.LatLonPoint(ll.Latitude, ll.Longitude)}); + + + }); + this.maps[api].AttachEvent(''onendzoom'', function(event){ + me.moveendHandler(me); + me.changeZoom.fire(); + + + }); + this.maps[api].AttachEvent(''onendpan'', function(event){ + me.moveendHandler(me); + me.endPan.fire(); + + + }); + this.maps[api].AttachEvent(''onchangeview'', function(event){ + me.endPan.fire(); + + + }); + this.maps[api].LoadMap(); + document.getElementById("MSVE_obliqueNotification").style.visibility = "hidden"; + //removes the bird''s eye pop-up + this.loaded[api] = true; + me.load.fire(); + } + else{ + alert(api + '' map script not imported'') + + } + + }, + + applyOptions: function(){ + var map = this.maps[this.api]; + if(this.options.enableScrollWheelZoom){ + map.enableContinuousZoom(); + map.enableScrollWheelZoom(); + + } + + }, + + resizeTo: function(width, height){ + this.maps[this.api].Resize(width, height); + }, + + addControls: function( args ) { + var map = this.maps[this.api]; + + if (args.pan) { + map.SetDashboardSize(VEDashboardSize.Normal); + } + else { + map.SetDashboardSize(VEDashboardSize.Tiny) + } + + if (args.zoom == ''large'') { + map.SetDashboardSize(VEDashboardSize.Small) + } + else if ( args.zoom == ''small'' ) { + map.SetDashboardSize(VEDashboardSize.Tiny) + } + else { + map.HideDashboard(); + map.HideScalebar(); + } + + + }, + + addSmallControls: function() { + var map = this.maps[this.api]; + map.SetDashboardSize(VEDashboardSize.Tiny); + + }, + + addLargeControls: function() { + var map = this.maps[this.api]; + map.SetDashboardSize(VEDashboardSize.Normal); + this.addControlsArgs.pan=true; + this.addControlsArgs.zoom = ''large''; + }, + + addMapTypeControls: function() { + var map = this.maps[this.api]; + map.addTypeControl(); + + }, + + dragging: function(on) { + var map = this.maps[this.api]; + if(on){ + map.enableDragMap(); + } + else{ + map.disableDragMap(); + + } + }, + + setCenterAndZoom: function(point, zoom) { + var map = this.maps[this.api]; + var pt = point.toProprietary(this.api); + var vzoom = zoom; + map.SetCenterAndZoom(new VELatLong(point.lat,point.lon), vzoom) + + }, + + addMarker: function(marker, old) { + var map = this.maps[this.api]; + var pin = marker.toProprietary(this.api); + map.AddShape(pin); + //give onclick event + //give on double click event + //give on close window + //return the marker + + + return pin; + }, + + removeMarker: function(marker) { + var map = this.maps[this.api]; + + // TODO: Add provider code + }, + + removeAllMarkers: function() { + var map = this.maps[this.api]; + + // TODO: Add provider code + }, + + declutterMarkers: function(opts) { + var map = this.maps[this.api]; + + // TODO: Add provider code + }, + + addPolyline: function(polyline, old) { + var map = this.maps[this.api]; + var pl = polyline.toProprietary(this.api); + pl.HideIcon();//hide the icon VE automatically displays + map.AddShape(pl); + + return pl; + }, + + removePolyline: function(polyline) { + var map = this.maps[this.api]; + + // TODO: Add provider code + }, + + getCenter: function() { + var map = this.maps[this.api]; + var LL = map.GetCenter(); + var point = new mxn.LatLonPoint(LL.Latitude, LL.Longitude); + return point; + + }, + + setCenter: function(point, options) { + var map = this.maps[this.api]; + var pt = point.toProprietary(this.api); + map.SetCenter(new VELatLong(point.lat, point.lon)); + + + }, + + setZoom: function(zoom) { + var map = this.maps[this.api]; + map.SetZoomLevel(zoom); + + + }, + + getZoom: function() { + var map = this.maps[this.api]; + var zoom = map.GetZoomLevel(); + + return zoom; + }, + + getZoomLevelForBoundingBox: function( bbox ) { + var map = this.maps[this.api]; + // NE and SW points from the bounding box. + var ne = bbox.getNorthEast(); + var sw = bbox.getSouthWest(); + var zoom; + + // TODO: Add provider code + + return zoom; + }, + + setMapType: function(type) { + var map = this.maps[this.api]; + switch(type) { + case mxn.Mapstraction.ROAD: + // TODO: Add provider code + break; + case mxn.Mapstraction.SATELLITE: + // TODO: Add provider code + break; + case mxn.Mapstraction.HYBRID: + // TODO: Add provider code + break; + default: + // TODO: Add provider code + } + }, + + getMapType: function() { + var map = this.maps[this.api]; + var mode = map.GetMapStyle(); + switch(mode){ + case VEMapStyle.Aerial: + return mxn.Mapstraction.SATELLITE; + case VEMapStyle.Road: + return mxn.Mapstraction.ROAD; + case VEMapStyle.Hybrid: + return mxn.Mapstraction.HYBRID; + default: + return null; + + } + + + }, + + getBounds: function () { + var map = this.maps[this.api]; + view = map.GetMapView(); + var topleft = view.TopLeftLatLong; + var bottomright = view.BottomRightLatLong; + + return new mxn.BoundingBox(bottomright.Latitude,topleft.Longitude,topleft.Latitude, bottomright.Longitude ); + }, + + setBounds: function(bounds){ + var map = this.maps[this.api]; + var sw = bounds.getSouthWest(); + var ne = bounds.getNorthEast(); + + var rec = new VELatLongRectangle(new VELatLong(ne.lat, ne.lon), new VELatLong(sw.lat, sw.lon)); + map.SetMapView(rec); + + + + }, + + addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) { + var map = this.maps[this.api]; + + // TODO: Add provider code + }, + + setImagePosition: function(id, oContext) { + var map = this.maps[this.api]; + var topLeftPoint; var bottomRightPoint; + + // TODO: Add provider code + + // oContext.pixels.top = ...; + // oContext.pixels.left = ...; + // oContext.pixels.bottom = ...; + // oContext.pixels.right = ...; + }, + + addOverlay: function(url, autoCenterAndZoom) { + var map = this.maps[this.api]; + var layer = new VEShapeLayer(); + var mlayerspec = new VEShapeSourceSpecification(VEDataType.GeoRSS, url, layer); + map.AddShapeLayer(layer); + + + + }, + + addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) { + throw ''Not implemented''; + }, + + toggleTileLayer: function(tile_url) { + throw ''Not implemented''; + }, + + getPixelRatio: function() { + throw ''Not implemented''; + }, + + mousePosition: function(element) { + throw ''Not implemented''; + } +}, + +LatLonPoint: { + + toProprietary: function() { + return new VELatLong(this.lat, this.lon); + }, + + fromProprietary: function(mpoint) { + this.lat =mpoint.Latitude; + this.lon =mpoint.Longitude; + } + +}, + +Marker: { + + toProprietary: function() { + var mmarker = new VEShape(VEShapeType.Pushpin, this.location.toProprietary(''microsoft'')); + + + return mmarker; + + }, + + openBubble: function() { + var mmarker = this.proprietary_marker; + map.ClearInfoBoxStyles(); + mmarker.SetTitle(this.infoBubble); + }, + + hide: function() { + this.proprietary_marker.hide(); + }, + + show: function() { + this.proprietary_marker_unhide(); + }, + + update: function() { + throw ''Not implemented''; + } + +}, + +Polyline: { + + toProprietary: function() { + var mpoints =[]; + for(var i =0, length = this.points.length; i < length; i++) + { + mpoints.push(this.points[i].toProprietary(''microsoft'')); + } + var mpolyline = new VEShape(VEShapeType.Polyline, mpoints); + // mpolyline.SetLineColor(new VEColor(this.color, this.opacity)); + //TODO: transfer this.color to the ve color/opacity requirements + // mpolyline.SetLineWidth(this.width); + return mpolyline; + + }, + + show: function() { + throw ''Not implemented''; + }, + + hide: function() { + throw ''Not implemented''; + } + +} + +});