China's Projection for OpenLayers
Projection Supported
Projection | code | Description |
---|---|---|
GCJ02 | 'GCJ02','GCJ:02','ZH:MARS' | 国测局02坐标系,火星坐标系 |
BD09 | 'BD09','BD09','baidu' | 百度坐标系 |
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:
npm install ol-proj-ch
Import:
by import olpjch
, the olpjch
is defined as a container for all supported projections in this module.
by import {xxx} from 'ol-proj-ch'
, import the pertinent projection you want.
/* GCJ02 */const GCJ02 = olpjchGCJ02const code = GCJ02CODE//... /* BD09 */const BD09 = olpjchBD09const code = BD09CODE //or import GCJ02, BD09 or othersconst code1 = GCJ02CODE //the code of GCJ02const code2 = BD09CODE //the code of BD09
Usage:
💡 here use GCJ02 to make exmaples.
- transform a coordinate from gcj02 to wgs84(EPSG:4326)
const coords = 1170320;const newCoords = ;
likewise, use transform([coords, "EPSG:4326", GCJ02.CODE)
from wgs84 to gcj02
- transform a coordinate from gcj02 to EPSG:3857
const coords = 1170320;const newCoords = ;
likewise, use transform([coords, "EPSG:3857", GCJ02.CODE)
from EPSG:3827 to gcj02
- eg: create feature from geojson data of GCJ02
; //geojson data pretend coordinates are in GCJ02const data = "type": "Feature" "geometry": "type": "Point" "coordinates": 1256 101 "properties": "name": "Dinagat Islands" ; const format = ;let feature = format;//... then add feature to layer and then add to map
- eg: visulaize vector data from wkt with gcj02 data projection
; //WKT dataconst data = `POINT (125.6 10.1)`; const format = ;let feature = format;//... then add feature to layer and then add to map