openlayers3投影转换——proj4js


proj4js

  • proj4js是一个转换点坐标从一个坐标系到另一个坐标系的JavaScript库,包括数据转换。这个库是由proj4和​gctcp C库转换而来的JavaScript版本。在浏览器端进行转换的可能允许将存储在不同的投影存储的地理数据可以在基于浏览器的Web地图应用应用中结合到一起。proj4js是metacrs项目组的一部分,使用和 PROJ.4相同的MIT许可。

proj4js 和 openlayers

  • 要在openlayers3中应用proj4js,需要在html中引用proj4js,然后在引用所需要的projection的js定义,如 http://epsg.io/21781-1753.js
    然后在openlayers中就会支持这种EPSG:21781的坐标转换。

  • 在ol3中使用(官方示例

proj4.defs('ESRI:53009', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +a=6371000 ' +
    '+b=6371000 +units=m +no_defs');

// Configure the Sphere Mollweide projection object with an extent,
// and a world extent. These are required for the Graticule.
var sphereMollweideProjection = new ol.proj.Projection({
  code: 'ESRI:53009',
  extent: [-9009954.605703328, -9009954.605703328,
    9009954.605703328, 9009954.605703328],
  worldExtent: [-179, -89.99, 179, 89.99]
});

var map = new ol.Map({
  keyboardEventTarget: document,
  layers: [
    new ol.layer.Vector({
      source: new ol.source.Vector({
        url: 'data/geojson/countries-110m.geojson',
        format: new ol.format.GeoJSON()
      })
    })
  ],
  renderer: 'canvas',
  target: 'map',
  view: new ol.View({
    center: [0, 0],
    projection: sphereMollweideProjection,
    resolutions: [65536, 32768, 16384, 8192, 4096, 2048],
    zoom: 0
  })
});

参考

转载自:https://blog.csdn.net/xk_zhang/article/details/53543606

You may also like...