/** * Created with JetBrains WebStorm. * User: liuyayun * Date: 13-5-27 * Time: 上午11:19 * To change this template use File | Settings | File Templates. */ //判定一下是否存在了SuperMap.Web,如果没有则初始化一个 if(SuperMap.Web == undefined ) { SuperMap.Web = new Object(); } //判定一下是否存在了SuperMap.Web.iConnector,如果没有则初始化一个 if(SuperMap.Web.iConnector == undefined ) { SuperMap.Web.iConnector = new Object(); } /** * Class: * Google适配器类 * @constructor */ SuperMap.Web.iConnector.Google = function(){ } /** * APIMethod: * 创建google的扩展图层,这里的图层中切片的来源为iserver服务器(只能是3857的地图) * @param url {String} 地图服务的url地址,如:“http://localhost:8090/iserver/services/map-china400/rest/maps/China” * @param options 可选的参数 * transparent - {Boolean} 设置切片是否透明,默认为true * cacheEnabled - {Boolean} 设置是否使用缓存,默认为false * layersID - {String} 设置临时图层的id,一般用于专题图的叠加使用 * @returns {Object} 返回google地图的扩展图层对象 */ SuperMap.Web.iConnector.Google.getLayer = function(url,options){ if(url == undefined) { return; } var layer = new Object(); layer.tileSize = new google.maps.Size(256, 256); var layerUrl = url + "/image.png?redirect=false&width=256&height=256"; //切片是否透明 var transparent = true; if(options && options.transparent !=undefined) { transparent = options.transparent; } layerUrl += "&transparent=" + transparent; //是否是否使用缓存 var cacheEnabled = false; if(options && options.cacheEnabled !=undefined) { cacheEnabled = options.cacheEnabled; } layerUrl += "&cacheEnabled=" + cacheEnabled; //如果有layersID,则是在使用专题图 if(options && options.layersID !=undefined) { layerUrl += "&layersID=" +options.layersID; } var resLen = 17; var resStart = 0; layer.resolutions3857 = []; var dpi = 95.99999999999984; layer.scales3857 = []; for(var i=resStart;i<=resLen;i++){ var res3857 = 156543.0339/Math.pow(2,i); layer.resolutions3857.push(res3857); var scale3857 = 0.0254/dpi/res3857; layer.scales3857.push(scale3857); } layer.url = layerUrl; layer.getTile = function(coord, zoom, ownerDocument){ var po = Math.pow(2,zoom); x = coord.x; y = coord.y; x-=po/2; y=po/2-y-1; //使用bounds出图(也可以使用center) var left = x*256*this.resolutions3857[zoom]; var bottom = y*256*this.resolutions3857[zoom]; var right = (x + 1)*256*this.resolutions3857[zoom]; var top = (y + 1)*256*this.resolutions3857[zoom]; //将bounds组合到url里面 tileUrl =this.url + "&viewBounds=" +"{\"leftBottom\" : {\"x\":" + left +",\"y\":" + bottom +"},\"rightTop\" : {\"x\":" + right +",\"y\":" +top + "}}"; tileUrl +="&scale=" +this.scales3857[zoom]; tileUrl += "&prjCoordSys={\"epsgCode\":3857}"; var div = ownerDocument.createElement('div'); div.innerHTML = ""; div.style.width = this.tileSize.width + 'px'; div.style.height = this.tileSize.height + 'px'; div.style.borderStyle = 'solid'; div.style.borderWidth = '0px'; return div; } return layer; } /** * APIMethod: * 将其他坐标系下的点转换为google地图的点 * @param array 点数组,支持四种形式的点: * 1、var points = [ * {x:116.1,y:38.9}, * {x:114.1,y:34.1} * ]; * 2、var points = [ * new SuperMap.Geometry.Point(116.1,38.9), * new SuperMap.Geometry.Point(116.1,38.9) * ]; * 3、var points = [ * new SuperMap.LonLat(116.1,38.9), * new SuperMap.LonLat(116.1,38.4) * ]; * 4、var points = [ * new google.maps.LatLng(39.9,116.38), * new google.maps.LatLng(39.9,116.35) * ]; * @param projection {SuperMap.Projection} 待转换点的投影系(数组里面的所有点投影系都必须是统一的),默认为4326. * @returns {Array} 返回google.maps.LatLng对象的数组 */ SuperMap.Web.iConnector.Google.transferPoint = function(array,projection){ if((typeof array) == "object" && array != null && array.constructor == Array) { var pro = projection || new SuperMap.Projection("EPSG:4326"); var points = [] //分几种不同的情况 for(var i = 0;i