Comparing version 0.0.3 to 0.0.4
@@ -1,1 +0,13 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var _point = require('./point'); | ||
var point = _interopRequireWildcard(_point); | ||
exports.point = point; |
import * as point from './point' | ||
export fun | ||
export { | ||
point | ||
} |
import ngeohash from 'ngeohash' | ||
export function clusterByGeohash(points, geohashLevel, reducer) { | ||
const result = [] | ||
const geohashes = {} | ||
for (let i = 0, l = points.geometries.length; i < l; i++) { | ||
const point = points.geometries[i] | ||
const geohash = ngeohash.encode(point.lat, point.lng, geohashLevel) | ||
if (geohashes[geohash]) { | ||
geohashes[geohash] = reducer(geohashes[geohash], point) | ||
} else { | ||
geohashes[geohash] = reducer(null, point) | ||
export default { | ||
clusterByGeohash(points, geohashLevel, reducer) { | ||
const result = [] | ||
const geohashes = {} | ||
for (let i = 0, l = points.geometries.length; i < l; i++) { | ||
const point = points.geometries[i] | ||
const geohash = ngeohash.encode(point.lat, point.lng, geohashLevel) | ||
if (geohashes[geohash]) { | ||
geohashes[geohash] = reducer(geohashes[geohash], point) | ||
} else { | ||
geohashes[geohash] = reducer(null, point) | ||
} | ||
} | ||
} | ||
for (let geohash in geohashes) { | ||
const {latitude, longitude} = ngeohash.decode(geohash) | ||
result.push({ | ||
...geohashes[geohash], | ||
lat: latitude, | ||
lng: longitude, | ||
}) | ||
} | ||
return result | ||
} | ||
for (let geohash in geohashes) { | ||
const {latitude, longitude} = ngeohash.decode(geohash) | ||
result.push({ | ||
...geohashes[geohash], | ||
lat: latitude, | ||
lng: longitude, | ||
}) | ||
} | ||
return result | ||
}, | ||
} | ||
{ | ||
"name": "geo-util", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "geo-util for eye", | ||
@@ -14,4 +14,3 @@ "author": "xiagan <huikang.whk@alibaba-inc.com>", | ||
"test": "make test", | ||
"prepublish": "make test-cov && make release", | ||
"postinstall": "make release" | ||
"prepublish": "make test-cov && make release" | ||
}, | ||
@@ -31,6 +30,3 @@ "dependencies": { | ||
"node >=0.10.7" | ||
], | ||
"scripts": { | ||
"test": "make test" | ||
} | ||
] | ||
} |
import e from 'expect.js' | ||
import ngeohash from 'ngeohash' | ||
import {clusterByGeohash} from '../lib/point' | ||
import point from '../lib/point' | ||
@@ -38,3 +38,3 @@ describe('point', () => { | ||
const geometries = points.geometries | ||
const results = clusterByGeohash(points, 6, (prev, curr) => { | ||
const results = point.clusterByGeohash(points, 6, (prev, curr) => { | ||
if (prev == null) return {...curr, properties: {...curr.properties, num: 1}} | ||
@@ -41,0 +41,0 @@ const result = {...prev} |
Sorry, the diff of this file is not supported yet
7014
11
123