项目作者: wkgreat

项目描述 :
china's gcj02 for openlayers
高级语言: TypeScript
项目地址: git://github.com/wkgreat/ol-proj-ch.git
创建时间: 2020-07-26T03:12:22Z
项目社区:https://github.com/wkgreat/ol-proj-ch

开源协议:BSD 2-Clause "Simplified" License

下载


China’s Projection for OpenLayers

Author: wkgreat
TS
NPM version
CI

Projection Supported

Projection code Description
GCJ02 ‘GCJ02’,’GCJ:02’,’ZH:MARS’ 国测局02坐标系,火星坐标系
BD09 ‘BD09’,’BD09’,’baidu’ 百度坐标系

Document

https://wkgreat.github.io/ol-proj-ch/

Introduction

GCJ02 is a coordinate systems often used in China.
Strictly speaking, it is a confidential algorithm for encrypting geopoints.
After processing by GCJ02 algorithm,
the point defined in WGS84 will be deviated on web map visually.
This module defines the GCJ02 as a Projection of openlayers, likewise EPSG:4326 and EPSG:3857

💡From version 1.0.3 also support typescript.

Install:

```shell script
npm install ol-proj-ch

  1. # Import:
  2. by `import olpjch`, the `olpjch` is defined as a container for all supported projections in this module.
  3. by `import {xxx} from 'ol-proj-ch'`, import the pertinent projection you want.
  4. ```javascript
  5. import olpjch from 'ol-proj-ch'
  6. /* GCJ02 */
  7. const GCJ02 = olpjch.GCJ02
  8. const code = GCJ02.CODE
  9. //...
  10. /* BD09 */
  11. const BD09 = olpjch.BD09
  12. const code = BD09.CODE
  13. //or import GCJ02, BD09 or others
  14. import {GCJ02} from 'ol-proj-ch'
  15. import {BD09} from 'ol-proj-ch'
  16. const code1 = GCJ02.CODE //the code of GCJ02
  17. const code2 = BD09.CODE //the code of BD09

Usage:

💡 here use GCJ02 to make exmaples.

  • transform a coordinate from gcj02 to wgs84(EPSG:4326)
    1. import {GCJ02} from 'ol-proj-ch'
    2. import {transform} from 'ol/proj'
    3. const coords = [117.0,32.0];
    4. const newCoords = transform(coords, GCJ02.CODE, "EPSG:4326");
    likewise, use transform([coords, "EPSG:4326", GCJ02.CODE) from wgs84 to gcj02
  • transform a coordinate from gcj02 to EPSG:3857

    1. import {GCJ02} from 'ol-proj-ch'
    2. import {transform} from 'ol/proj'
    3. const coords = [117.0,32.0];
    4. const newCoords = transform(coords, GCJ02.CODE, "EPSG:3857");

    likewise, use transform([coords, "EPSG:3857", GCJ02.CODE) from EPSG:3827 to gcj02

  • eg: create feature from geojson data of GCJ02
    ```javascript
    import {GCJ02} from ‘ol-proj-ch’
    import {GeoJSON} from “ol/format”;

//geojson data pretend coordinates are in GCJ02
const data = {
“type”: “Feature”,
“geometry”: {
“type”: “Point”,
“coordinates”: [125.6, 10.1]
},
“properties”: {
“name”: “Dinagat Islands”
}
};

const format = new GeoJSON();
let feature = format.readFeature(data, {
dataProjection: GCJ02.CODE,
featureProjection: “EPSG:3857”
});
//… then add feature to layer and then add to map

  1. * eg: visulaize vector data from wkt with gcj02 data projection
  2. ```javascript
  3. import {GCJ02} from 'ol-proj-ch'
  4. import WKT from "ol/format/WKT";
  5. //WKT data
  6. const data = `POINT (125.6 10.1)`;
  7. const format = new WKT();
  8. let feature = format.readFeature(data, {
  9. dataProjection: GCJ02.CODE,
  10. featureProjection: "EPSG:3857"
  11. });
  12. //... then add feature to layer and then add to map