1.2.2 • Published 5 years ago

@ne_fe/gis v1.2.2

Weekly downloads
64
License
MIT
Repository
-
Last release
5 years ago

ne-gis

npm.io npm.io npm.io npm.io npm.io npm.io npm.io

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 }]
});
1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago