openlayers6地图离线开发demo-在线天地图wmts服务地图初始化

 

initTiandituWMTSMap() {
  registerProj('EPSG:4490')
  this.map = new Map({
    layers: [],
    target: 'olMap',
    view: new View({
      center: transform([118.182570, 24.487530], 'EPSG:4490', 'EPSG:3857'),
      zoom: this.zoom
    })
  })
  const projection = getProjection('EPSG:3857')
  const projectionExtent = projection.getExtent()
  const size = getWidth(projectionExtent) / 256
  const resolutions = new Array(18)
  const matrixIds = new Array(18)
  for (let z = 1; z < 19; ++z) {
    // generate resolutions and matrixIds arrays for this WMTS
    resolutions[z] = size / Math.pow(2, z)
    matrixIds[z] = z
  }
  const taindiLayer = new TileLayer({
    opacity: 0.7,
    source: new WMTS({
      url: 'http://t0.tianditu.gov.cn/vec_w/wmts?tk=10f2d5da71582b8d105e7535da8e6a1c',
      layer: 'vec', // 注意每个图层这里不同
      matrixSet: 'w',
      format: 'tiles',
      style: 'default',
      projection: projection,
      tileGrid: new WMTSTileGrid({
        origin: getTopLeft(projectionExtent),
        resolutions: resolutions,
        matrixIds: matrixIds
      }),
      wrapX: true
    })
  })
  this.map.addLayer(taindiLayer)
  /* const taindiLayerFont = new TileLayer({
      opacity: 0.7,
      source: new WMTS({
        url: 'http://t0.tianditu.gov.cn/cva_w/wmts?tk=10f2d5da71582b8d105e7535da8e6a1c',
        layer: 'cva', //注意每个图层这里不同
        matrixSet: 'w',
        format: 'tiles',
        style: 'default',
        projection: projection,
        tileGrid: new WMTSTileGrid({
          origin: getTopLeft(projectionExtent),
          resolutions: resolutions,
          matrixIds: matrixIds,
        }),
        wrapX: true,
      }),
    });
    this.map.addLayer(taindiLayerFont);*/
  const fontLayer = this.crtLayerXYZ()
  this.map.addLayer(fontLayer)
},
// 创建图层(xyz方式,推荐使用) 图层方式有多种,官方推荐xyz
crtLayerXYZ() {
  const source = new XYZ({
    url: 'http://t0.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=10f2d5da71582b8d105e7535da8e6a1c',
    crossOrigin: 'anonymous'
  })
  const layer = new TileLayer({
    source,
    opacity: 1
  })
  layer.id = 'cva_ccva_c'
  return layer
},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值