UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

64 lines (63 loc) 2.19 kB
import { isNumber } from 'lodash'; import { gcj2wgs } from '../../../utils/geoTransform'; import { CoordinateSystem } from '../../../constants'; function transformCoordinateSystem(lng, lat, coordinateSystem) { if (coordinateSystem === CoordinateSystem.GCJ02) { var wgsLngLat = gcj2wgs(lat, lng); return [wgsLngLat.lng, wgsLngLat.lat]; } return [lng, lat]; } export function getGeojson(dataset, longitudeField, latitudeField, coordinateSystem) { var rows = dataset.rows, fields = dataset.fields; var features = rows .map(function (row) { var properties = fields.reduce(function (pre, cur, index) { pre[cur.key] = row[index][0]; return pre; }, {}); var longitude = properties[longitudeField]; var latitude = properties[latitudeField]; if (!isNumber(longitude) || !isNumber(latitude)) { return null; } return { type: 'Feature', properties: properties, geometry: { type: 'Point', coordinates: transformCoordinateSystem(longitude, latitude, coordinateSystem) } }; }) .filter(function (item) { return !!item; }); return { type: 'FeatureCollection', features: features }; } export function getGeojsonLine(dataset, longitudeField, latitudeField, coordinateSystem) { var rows = dataset.rows, fields = dataset.fields; var coordinates = rows .map(function (row) { var properties = fields.reduce(function (pre, cur, index) { pre[cur.key] = row[index][0]; return pre; }, {}); var longitude = properties[longitudeField]; var latitude = properties[latitudeField]; if (!isNumber(longitude) || !isNumber(latitude)) { return null; } return transformCoordinateSystem(longitude, latitude, coordinateSystem); }) .filter(function (item) { return !!item; }); return { type: 'Feature', properties: {}, geometry: { type: 'LineString', coordinates: coordinates } }; }