OpenLayer切换天地图底图

OpenLayer切换天地图底图

1.HTML代码

<el-button type="primary" @click="change_img">影像</el-button>
<el-button type="primary" @click="change_vec">街道</el-button>
<el-button type="primary" @click="change_ter">地形</el-button>

2.js代码

// 影像
change_img (){
    let img = new ol.layer.Tile({
        source: new ol.source.XYZ({
            url:  'http://t3.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=key'
        })
    });
    let cia = new ol.layer.Tiler({
        source: new XYZ({
            url:  "http://t0.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=key"
        })
    });
    this.map.addLayer(img);
    this.map.addLayer(cia);
},
// 街道
change_vec (){
    let img = new ol.layer.Tile({
        source: new ol.source.XYZ({
            url:  'http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=key'
        })
    });
    let cia = new ol.layer.Tiler({
        source: new XYZ({
            url:  "http://t4.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=key"
        })
    });
    this.map.addLayer(img);
    this.map.addLayer(cia);
},
// 地形
change_ter (){
    let img = new ol.layer.Tile({
        source: new ol.source.XYZ({
            url:  'http://t4.tianditu.com/DataServer?T=ter_w&x={x}&y={y}&l={z}&tk=key'
        })
    });
    let cia = new ol.layer.Tiler({
        source: new XYZ({
            url:  "http://t4.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=key"
        })
    });
    this.map.addLayer(img);
    this.map.addLayer(cia);
},
全部评论

相关推荐

点赞 评论 收藏
分享
02-16 22:13
门头沟学院 Java
Yki_:女生学成这样挺不错了,现在停止网课,立刻all in八股,从最频繁的开始背,遇到不会的知识点直接问AI,项目也别手敲,直接看技术文档,背别人总结好的面试官可能问的问题的答案,遇到不会的再去代码里找具体实现就可以了,3月份开始边背边投实习约面
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务