ol-mbtiles
Version:
MBTiles format reader for Openlayers
2 lines • 7.52 kB
JavaScript
;(self.webpackChunkol_mbtiles=self.webpackChunkol_mbtiles||[]).push([[832],{4509:(o,t,e)=>{e.d(t,{Cy:()=>x,bX:()=>C,v0:()=>E});var i,r=e(7139),n=e(6438),l=e(915),s=e(6758),a=e(1940),d=e(8112),c=e(4537),u=e(3075),p=e(8258),m=e(5286),h=e(4778),v=e(8512),g=e(1078);const w="undefined"!=typeof process&&void 0!==(null===(i=null===process||void 0===process?void 0:process.env)||void 0===i?void 0:i.OL_MBTILES_DEBUG)&&process.env.OL_MBTILES_DEBUG?console.debug.bind(console):()=>{},y={jpg:{type:"raster",mime:"image/jpeg"},png:{type:"raster",mime:"image/png"},webp:{type:"raster",mime:"image/webp"},pbf:{type:"vector"},mvt:{type:"vector"}};function f(o){var t,e,i;return{workers:null!==(t=null==o?void 0:o.sqlWorkers)&&void 0!==t?t:4,httpOptions:{backendType:null==o?void 0:o.backendType,maxPageSize:null!==(e=null==o?void 0:o.maxSqlPageSize)&&void 0!==e?e:4096,cacheSize:null!==(i=null==o?void 0:o.sqlCacheSize)&&void 0!==i?i:4096}}}function x(o){const t=(0,r.j8)(f(o));return t.then((t=>t.open(o.url).then((()=>t)))).then((o=>o.exec("SELECT name,value FROM metadata"))).then((o=>{if(o&&o.length){const t=o.reduce(((o,t)=>(o[t.row[0]]=t.row[1],o)),{});return w("Loaded metadata",t),t}throw new Error("Could not load metadata")})).then((e=>{var i,r,a,d,c,u,p,m,h;const v=Object.assign({},o),g=null===(r=null===(i=e.format)||void 0===i?void 0:i.toLowerCase)||void 0===r?void 0:r.call(i);y[g]||console.warn("Unknown tile format",g),v.projection=null!==(a=o.projection)&&void 0!==a?a:"EPSG:3857",v.attributions=null!==(d=e.attribution)&&void 0!==d?d:e.description,v.maxZoom=null!==(c=o.maxZoom)&&void 0!==c?c:+e.maxzoom,v.minZoom=null!==(u=o.minZoom)&&void 0!==u?u:+e.minzoom;const w=null===(m=null===(p=(0,n.Jt)(v.projection))||void 0===p?void 0:p.getExtent)||void 0===m?void 0:m.call(p),f=e.bounds,x=f?(0,n.DI)(f.split(",").map((o=>+o)),"EPSG:4326",v.projection):w;if("raster"===y[g].type){if(void 0===v.maxZoom||void 0===v.minZoom||void 0===w)throw new Error("Cannot determine tilegrid, need minZoom, maxZoom");const o=[(0,l.RG)(w)/256];for(let t=1;t<=v.maxZoom;t++)o.push(o[o.length-1]/2);const t=null!==(h=y[g].mime)&&void 0!==h?h:g;v.mime=t,v.tileGrid=new s.A({origin:[w[0],w[2]],extent:x,minZoom:v.minZoom,resolutions:o})}else v.extent=w;return v.pool=t,v.url=o.url,v})).catch((o=>t.then((o=>o.close())).then((()=>Promise.reject(o)))))}class b extends p.Ay{constructor(o){var t,e,i;super(),o=o||{},this.dataProjection=new m.A({code:"",units:"tile-pixels"}),this.featureClass_=o.featureClass?o.featureClass:h.Ay,this.geometryName_=null!==(t=o.geometryName)&&void 0!==t?t:"Geometry",this.layers_=null!==(e=o.layers)&&void 0!==e?e:null,this.idProperty_=o.idProperty,this.extent=null!==(i=o.extent)&&void 0!==i?i:4096,this.supportedMediaTypes=["application/vnd-mbtiles"]}readFeature(o,t){const e=o.properties;let i;this.idProperty_?(i=e[this.idProperty_],delete e[this.idProperty_]):i=o.id;const r=o.loadGeometry(),n=[],l=[],s=b.MBTypes[r.length>1?"multi":"mono"][o.type];if("Unknown"===s)return null;for(let o=0;o<r.length;o++)if(0!=r[o].length){for(let t=0;t<r[o].length;t++)n.push(r[o][t].x,r[o][t].y);l.push(n.length)}const a=new this.featureClass_(s,n,l,2,e,i);return(null==t?void 0:t.dataProjection)&&"transform"in a&&a.transform(null==t?void 0:t.dataProjection),a}readFeatures(o,t){const e=this.layers_,i=[],r=new c.VectorTile(new d.A(u.Ay.ungzip(o)));t=this.adaptOptions(t);const l=(0,n.Jt)(null==t?void 0:t.dataProjection),s=null==t?void 0:t.extent;if(!l||!t||!s)throw new Error("Cannot determine the projection/extent");l.setWorldExtent(s),l.setExtent([0,0,this.extent,this.extent]),t.dataProjection=l;for(const o of Object.keys(r.layers)){if(e&&!e.includes(o))continue;const n=r.layers[o];for(let e=0;e<n.length;e++){const r=n.feature(e),l=this.readFeature(r,t);l.getProperties().layer=o,i.push(l)}}return i}readProjection(){return this.dataProjection}}b.MBTypes={mono:["Unknown","Point","LineString","Polygon"],multi:["Unknown","MultiPoint","MultiLineString","Polygon"]};class C extends a.A{constructor(o){var t;if(void 0===o.url&&void 0===o.pool)throw new Error("Must specify url");super(Object.assign(Object.assign({},o),{url:void 0,format:new b({layers:o.layers}),tileUrlFunction:t=>`${o.url}#${t[0]}:${t[1]}:${t[2]}`})),this.setTileLoadFunction(this.tileLoader.bind(this)),this.pool=null!==(t=o.pool)&&void 0!==t?t:(0,r.j8)(f(o)).then((t=>t.open(o.url).then((()=>t))))}tileLoader(o,t){const e=o;w("loading tile",[e.tileCoord[0],e.tileCoord[1],e.tileCoord[2]]),e.setLoader(((o,t,i)=>{this.pool.then((o=>o.exec("SELECT tile_data FROM tiles WHERE zoom_level = $zoom AND tile_column = $col AND tile_row = $row",{$zoom:e.tileCoord[0],$col:e.tileCoord[1],$row:(1<<e.tileCoord[0])-1-e.tileCoord[2]}))).then((t=>{if(t&&t[0]&&t[0].row[0]){const r=e.getFormat().readFeatures(t[0].row[0],{extent:o,featureProjection:i});return e.setFeatures(r),void e.onLoad(r,i)}throw new Error(`No data for ${e.tileCoord}`)})).catch((o=>{w(o),e.onError()}))}))}disposeInternal(){return this.pool.then((o=>o.close()))}}class E extends v.A{constructor(o){var t;if(void 0===o.url&&void 0===o.pool)throw new Error("Must specify url");super(Object.assign(Object.assign({},o),{url:void 0,tileUrlFunction:t=>`${o.url}#${t[0]}:${t[1]}:${t[2]}`})),this.setTileLoadFunction(this.tileLoader.bind(this)),this.pool=null!==(t=o.pool)&&void 0!==t?t:(0,r.j8)(f(o)).then((t=>t.open(o.url).then((()=>t)))),this.mime=o.mime}tileLoader(o,t){w("loading tile",[o.tileCoord[0],o.tileCoord[1],o.tileCoord[2]]);const e=o.getImage();this.pool.then((t=>t.exec("SELECT tile_data FROM tiles WHERE zoom_level = $zoom AND tile_column = $col AND tile_row = $row",{$zoom:o.tileCoord[0],$col:o.tileCoord[1],$row:(1<<o.tileCoord[0])-1-o.tileCoord[2]}))).then((t=>{if(!(t&&t[0]&&t[0].row[0]instanceof Uint8Array))throw new Error(`No data for ${o.tileCoord}`);{const o=new Blob([t[0].row[0]],{type:this.mime}),i=URL.createObjectURL(o);e.src=i}})).catch((t=>{w(t),o.setState(g.A.ERROR)}))}disposeInternal(){return this.pool.then((o=>o.close()))}}},4396:(o,t,e)=>{e.d(t,{A:()=>s});var i=e(4863),r=e(8512);class n extends r.A{constructor(o){const t=void 0!==(o=o||{}).projection?o.projection:"EPSG:3857",e=void 0!==o.tileGrid?o.tileGrid:(0,i.EN)({extent:(0,i.kZ)(t),maxResolution:o.maxResolution,maxZoom:o.maxZoom,minZoom:o.minZoom,tileSize:o.tileSize});super({attributions:o.attributions,cacheSize:o.cacheSize,crossOrigin:o.crossOrigin,interpolate:o.interpolate,projection:t,reprojectionErrorThreshold:o.reprojectionErrorThreshold,tileGrid:e,tileLoadFunction:o.tileLoadFunction,tilePixelRatio:o.tilePixelRatio,tileUrlFunction:o.tileUrlFunction,url:o.url,urls:o.urls,wrapX:void 0===o.wrapX||o.wrapX,transition:o.transition,attributionsCollapsible:o.attributionsCollapsible,zDirection:o.zDirection}),this.gutter_=void 0!==o.gutter?o.gutter:0}getGutter(){return this.gutter_}}const l=n,s=class extends l{constructor(o){let t;t=void 0!==(o=o||{}).attributions?o.attributions:['© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors.'];const e=void 0!==o.crossOrigin?o.crossOrigin:"anonymous",i=void 0!==o.url?o.url:"https://tile.openstreetmap.org/{z}/{x}/{y}.png";super({attributions:t,attributionsCollapsible:!1,cacheSize:o.cacheSize,crossOrigin:e,interpolate:o.interpolate,maxZoom:void 0!==o.maxZoom?o.maxZoom:19,reprojectionErrorThreshold:o.reprojectionErrorThreshold,tileLoadFunction:o.tileLoadFunction,transition:o.transition,url:i,wrapX:o.wrapX,zDirection:o.zDirection})}}}}]);
//# sourceMappingURL=832.bundle.js.map