Skip to content

Commit

Permalink
Merge pull request #15 from geolonia/add-get-data
Browse files Browse the repository at this point in the history
件数指定して取得、featureの件数を取得できるように修正
  • Loading branch information
sugama-satsuki authored Aug 2, 2024
2 parents d68ae58 + 6ac157c commit f0649bf
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,19 @@ export class GeoJsonlookfor {
/* *****************
* geojsonを返す
* *****************/
getGeoJSON() {
getGeoJSON(number?: number) {
if (number !== undefined) {
this.geojson.features = this.geojson.features.slice(0, number);
}
return this.geojson
}


/* *******************
* featureの件数を取得する
* *******************/
getFeatureCount() {
return this.geojson.features.length;
}

}
60 changes: 60 additions & 0 deletions test/testByGetDataType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { assert } from 'chai';
import * as fs from 'fs';
import { GeoJsonlookfor } from '../src/index';


// testデータのディレクトリ名を取得する
const geojson = JSON.parse(fs.readFileSync(`${__dirname}/test.geojson`, 'utf8'));

/* *******************
* 取得するデータ別のテスト
* *******************/
describe('Test by return value', () => {

// 件数を取得する
it('Get the number of cases', () => {
const gl = new GeoJsonlookfor(geojson);
const res = gl.match('スイーツ').getFeatureCount();
assert.deepEqual(4, res);
});

// 指定した件数分featureを取得する
it('Get the number of cases', () => {
const gl = new GeoJsonlookfor(geojson);
const res = gl.match('スイーツ').getGeoJSON(2);
assert.deepEqual({
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "スイーツショップ",
"address": "埼玉県桶川市川田谷",
"category": "スイーツ"
},
"geometry": {
"coordinates": [
139.517720985072,
35.99865685174926
],
"type": "Point"
}
},{
"type": "Feature",
"properties": {
"name": "菓子店",
"address": "埼玉県川越市中老袋",
"category": "スイーツ"
},
"geometry": {
"coordinates": [
139.5371783066526,
35.941979468748585
],
"type": "Point"
}
}
]
}, res);
});
});

0 comments on commit f0649bf

Please sign in to comment.