📄 mapstraction.js
字号:
if (this.controls) { while (ctl = this.controls.pop()) { map.removeControl(ctl);}} else { this.controls = new Array();}c = this.controls; if ( args.pan ) { c.unshift(new MQPanControl()); map.addControl(c[0], new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,0)));}if ( args.zoom == 'large' ) { c.unshift(new MQLargeZoomControl()); map.addControl(c[0], new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,0)));}else if ( args.zoom == 'small' ) { c.unshift(new MQZoomControl()); map.addControl(c[0], new MQMapCornerPlacement(MQMapCorner.BOTTOM_LEFT, new MQSize(0,0)));}if ( args.map_type ) { c.unshift(new MQViewControl()); map.addControl(c[0], new MQMapCornerPlacement(MQMapCorner.TOP_RIGHT, new MQSize(0,0)));}break;}}Mapstraction.prototype.addSmallControls = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addSmallControls();} ); return;}var map = this.maps[this.api]; switch (this.api) { case 'yahoo':map.addPanControl(); map.addZoomShort(); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'small'; break; case 'google':case 'openstreetmap':map.addControl(new GSmallMapControl()); this.addControlsArgs.zoom = 'small'; break; case 'openlayers':map.addControl(new OpenLayers.Control.ZoomBox()); map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); break; case 'multimap':smallPanzoomWidget = new MMSmallPanZoomWidget(); map.addWidget( smallPanzoomWidget ); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'small'; break; case 'mapquest':map.addControl(new MQZoomControl(map)); map.addControl(new PanControl(map)); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'small'; break;}}Mapstraction.prototype.addLargeControls = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addLargeControls();} ); return;}var map = this.maps[this.api]; switch (this.api) { case 'yahoo':map.addPanControl(); map.addZoomLong(); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'large'; break; case 'openlayers':map.addControl(new OpenLayers.Control.PanZoomBar()); break; case 'google':map.addControl(new GMapTypeControl()); map.addControl(new GOverviewMapControl()) ; this.addControlsArgs.overview = true; this.addControlsArgs.map_type = true; case 'openstreetmap':map.addControl(new GLargeMapControl()); map.addControl(new GScaleControl()) ; this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'large'; this.addControlsArgs.scale = true; break; case 'multimap':panzoomWidget = new MMPanZoomWidget(); map.addWidget( panzoomWidget ); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'large'; break; case 'mapquest':map.addControl(new MQLargeZoomControl(map)); map.addControl(new PanControl(map)); map.addControl(new MQViewControl(map)); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'large'; this.addControlsArgs.map_type = true; break;}}Mapstraction.prototype.addMapTypeControls = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addMapTypeControls();} ); return;}var map = this.maps[this.api]; switch (this.api) { case 'yahoo':map.addTypeControl(); break; case 'google':case 'openstreetmap':map.addControl(new GMapTypeControl()); break; case 'multimap':map.addWidget( new MMMapTypeWidget() ); break; case 'mapquest':map.addControl(new MQViewControl(map)); break; case 'openlayers':map.addControl( new OpenLayers.Control.LayerSwitcher({'ascending':false}) ); break;}}Mapstraction.prototype.dragging = function(on) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.dragging(on);} ); return;}var map = this.maps[this.api]; switch (this.api) { case 'google':case 'openstreetmap':if (on) { map.enableDragging();} else { map.disableDragging();}break; case 'yahoo':if (on) { map.enableDragMap();} else { map.disableDragMap();}break; case 'multimap':if (on) { map.setOption("drag","dragmap");} else { map.setOption("drag","");}break; case 'mapquest':map.enableDragging(on); break;}}Mapstraction.prototype.setCenterAndZoom = function(point, zoom) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.setCenterAndZoom(point, zoom);} ); return;}var map = this.maps[this.api]; switch (this.api) { case 'yahoo':var yzoom = 18 - zoom; map.drawZoomAndCenter(point.toYahoo(),yzoom); break; case 'google':case 'openstreetmap':map.setCenter(point.toGoogle(), zoom); break; case 'microsoft':map.SetCenterAndZoom(point.toMicrosoft(),zoom); break; case 'openlayers':map.setCenter(point.toOpenLayers(), zoom); break; case 'multimap':map.goToPosition( new MMLatLon( point.lat, point.lng ) ); map.setZoomFactor( zoom ); break; case 'map24':var newSettings = new Object(); newSettings.Latitude = point.lat*60; newSettings.Longitude = point.lon*60; var client = map.MapClient['Static']; var dLon = getDegreesFromGoogleZoomLevel(client.getCanvasSize().Width,zoom); newSettings.MinimumWidth = lonToMetres (dLon, point.lat); Map24.MapApplication.center ( newSettings ); break; case 'mapquest':map.setCenter(new MQLatLng( point.lat, point.lng ), zoom - 3 ); break; case 'freeearth':if (this.freeEarthLoaded) { map.setTargetLatLng( point.toFreeEarth() );} else { myself = this; this.freeEarthOnLoad.push( function() { myself.setCenterAndZoom(point);} );}break; default:if(this.debug)alert(this.api + ' not supported by Mapstraction.setCenterAndZoom');}}Mapstraction.prototype.addMarker = function(marker,old) { var map = this.maps[this.api]; marker.mapstraction = this; marker.api = this.api; marker.map = this.maps[this.api]; if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addMarker(marker, old);} ); return;}switch (this.api) { case 'yahoo':var ypin = marker.toYahoo(); marker.setChild(ypin); map.addOverlay(ypin); if (! old) { this.markers.push(marker);}break; case 'google':case 'openstreetmap':var gpin = marker.toGoogle(); marker.setChild(gpin); map.addOverlay(gpin); if (! old) { this.markers.push(marker);}break; case 'microsoft':var mpin = marker.toMicrosoft(); marker.setChild(mpin); map.AddPushpin(mpin); if (! old) { this.markers.push(marker);}break; case 'openlayers':if (!this.layers['markers']){ this.layers['markers'] = new OpenLayers.Layer.Markers("markers"); map.addLayer(this.layers['markers']);}var olmarker = marker.toOpenLayers(); marker.setChild(olmarker); this.layers['markers'].addMarker(olmarker); if (! old) { this.markers.push(marker);}break; case 'multimap':var mmpin = marker.toMultiMap(); marker.setChild(mmpin); map.addOverlay(mmpin); if (! old) { this.markers.push(marker);}break; case 'map24':var m24pin = marker.toMap24(); marker.setChild(m24pin); m24pin.commit(); if (! old) { this.markers.push(marker);}break; case 'mapquest':var mqpin = marker.toMapQuest(); marker.setChild(mqpin); map.addPoi(mqpin); if (! old) { this.markers.push(marker);}break; case 'freeearth':var fepin = marker.toFreeEarth(); marker.setChild(fepin); map.addOverlay(fepin); if (! old) { this.markers.push(marker);}break; default:if(this.debug)alert(this.api + ' not supported by Mapstraction.addMarker');}}Mapstraction.prototype.addMarkerWithData = function(marker,data) { marker.addData(data); this.addMarker(marker);}Mapstraction.prototype.addPolylineWithData = function(polyline,data) { polyline.addData(data); this.addPolyline(polyline);}Mapstraction.prototype.removeMarker = function(marker) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.removeMarker(marker);} ); return;}var map = this.maps[this.api]; var tmparray = new Array(); while(this.markers.length > 0){ current_marker = this.markers.pop(); if(marker == current_marker) { switch (this.api) { case 'google':case 'openstreetmap':map.removeOverlay(marker.proprietary_marker); break; case 'yahoo':map.removeOverlay(marker.proprietary_marker); break; case 'microsoft':map.DeletePushpin(marker.pinID); break; case 'multimap':map.removeOverlay(marker.proprietary_marker); break; case 'mapquest':map.removePoi(marker.proprietary_marker); break; case 'map24':marker.proprietary_marker.remove(); break; case 'openlayers':this.layers['markers'].removeMarker(marker.proprietary_marker); marker.proprietary_marker.destroy(); break;}marker.onmap = false; break;} else { tmparray.push(current_marker);}}this.markers = this.markers.concat(tmparray);}Mapstraction.prototype.removeAllMarkers = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.removeAllMarkers();} ); return;}var map = this.maps[this.api]; switch (this.api) { case 'yahoo':map.removeMarkersAll(); break; case 'google':case 'openstreetmap':map.clearOverlays(); break; case 'microsoft':map.DeleteAllPushpins(); break; case 'multimap':map.removeAllOverlays(); break; case 'mapquest':map.removeAllPois(); break; case 'map24':var current_marker; while(this.markers.length > 0) { current_marker = this.markers.pop(); current_marker.proprietary_marker.remove();}break; case 'openlayers':this.layers['markers'].clearMarkers(); break; default:if(this.debug)alert(this.api + ' not supported by Mapstraction.removeAllMarkers');}this.markers = new Array();}Mapstraction.prototype.addPolyline = function(polyline,old) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addPolyline(polyline,old);} ); return;}var map = this.maps[this.api]; switch (this.api) { case 'yahoo':ypolyline = polyline.toYahoo(); polyline.setChild(ypolyline); map.addOverlay(ypolyline); if(!old) {this.polylines.push(polyline);}break; case 'google':case 'openstreetmap':gpolyline = polyline.toGoogle(); polyline.setChild(gpolyline); map.addOverlay(gpolyline); if(!old) {this.polylines.push(polyline);}break; case 'microsoft':mpolyline = polyline.toMicrosoft(); polyline.setChild(mpolyline); map.AddPolyline(mpolyline); if(!old) {this.polylines.push(polyline);}break; case 'openlayers':if(this.debug)alert(this.api + ' not supported by Mapstraction.addPolyline'); break; case 'multimap':mmpolyline = polyline.toMultiMap(); polyline.setChild(mmpolyline); map.addOverlay( mmpolyline ); if(!old) {this.polylines.push(polyline);}break; case 'mapquest':mqpolyline = polyline.toMapQuest(); polyline.setChild(mqpolyline); map.addOverlay( mqpolyline ); if(!old) {this.polylines.push(polyline);}break; case 'map24':var m24polyline = polyline.toMap24(); polyline.setChild(m24polyline); m24polyline.commit(); if(!old) {this.polylines.push(polyline);}break; default:if(this.debug)alert(this.api + ' not supported by Mapstraction.addPolyline');}}Mapstraction.prototype.removePolyline = function(polyline) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.removePolyline(polyline);} ); return;}var map = this.maps[this.api]; var tmparray = new Array(); while(this.polylines.length > 0){ current_polyline = this.polylines.pop(); if(polyline == current_polyline) { switch (this.api) { case 'google':case 'openstreetmap':map.removeOverlay(polyline.proprietary_polyline); break; case 'yahoo':map.removeOverlay(polyline.proprietary_polyline); break; case 'microsoft':map.DeletePolyline(polyline.pllID); break; case 'multimap':polyline.proprietary_polyline.remove(); break; case 'mapquest':map.removeOverlay(polyline.proprietary_polyline); break; case 'map24':polyline.proprietary_polyline.remove(); break;}polyline.onmap = false; break;} else { tmparray.push(current_polyline);}}this.polylines = this.polylines.concat(tmparray);}Mapstraction.prototype.removeAllPolylines = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.removeAllPolylines();} ); return;}var map = this.maps[this.api]; switch (this.api) { case 'yahoo':for(var i = 0, length = this.polylines.length;i < length;i++){ map.removeOverlay(this.polylines[i].proprietary_polyline);}break; case 'google':case 'openstreetmap':for(var i = 0, length = this.polylines.length;i < length;i++){ map.removeOverlay(this.polylines[i].proprietary_polyline);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -