1.0.2 • Published 1 year ago

tbgis v1.0.2

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

Gis项目开发常用 utils 方法

1. utils 常用工具类

import { utils } from 'tbgis';

1.1 获取 antdv 表格的默认配置

参数:

pageSize 每页显示条数,默认为 10

config 需要覆盖的配置,默认为 {}

const options = utils.getDefaultPagination(pageSize, config);

返回值:

const data = {
 total: 0,
 current: 1,
 pageSize,
 hideOnSinglePage: true,
 showTotal: (total, range) => {
  return range[0] + '-' + range[1] + ' 共' + total + '条';
 },
};

1.2 获取表格的可视化高度

参数为 Object类型,可选的属性有:

  • id 表格dom的 id
  • extraHeight 额外的高度,默认为 88
const tableHeight = utils.getTableScrollHeight({id: "tableId"})

使用方法:

<a-table
  id="tableId"
  :scroll="{ y: tableHeight }"
></a-table>

1.3 获取上传文件的真实文件名

参数: url路径地址。 栗子: /gfgx-public/data/63acf5aead945f0e23cba2de/thumbnail_63acf5aead945f0e23cba2de.png

const fileName = utils.getFileName(`/gfgx-public/data/63acf5aead945f0e23cba2de/thumbnail_63acf5aead945f0e23cba2de.png`)

返回值:thumbnail_63acf5aead945f0e23cba2de.png

1.4 直链文件下载

参数: 文件的 url 地址

utils.downloadFile(url)

2. mapUtils 地图工具类,主要针对于 leaflet

import { utils } from 'tbgis';

2.1 创建地图

参数:

id 地图容器的 id

config 地图的配置,可选,默认参数如下:

{
  center: { lat: 33.51361277047545, lng: 107.89657445624471 },
  zoom: 7,
  zoomControl: false,
  minZoom: 3,
  maxZoom: 17,
  zoomOffset: 1,
  crs: L.CRS.EPSG4326,
  attributionControl: false,
  ...config,
 }

使用方法:

this.map = mapUtils.createMap('map2d', {
  zoom: 10
});

3. 行政区工具类

import { districtUtils } from 'tbgis';

3.1 根据code获取行政区树节点数组

参数:行政区的code

const result = districtUtils.getNodeArray("110107")

返回值:

['110000', '110107']

3.2 根据code获取行政区树节点label

参数:行政区的code

const result = districtUtils.getLabel("110101")

返回值:东城区

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago