⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapstraction.js

📁 extjs + mysql + java
💻 JS
📖 第 1 页 / 共 5 页
字号:
return null;}break; default:if(this.debug)alert(this.api + ' not supported by Mapstraction.getMapType');}}Mapstraction.prototype.getBounds = function () { if(this.loaded[this.api] == false) { return null;}var map = this.maps[this.api]; switch (this.api) { case 'google':case 'openstreetmap':var gbox = map.getBounds(); var sw = gbox.getSouthWest(); var ne = gbox.getNorthEast(); return new BoundingBox(sw.lat(), sw.lng(), ne.lat(), ne.lng()); break; case 'openlayers':var olbox = map.calculateBounds(); break; case 'yahoo':var ybox = map.getBoundsLatLon(); return new BoundingBox(ybox.LatMin, ybox.LonMin, ybox.LatMax, ybox.LonMax); break; case 'microsoft':var mbox = map.GetMapView(); var nw = mbox.TopLeftLatLong; var se = mbox.BottomRightLatLong; return new BoundingBox(se.Latitude,nw.Longitude,nw.Latitude,se.Longitude); break; case 'multimap':var mmbox = map.getMapBounds(); var sw = mmbox.getSouthWest(); var ne = mmbox.getNorthEast(); return new BoundingBox(sw.lat, sw.lon, ne.lat, ne.lon); break; case 'mapquest':var mqbox = map.getMapBounds(); var se = mqbox.getLowerRightLatLng(); var nw = mqbox.getUpperLeftLatLng(); return new BoundingBox(se.lat, nw.lon, nw.lat, se.lon); break; case 'map24':var mv = map.MapClient['Static'].getCurrentMapView(); var se = mv.LowerRight; var nw = mv.TopLeft; return new BoundingBox (se.Latitude/60, nw.Longitude/60, nw.Latitude/60, se.Longitude/60 ); break; default:if(this.debug)alert(this.api + ' not supported by Mapstraction.getBounds');}}Mapstraction.prototype.setBounds = function(bounds){ if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.setBounds(bounds);} ); return;}var map = this.maps[this.api]; var sw = bounds.getSouthWest(); var ne = bounds.getNorthEast(); switch (this.api) { case 'google':case 'openstreetmap':var gbounds = new GLatLngBounds(new GLatLng(sw.lat,sw.lon),new GLatLng(ne.lat,ne.lon)); map.setCenter(gbounds.getCenter(), map.getBoundsZoomLevel(gbounds)); break; case 'openlayers':var bounds = new OpenLayers.Bounds(); bounds.extend(new LatLonPoint(sw.lat,sw.lon).toOpenLayers()); bounds.extend(new LatLonPoint(ne.lat,ne.lon).toOpenLayers()); map.zoomToExtent(bounds); break; case 'yahoo':if(sw.lon > ne.lon)sw.lon -= 360; var center = new YGeoPoint((sw.lat + ne.lat)/2, (ne.lon + sw.lon)/2); var container = map.getContainerSize(); for(var zoom = 1 ; zoom <= 17 ; zoom++){ var sw_pix = convertLatLonXY_Yahoo(sw,zoom); var ne_pix = convertLatLonXY_Yahoo(ne,zoom); if(sw_pix.x > ne_pix.x)sw_pix.x -= (1 << (26 - zoom)); if(Math.abs(ne_pix.x - sw_pix.x)<=container.width&& Math.abs(ne_pix.y - sw_pix.y) <= container.height){ map.drawZoomAndCenter(center,zoom); break;}}break; case 'microsoft':map.SetMapView([new VELatLong(sw.lat,sw.lon),new VELatLong(ne.lat,ne.lon)]); break; case 'multimap':var mmlocation = map.getBoundsZoomFactor( sw.toMultiMap(), ne.toMultiMap() ); var center = new LatLonPoint(mmlocation.coords.lat, mmlocation.coords.lon); this.setCenterAndZoom(center, mmlocation.zoom_factor); break; case 'mapquest':if(this.debug)alert(this.api + ' not supported by Mapstraction.setBounds'); break; case 'freeearth':var center = new LatLonPoint((sw.lat + ne.lat)/2, (ne.lon + sw.lon)/2); this.setCenter(center); break; case 'map24':var settings = new Object(); settings.Latitude = ((sw.lat+ne.lat) / 2) * 60; settings.Longitude = ((sw.lon+ne.lon) / 2) * 60; settings.MinimumWidth = lonToMetres(ne.lon-sw.lon, (ne.lat+sw.lat)/2); Map24.MapApplication.center ( settings ); break; default:if(this.debug)alert(this.api + ' not supported by Mapstraction.setBounds');}}Mapstraction.prototype.addImageOverlay = function(id, src, opacity, west, south, east, north) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addImageOverlay(id, src, opacity, west, south, east, north);} ); return;}var map = this.maps[this.api]; var b = document.createElement("img"); b.style.display = 'block'; b.setAttribute('id',id); b.setAttribute('src',src); b.style.position = 'absolute'; b.style.zIndex = 1; b.setAttribute('west',west); b.setAttribute('south',south); b.setAttribute('east',east); b.setAttribute('north',north); switch (this.api) { case 'google':case 'openstreetmap':map.getPane(G_MAP_MAP_PANE).appendChild(b); this.setImageOpacity(id, opacity); this.setImagePosition(id); GEvent.bind(map, "zoomend", this, function(){this.setImagePosition(id)}); GEvent.bind(map, "moveend", this, function(){this.setImagePosition(id)}); break; case 'multimap':map.getContainer().appendChild(b); this.setImageOpacity(id, opacity); this.setImagePosition(id); me = this; map.addEventHandler( 'changeZoom', function(eventType, eventTarget, arg1, arg2, arg3) { me.setImagePosition(id);}); map.addEventHandler( 'drag', function(eventType, eventTarget, arg1, arg2, arg3) { me.setImagePosition(id);}); map.addEventHandler( 'endPan', function(eventType, eventTarget, arg1, arg2, arg3) { me.setImagePosition(id);}); break; default:b.style.display = 'none'; if(this.debug)alert(this.api + "not supported by Mapstraction.addImageOverlay not supported"); break;}}Mapstraction.prototype.setImageOpacity = function(id, opacity) { if(opacity<0){opacity=0;} if(opacity>=100){opacity=100;}var c=opacity/100; var d=document.getElementById(id); if(typeof(d.style.filter)=='string'){d.style.filter='alpha(opacity:'+opacity+')';}if(typeof(d.style.KHTMLOpacity)=='string'){d.style.KHTMLOpacity=c;}if(typeof(d.style.MozOpacity)=='string'){d.style.MozOpacity=c;}if(typeof(d.style.opacity)=='string'){d.style.opacity=c;}}Mapstraction.prototype.setImagePosition = function(id) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.setImagePosition(id);} ); return;}var map = this.maps[this.api]; var x = document.getElementById(id); var d; var e; switch (this.api) { case 'google':case 'openstreetmap':d = map.fromLatLngToDivPixel(new GLatLng(x.getAttribute('north'), x.getAttribute('west'))); e = map.fromLatLngToDivPixel(new GLatLng(x.getAttribute('south'), x.getAttribute('east'))); break; case 'multimap':d = map.geoPosToContainerPixels(new MMLatLon(x.getAttribute('north'), x.getAttribute('west'))); e = map.geoPosToContainerPixels(new MMLatLon(x.getAttribute('south'), x.getAttribute('east'))); break;}x.style.top=d.y+'px'; x.style.left=d.x+'px'; x.style.width=e.x-d.x+'px'; x.style.height=e.y-d.y+'px';}Mapstraction.prototype.addOverlay = function(url, autoCenterAndZoom) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addOverlay(url);} ); return;}var map = this.maps[this.api]; switch (this.api) { case 'yahoo':map.addOverlay(new YGeoRSS(url)); break; case 'openstreetmap':case 'google':var geoXML = new GGeoXml(url); map.addOverlay(geoXML, function() { if(autoCenterAndZoom) { geoXML.gotoDefaultViewport(map);}}); break; case 'microsoft':var veLayerSpec = new VELayerSpecification(); veLayerSpec.Type = VELayerType.GeoRSS; veLayerSpec.ID = 1; veLayerSpec.LayerSource = url; veLayerSpec.Method = 'get'; map.AddLayer(veLayerSpec); break; case 'multimap':break; case 'freeearth':if (this.freeEarthLoaded) { var ferss = new FE.GeoRSS(url); map.addOverlay(ferss);} else { myself = this; this.freeEarthOnLoad.push( function() { myself.addOverlay(url);} );}break; default:if(this.debug)alert(this.api + ' not supported by Mapstraction.addGeoRSSOverlay');}}Mapstraction.prototype.addTileLayer = function(tile_url, opacity, copyright_text, min_zoom, max_zoom) { if(!tile_url)return; if (! this.tileLayers) { this.tileLayers = [];}if(!opacity)opacity = 0.6; if(!copyright_text)copyright_text = "Mapstraction"; if(!min_zoom)min_zoom = 1; if(!max_zoom)max_zoom = 18; console.log(this.api); switch (this.api) { case 'google':case 'openstreetmap':var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)), 0, "copyleft"); var copyrightCollection = new GCopyrightCollection(copyright_text); copyrightCollection.addCopyright(copyright); var tilelayers = new Array(); tilelayers[0] = new GTileLayer(copyrightCollection, min_zoom, max_zoom); tilelayers[0].isPng = function() { return true;}; tilelayers[0].getOpacity = function() { return opacity;}tilelayers[0].getTileUrl = function (a, b) { url = tile_url; url = url.replace(/\{Z\}/,b); url = url.replace(/\{X\}/,a.x); url = url.replace(/\{Y\}/,a.y); return url}; tileLayerOverlay = new GTileLayerOverlay(tilelayers[0]); this.tileLayers.push( [tile_url, tileLayerOverlay, true] ); this.maps[this.api].addOverlay(tileLayerOverlay); break;}return tileLayerOverlay;}Mapstraction.prototype.toggleTileLayer = function(tile_url) { switch (this.api) { case 'google':case 'openstreetmap':for (var f=0; f<this.tileLayers.length; f++) { if(this.tileLayers[f][0] == tile_url) { if(this.tileLayers[f][2]) { this.maps[this.api].removeOverlay(this.tileLayers[f][1]); this.tileLayers[f][2] = false;} else { this.maps[this.api].addOverlay(this.tileLayers[f][1]); this.tileLayers[f][2] = true;}}}break;}}Mapstraction.prototype.addFilter = function(field, operator, value) { if (! this.filters) { this.filters = [];}this.filters.push( [field, operator, value] );}Mapstraction.prototype.removeFilter = function(field, operator, value) { if (! this.filters) { return;}var del; for (var f=0; f<this.filters.length; f++) { if (this.filters[f][0] == field &&(! operator || (this.filters[f][1] == operator && this.filters[f][2] == value))) { this.filters.splice(f,1); f--;}}}Mapstraction.prototype.toggleFilter = function(field, operator, value) { if (! this.filters) { this.filters = [];}var found = false; for (var f=0; f<this.filters.length; f++) { if (this.filters[f][0] == field && this.filters[f][1] == operator && this.filters[f][2] == value) { this.filters.splice(f,1); f--; found = true;}}if (! found) { this.addFilter(field, operator, value);}}Mapstraction.prototype.removeAllFilters = function() { this.filters = [];}Mapstraction.prototype.doFilter = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.doFilter();} ); return;}var map = this.maps[this.api]; if (this.filters) { switch (this.api) { case 'multimap':var mmfilters = []; for (var f=0; f<this.filters.length; f++) { mmfilters.push( new MMSearchFilter( this.filters[f][0], this.filters[f][1], this.filters[f][2] ));}map.setMarkerFilters( mmfilters ); map.redrawMap(); break; default:var vis; for (var m=0; m<this.markers.length; m++) { vis = true; for (var f=0; f<this.filters.length; f++) { if (! this.applyFilter(this.markers[m], this.filters[f])) { vis = false;}}if (vis) { this.markers[m].show();} else { this.markers[m].hide();}}break;}}}Mapstraction.prototype.applyFilter = function(o, f) { var vis = true; switch (f[1]) { case 'ge':if (o.getAttribute( f[0] ) < f[2]) { vis = false;}break; case 'le':if (o.getAttribute( f[0] ) > f[2]) { vis = false;}break; case 'eq':if (o.getAttribute( f[0] ) != f[2]) { vis = false;}break;}return vis;}Mapstraction.prototype.getAttributeExtremes = function(field) { var min; var max; for (var m=0; m<this.markers.length; m++) { if (! min || min > this.markers[m].getAttribute(field)) { min = this.markers[m].getAttribute(field);}if (! max || max < this.markers[m].getAttribute(field)) { max = this.markers[m].getAttribute(field);}}for (var p=0; m<this.polylines.length; m++) { if (! min || min > this.polylines[p].getAttribute(field)) { min = this.polylines[p].getAttribute(field);}if (! max || max < this.polylines[p].getAttribute(field)) { max = this.polylines[p].getAttribute(field);}}return [min, max];}Mapstraction.prototype.getMap = function() { return this.maps[this.api];}function LatLonPoint(lat,lon) { this.lat = lat; this.lon = lon; this.lng = lon;}LatLonPoint.prototype.toYahoo = function() { return new YGeoPoint(this.lat,this.lon);}LatLonPoint.prototype.toGoogle = function() { return new GLatLng(this.lat,this.lon);}LatLonPoint.prototype.toOpenLayers = function() { var ollon = this.lon * 20037508.34 / 180; var ollat = Math.log(Math.tan((90 + this.lat) * Math.PI / 360)) / (Math.PI / 180); ollat = ollat * 20037508.34 / 180; return new OpenLayers.LonLat(ollon, ollat);}LatLonPoint.prototype.fromOpenLayers = function() { var lon = (this.lon / 20037508.34) * 180; var lat = (this.lat / 20037508.34) * 180; lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2); this.lon = lon; this.lat = lat;}LatLonPoint.prototype.toMicrosoft = function() { return new VELatLong(this.lat,this.lon);}LatLonPoint.prototype.toMultiMap = function() { return new MMLatLon(this.lat, this.lon);}LatLonPoint.prototype.toMapQuest = function() { return new MQLatLng(this.lat, this.lon);}LatLonPoint.prototype.toFreeEarth = function() { return new FE.LatLng(this.lat,this.lon);}LatLonPoint.prototype.toMap24 = function() { return new Map24.Point (this.lon,this.lat);}LatLonPoint.prototype.toString = function() { return this.lat + ', ' + this.lon;}LatLonPoint.prototype.distance = function(otherPoint) { var d,dr; with (Math) { dr = 0.017453292519943295; d = cos(otherPoint.lon*dr - this.lon*dr) * cos(otherPoint.lat*dr - this.lat*dr); return acos(d)*6378.137;}return -1;}LatLonPoint.prototype.equals = function(otherPoint) { return this.lat == otherPoint.lat && this.lon == otherPoint.lon;}function BoundingBox(swlat, swlon, nelat, nelon) { this.sw = new LatLonPoint(swlat, swlon); this.ne = new LatLonPoint(nelat, nelon);}BoundingBox.prototype.getSouthWest = function() { return this.sw;}BoundingBox.prototype.getNorthEast = function() { return this.ne;}BoundingBox.prototype.isEmpty = function() { return this.ne == this.sw;}BoundingBox.prototype.contains = function(point){ return point.lat >= this.sw.lat && point.lat <= this.ne.lat && point.lon>= this.sw.lon && point.lon <= this.ne.lon;}BoundingBox.prototype.toSpan = function() { return new LatLonPoint( Math.abs(this.sw.lat - this.ne.lat), Math.abs(this.sw.lon - this.ne.lon) );}BoundingBox.prototype.extend = function(point) { if(this.sw.lat > point.lat)this.sw.lat = point.lat; if(this.sw.lon > point.lon)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -