@ne_fe/gis
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

ne-gis

ne 前端地图组件 - 高性能经纬度转换库

简介

经纬度转换

安装&配置

$ npm i @ne_fe/gis -D
// webpack.config.js
const path = require('path');
const WasmModuleWebpackPlugin = require('wasm-module-webpack-plugin');

...
{
  test: /\.m?js$/,
  exclude: /(node_modules|bower_components)/,
  include: [ path.join(process.cwd(), './node_modules/@ne_fe/gis') ],
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env'],
      plugins: [ '@babel/plugin-syntax-dynamic-import', WasmModuleWebpackPlugin.BabelPlugin ]
    }
  }
}

...

plugins: [
  new WasmModuleWebpackPlugin.WebpackPlugin()
]

...

坐标转换-GPS转当前地图坐标

Note: 由于使用webssembly实现,所以 longitude、latitude 暂时只支持number类型

import neGis from '@ne_fe/gis';
const gps = [];
let lngX = 116.3;
let latY = 39.9;
gps.push({ longitude: lngX, latitude: latY });
for (let i = 1; i < 40; i++) {
    lngX = lngX + Math.random() * 0.0005;
    if (i % 2) {
        latY = latY + Math.random() * 0.0001;
    } else {
        latY = latY + Math.random() * 0.0006;
    }
    gps.push({ longitude: lngX, latitude: latY });
}
// 转腾讯地图 确保已经加载腾讯地图sdk 不仅会对数值做计算转换,还会转为腾讯地图经纬度对象
neGis.translateFromGPS(gps, 't', 1).then(res => {
  console.log(res);
});
// 转腾讯地图 只会对数值做计算转换 可以不用加载腾讯地图sdk 
neGis.translateFromGPS(gps, 't', 0).then(res => {
  console.log(res);
});
neGis.translateFromGPS(gps, 't').then(res => {
  console.log(res);
});
// 还可对每条转换后数据进行操作
// 第三个参数必须,不能省略,第四个参数为一个函数,两个参数分别为该条数据的值与下标,返回新数据
neGis.translateFromGPS(gps, 't', 0, (value, index) => {
  console.log(value, index);
  return value;
}).then(res => {
  console.log(res);
});

// 注意 1.1.0以上版本会保留原始数据,示例如下

const gpsTest = [
  {
    longitude: 116.3,
    latitude: 39.9,
    tkey: 111,
  }
];
neGis.translateFromGPS(gpsTest, 't', 1).then(res => {
  console.log(res);
  // [{ lng: 116.29787221, lat: 39.921133, longitude: 116.3, latitude: 39.9, tkey: 111 }]
});

坐标转换-当前地图坐标转GPS

Note: 由于使用webssembly实现,所以 lat、lng 暂时只支持number类型

import neGis from '@ne_fe/gis';
const gps = [];
let lngX = 116.3;
let latY = 39.9;
gps.push(new qq.maps.latlng(latY, lngX));
for (let i = 1; i < 40; i++) {
    lngX = lngX + Math.random() * 0.0005;
    if (i % 2) {
        latY = latY + Math.random() * 0.0001;
    } else {
        latY = latY + Math.random() * 0.0006;
    }
    gps.push(new qq.maps.latlng(latY, lngX));
}
// 转GPS使用的坐标系
neGis.translateToGPS(gps, 't').then(res => {
  console.log(res);
});

// 注意 1.1.0以上版本会保留原始数据,示例如下

const gpsTest = [
  {
    ...new qq.maps.latlng(39.921133, 116.29787221),
    tkey: 111,
  }
];
neGis.translateToGPS(gpsTest, 't').then(res => {
  console.log(res);
  // [{ lng: 116.29787221, lat: 39.921133, longitude: 116.3, latitude: 39.9, tkey: 111 }]
});

/@ne_fe/gis/

    Package Sidebar

    Install

    npm i @ne_fe/gis

    Weekly Downloads

    28

    Version

    1.2.2

    License

    MIT

    Unpacked Size

    86.9 kB

    Total Files

    7

    Last publish

    Collaborators

    • caando11
    • ne.fe
    • yong.liu
    • yuezm
    • zhouzhi