maptalks / maptalks.js

A light and plugable JavaScript library for integrated 2D/3D maps.
https://maptalks.org
BSD 3-Clause "New" or "Revised" License
4.3k stars 503 forks source link

天地图影像按照EPSG:4326加载坐标偏移很大 #691

Closed yzpopulation closed 6 years ago

yzpopulation commented 6 years ago

天地图影像按照EPSG:4326加载坐标偏移很大?如何解决?

fuzhenn commented 6 years ago

应该是设置问题,请给个重现代码

yzpopulation commented 6 years ago
 var map = new maptalks.Map('map', {
      center: [119.4079706689,32.3955292132],
      zoom: 14,
      minZoom: 1,
      maxZoom: 18,
      spatialReference: {
        projection: 'EPSG:4326'
      },
      baseLayer: new maptalks.TileLayer('base', {
        tileSystem: [1, -1, -180, 180],
        renderer: 'canvas',
        urlTemplate: 'http://t{s}.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}',
        subdomains: ['1', '2', '3', '4', '5'],
        attribution: '&copy; <a target="_blank" href="http://www.tianditu.cn">Tianditu</a>'
      }),
      layers: [
        new maptalks.TileLayer('road', {
          urlTemplate: 'http://t{s}.tianditu.com/DataServer?T=ibo_w&x={x}&y={y}&l={z}',
          subdomains: ['1', '2', '3', '4', '5'],
          renderer: 'canvas',
          opacity: 1
        }),
        new maptalks.TileLayer('road2', {
          urlTemplate: 'http://t{s}.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}',
          subdomains: ['1', '2', '3', '4', '5'],
          renderer: 'canvas',
          opacity: 1
        })
      ]
    });
yzpopulation commented 6 years ago

已经改成[1,-1,-180,180]了 @fuzhenn

fuzhenn commented 6 years ago

刚看了一下,这个天地图的图源不是4326投影,而是3857墨卡托投影,所以有很大偏差。

有两个解决方案:

  1. 不要设置map的spatialReference,用默认的3857投影
  2. 单独设置TileLayer的spatialReference,参考示例