天天看点

ol xyz 加载天地图_Openlayers3 加载百度地图,天地图

openlayers3 加载百度地图:

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 加载天地图:

路网

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);