UNPKG

flatgeobuf

Version:

A performant binary encoding for geographic data

2 lines 1.39 kB
import{all as e}from"ol/loadingstrategy.js";import{transformExtent as t}from"ol/proj.js";import{deserialize as r,deserializeFiltered as i,deserializeStream as o,serialize as a}from"./generic/featurecollection.js";import{getFromFeatureFn as n}from"./ol/feature.js";export function serialize(e){return a(e)}export function deserialize(e,t,a,l=!1,s={},f=!1,c="EPSG:4326",d="EPSG:4326"){let u=n(f,c,d);if(e instanceof Uint8Array)return r(e,u,t,a);if(e instanceof ReadableStream)return o(e,u,a);if("string"==typeof e&&t)return i(e,t,u,a,l,s);throw Error("Invalid input type or missing rect for URL input")}function l(e,r,i){let[o,a,n,l]=r&&i&&r!==i?t(e,r,i):e;return{minX:o,minY:a,maxX:n,maxY:l}}export function createLoader(t,r,i="EPSG:4326",o=e,a=!1,n={},s=!1){return async(f,c,d,u,p)=>{try{let c;a&&t.clear();let p=d.getCode(),m=[];if(o===e){let e=await fetch(r,{headers:n});c=deserialize(e.body,void 0,void 0,!1,n,s,i,p)}else{let e=l(f,p,i);c=deserialize(r,e,void 0,!1,n,s,i,p)}for await(let e of c)m.push(e),t.addFeature(e);u?.(m)}catch(e){p?.()}}}export const tileUrlFunction=e=>JSON.stringify(e);export function createTileLoadFunction(e,t,r="EPSG:4326",i={},o=!1){let a=e.getProjection(),n=a?.getCode()??"EPSG:3857";return e=>{let a=async a=>{let s=deserialize(t,l(a,n,r),void 0,!1,i,o,r,n),f=[];for await(let e of s)f.push(e);e.setFeatures(f)};e.setLoader(a)}} //# sourceMappingURL=ol.js.map