ol.control.LayerSwitcher = function(opt_options) { var this_ = this; var options = opt_options || {}; var layers = []; if(window.parent.googleStatus == "true"){ layers.push({"mapType":"googleMap","jiupian":"1","showText":"Google Map","layer":null}); layers.push({"mapType":"googleMapSate","jiupian":"0","showText":"Google Sate Map","layer":null}); } if(window.parent.baiduStatus == "true"){ layers.push({"mapType":"baiduMap","jiupian":"2","showText":"Baidu Map","layer":null}); layers.push({"mapType":"baiduMapSate","jiupian":"2","showText":"Baidu Sate Map","layer":null}); } if(window.parent.gaodeStatus == "true"){ layers.push({"mapType":"gaodeMap","jiupian":"1","showText":"Gaode Map","layer":null}); layers.push({"mapType":"gaodeMapSate","jiupian":"1","showText":"Gaode Sate Map","layer":null}); } layers.push({"mapType":"openStreetMap","jiupian":"0","showText":"OpenStreetMap","layer":null}); for(var i=0;iOpenStreetMap' ] }) // source = new ol.source.OSM({ // attributions : [ // new ol.Attribution({html: 'Map data ©2017'}), // new ol.Attribution({html : 'OpenStreetMap'}) // ] // }) } else if (mapType === 'gaodeMap' || mapType === 'gaodeMapSate') {// 高德地图层 var url; if(mapType == 'gaodeMap'){ url = "http://webrd0{1-4}.is.autonavi.com/appmaptile?size=1&scale=1&style=7&x={x}&y={y}&z={z}"; }else if(mapType == 'gaodeMapSate'){ url = "http://webst0{1-4}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}"; } source = new ol.source.XYZ({ url : url, attributions : [ 'Map data © 高德地图' ] }) } else if (mapType === 'googleMap' || mapType === 'googleMapSate') {// google地图层 //var url = 'http://mt{0-4}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}?hl='+locale; var url = ''; if(mapType == 'googleMap'){ url = 'http://mt{0-3}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'; }else if(mapType == 'googleMapSate'){ url = 'http://mt{0-3}.google.com/vt/lyrs=y&x={x}&y={y}&z={z}'; } source = new ol.source.XYZ({ url: url, attributions : [ 'Map data © Google Map' ] }) } else if (mapType === 'baiduMap' || mapType === 'baiduMapSate') {// 百度地图层 var projection = ol.proj.get("EPSG:3857"); var resolutions = []; for (var i = 0; i < 19; i++) { resolutions[i] = Math.pow(2, 18 - i); } var tilegrid = new ol.tilegrid.TileGrid({ // origin : [ 0,0 ], origin : [ -110,16600 ], resolutions : resolutions }); var source = new ol.source.TileImage({ projection : projection, tileGrid : tilegrid, crossOrigin: 'anonymous', //跨域 tileUrlFunction : function(tileCoord, pixelRatio, proj){ if (!tileCoord) { return ""; } var z = tileCoord[0]; var x = tileCoord[1]; var y = tileCoord[2]; if (x < 0) { x = "M" + (-x); } if (y < 0) { y = "M" + (-y); } if(mapType == 'baiduMap'){ return "http://online3.map.bdimg.com/onlinelabel/?qt=tile&x="+x+"&y="+y+"&z="+z+"&styles=pl&udt=20170301&scaler=1&p=1"; }else if(mapType == 'baiduMapSate'){ return "http://shangetu3.map.bdimg.com/it/u=x="+x+";y="+y+";z="+z+";v=009;type=sate&fm=46&udt=20170301"; } }, attributions : [ 'Map data © Baidu Map' ] }); } var layer = new ol.layer.Tile({ visible: false,//不可见 source : source }); return layer; };