UNPKG

flatgeobuf

Version:

A performant binary encoding for geographic data

2 lines 1.15 kB
import{createServer as e}from"node:http";import t from"sirv";import{afterAll as o,beforeAll as a,describe as r,expect as s,it as i}from"vitest";import{fromFeature as n}from"./geojson/feature";import{HttpReader as m}from"./http-reader";r("http reader",()=>{let r,l;a(()=>{let o=t(".",{dev:!0,single:!1});return r=e((e,t)=>o(e,t)),new Promise(e=>{r.listen(0,()=>{l=r.address().port,e()})})}),o(()=>new Promise(e=>r?.close(()=>e()))),i("fetches a subset of data based on bounding box",async()=>{let e=`http://localhost:${l}/test/data/UScounties.fgb`,t=await m.open(e,!1),o=[];for await(let e of t.selectBbox({minX:-106.88,minY:36.75,maxX:-101.11,maxY:41.24}))o.push(n(e.id,e.feature,t.header));s(o.length).toBe(86),s(o.slice(0,4).map(e=>`${e.properties?.NAME}, ${e.properties?.STATE}`)).toEqual(["Texas, OK","Cimarron, OK","Taos, NM","Colfax, NM"])}),i("can fetch the final feature",async()=>{let e=`http://localhost:${l}/test/data/countries.fgb`,t=await m.open(e,!0);s(179).toBe(t.header.featuresCount);let o=0;for await(let e of t.selectBbox({minX:-61.2,minY:-51.85,maxX:-60,maxY:-51.25}))o++;s(o).toBe(2)})}); //# sourceMappingURL=http-reader.spec.js.map