hermanho / react-leaflet-pouchdb-tilelayer

MIT License
4 stars 4 forks source link

Store map data as Base64 Strings #1

Open xahitbayri opened 4 years ago

xahitbayri commented 4 years ago

Hi,

I am trying to use "pouchdb-replication-stream" and "pouchdb-load". Purpose is to download maps at PC1(internet available). Dump it to file. Go to PC2(internet not available). Load this file in this and use it.

In current approach, values are stored as URL's at Pouchdb. Is it possible to store them as base64 and load back ?

xahitbayri commented 4 years ago

In addition, native javascript implemention "L.TileLayer.PouchDBCached.js", It converts to base64, as below lines:

var binStr = atob(dataURL), len = binStr.length, arr = new Uint8Array(len);

            for (var i = 0; i < len; i++) {
                arr[i] = binStr.charCodeAt(i);
            }

            callback(new Blob([arr], { type: type || "image/png" }));

is it possible to add an option for this ? Or How can I do this by myself :) ?

hermanho commented 4 years ago

Map tiles are stored as blob in PounchDB which follow their guideline. https://pouchdb.com/guides/attachments.html

xahitbayri commented 4 years ago

{"docs":[{"timestamp":1593065367609,"_attachments":{"tile":{"data":{},"digest":"md5-MVRT7Pw0eI+AnOcuZLK64g==","content_type":"image/png","revpos":1}},"_id":"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/11/781/1211","_rev":"1-baca466ae141d89cc8a44361de82d5b8","_revisions":{"start":1,"ids":["baca466ae141d89cc8a44361de82d5b8"]}},{"timestamp":1593065367614,"_attachments":{"tile":{"data":{},"digest":"md5-FrK2jLUhMbhY7FWLvW3KeQ==","content_type":"image/png","revpos":1}},"_id":"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/11/781/1212","_rev":"1-3b0ea30e640660229f15d33361827cc1","_revisions":{"start":1,"ids":["3b0ea30e640660229f15d33361827cc1"]}},{"timestamp":1593065367613,"_attachments":{"tile":{"data":{},"digest":"md5-FkNxUiIPYCUihVTpAFB//Q==","content_type":"image/png","revpos":1}},"_id":"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/11/782/1210","_rev":"1-44454a91a1c60371cbde3b958ed361ca","_revisions":{"start":1,"ids":["44454a91a1c60371cbde3b958ed361ca"]}},{"timestamp":1593065367612,"_attachments":{"tile":{"data":{},"digest":"md5-x0IS2y4eLndDzMh7hONqBA==","content_type":"image/png","revpos":1}},"_id":"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/11/782/1211","_rev":"1-9f39b51382aea9a0c2bc93def39352cf","_revisions":{"start":1,"ids":["9f39b51382aea9a0c2bc93def39352cf"]}},{"timestamp":1593065367615,"_attachments":{"tile":{"data":{},"digest":"md5-gFlfp5vV1E1edgRH+IAMag==","content_type":"image/png","revpos":1}},"_id":"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/11/782/1212","_rev":"1-684af0c4ea96a2d1d22c5d48a46bf240","_revisions":{"start":1,"ids":["684af0c4ea96a2d1d22c5d48a46bf240"]}},{"timestamp":1593065367056,"_attachments":{"tile":{"data":{},"digest":"md5-HAyo5ZEb8Tqq18DOoK7azA==","content_type":"image/png","revpos":1}},"_id":"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/15/12504/19374","_rev":"1-41ddb4d91aa8168f0832decde2368845","_revisions":{"start":1,"ids":["41ddb4d91aa8168f0832decde2368845"]}},{"timestamp":1593065367180,"_attachments":{"tile":{"data":....

Thank you very much for your response. I try to dump database pouchdb. This is the content of dump. I try to load this to a new database by "load" function. Although I got "Result : {"ok":true}" it is not loaded to this database. What could be the problem ?

hermanho commented 4 years ago

It looks like a known bug. https://github.com/pouchdb-community/pouchdb-replication-stream/issues/75