https://map.tianditu.gov.cn/
去天地图官网注册账号申请tk
最简单的用法 加载基础矢量图
new ol.Map({
target: "map",//绑定的dom
view: new ol.View({
center: [112.549248, 37.857014],//中心点
zoom: 5,//缩放等级
projection: "EPSG:4326",//坐标系
}),
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
tileGrid: new ol.tilegrid.TileGrid({
origin: ol.extent.getTopLeft(ol.proj.get("EPSG:4326")?.getExtent() || []),
tileSize: [256, 256],
resolutions: new Array(18).fill(0).map(
(item, index) =>
ol.extent.getWidth(ol.proj.get("EPSG:4326")?.getExtent() || []) /
256 /
Math.pow(2, index)
),
}),
crossOrigin: "anonymous",
wrapX: true,
tileUrlFunction:([z,x,y])=>`http://t4.tianditu.gov.cn/DataServer?T=请求的地图格式&x=${x}&y=${y}&l=${z}&tk=天地图的tk`,//请求地址 自己改改 请求地图格式可以在天地图里找当 用于加载不同的地图:vec_c矢量图
projection: "EPSG:4326",
}),
})//如果还需要加载其他 可以在数组内添加Tile 只更换地址即可
],
});