JSPM

@ryry886/coord-transform

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q51914F
  • License MIT

坐标转换

Package Exports

  • @ryry886/coord-transform
  • @ryry886/coord-transform/dist/coord-transform.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ryry886/coord-transform) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

coord-transform

wgs84,高德,百度之间的坐标转换,以及用proj4自定义转换,不改变数据结构

api

transform(geojsonOrArray,transOption)

geojsonOrArray: 数组或者标准geojson格式
//wgs84,高德,百度之间的坐标转换
transOption: {
                from:"WGS84", // WGS84, BD09,GCJ02
                to:"BD09",  // WGS84, BD09,GCJ02
                proj4:false
            }
//proj4参数转换
transOption: {
                from:"+proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=37500000 +y_0=0 +ellps=GRS80 +units=m +no_defs",
                to:"+proj=longlat +ellps=GRS80 +no_defs",
                proj4:true
            }
//使用proj4自带坐标系,详细看proj4
transform([113.9612,31.315],{
    from:"WGS84",
    to:"EPSG:3857",
    proj4:true
})
//使用epsg 库的坐标系
npm i epsg
import epsg from "epsg"
transform([37488855.08,3514760.39],{
    from:epsg["EPSG:4525"],
    to:"+proj=longlat +ellps=GRS80 +no_defs",
    proj4:true,
});

使用

NPM

npm i @ryry886/coord-transform

import  transform  from "@ryry886/coord-transform"
//传入数组
transform([114.331754,30.478323],{from:"WGS84",to:"GCJ02"})

//传入嵌套数组
transform([[114.331754,30.478323],[114.331754,30.478323]],{from:"BD09",to:"WGS84"})

//geojson
transform({"type": "Point", "coordinates": [114.331754,30.478323]},{from:"BD09",to:"GCJ02"})

//使用proj4
let option={
    from:"+proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=37500000 +y_0=0 +ellps=GRS80 +units=m   +no_defs",
    to:"+proj=longlat +ellps=GRS80 +no_defs",
    proj4:true,
}
let geojson = {
        "type": "FeatureCollection",
        "features": [
            { "type": "Feature",
                "geometry": {"type": "Point", "coordinates": [37488855.08,3514760.39]},
                "properties": {
                    "name": "Location A",
                    "category": "Store"
                }
            },
            { "type": "Feature",
                "geometry": {"type": "Point", "coordinates": [37488855.08,3514760.39]},
                "properties": {
                    "name": "Location B",
                    "category": "House"
                }
            },
            { "type": "Feature",
                "geometry": {"type": "Point", "coordinates": [37488855.08,3514760.39]},
                "properties": {
                    "name": "Location C",
                    "category": "Office"
                }
            }
        ]
    }
transform(geojson,option);