openlayers3 加載百度地圖:javascript
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], resolutions: resolutions }); var baidu_source = new ol.source.TileImage({ projection: projection, tileGrid: tilegrid, 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); } return "http://online3.map.bdimg.com/onlinelabel/?qt=tile&x="+x+"&y="+y+"&z="+z+"&styles=pl&udt=20151021&scaler=1&p=1"; } }); var baidu_layer = new ol.layer.Tile({ source: baidu_source }); var map = new ol.Map({ target: 'map', layers: [baidu_layer], view: new ol.View({ center: [12959773,4853101], zoom: 12 }) });
openlayers3 加載天地圖:java
路網 var tian_di_tu_road_layer = new ol.layer.Tile({ title: "天地圖路網", source: new ol.source.XYZ({ url: "http://t4.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}" }) }); map.addLayer(tian_di_tu_road_layer); 註記 var tian_di_tu_annotation = new ol.layer.Tile({ title: "天地圖文字標註", source: new ol.source.XYZ({ url: 'http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}' }) }); map.addLayer(tian_di_tu_annotation); 衛星影像 var tian_di_tu_satellite_layer = new ol.layer.Tile({ title: "天地圖衛星影像", source: new ol.source.XYZ({ url: 'http://t3.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}' }) }); map.addLayer(tian_di_tu_satellite_layer);