1 Star 0 Fork 0

dungang / ol-proj-ch

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-2-Clause

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:

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.

import olpjch from 'ol-proj-ch'

/* GCJ02 */
const GCJ02 = olpjch.GCJ02
const code = GCJ02.CODE
//...

/* BD09 */
const BD09 = olpjch.BD09
const code = BD09.CODE

//or import GCJ02, BD09 or others
import {GCJ02} from 'ol-proj-ch'
import {BD09} from 'ol-proj-ch'
const code1 = GCJ02.CODE    //the code of GCJ02
const code2 = BD09.CODE     //the code of BD09

Usage:

💡 here use GCJ02 to make exmaples.

  • transform a coordinate from gcj02 to wgs84(EPSG:4326)
import {GCJ02} from 'ol-proj-ch'
import {transform} from 'ol/proj'
const coords = [117.0,32.0];
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
import {GCJ02} from 'ol-proj-ch'
import {transform} from 'ol/proj'
const coords = [117.0,32.0];
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
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
  • eg: visulaize vector data from wkt with gcj02 data projection
import {GCJ02} from 'ol-proj-ch'
import WKT from "ol/format/WKT";

//WKT data
const data = `POINT (125.6 10.1)`;

const format = new WKT();
let feature = format.readFeature(data, {
   dataProjection: GCJ02.CODE,
   featureProjection: "EPSG:3857"
});
//... then add feature to layer and then add to map
BSD 2-Clause License Copyright (c) 2020, Ke Wang All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

This module defines the GCJ02 as a Projection of openlayers, likewise EPSG:4326 and EPSG:3857 展开 收起
JavaScript 等 2 种语言
BSD-2-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/dungang/ol-proj-ch.git
git@gitee.com:dungang/ol-proj-ch.git
dungang
ol-proj-ch
ol-proj-ch
master

搜索帮助