使用 PouchDB 作为离线栅格地图缓存 [英] Using PouchDB as an offline raster map cache

查看:8
本文介绍了使用 PouchDB 作为离线栅格地图缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在探索使用 PouchDB 作为栅格地图切片的离线缓存.具体来说,对于传单.我刚刚完成了一些初步测试,我想分享一下.

I have been exploring using PouchDB as an offline cache for raster map tiles. Specifically, for Leaflet. I have just finished some preliminary tests which I thought I would share.

推荐答案

我创建了一个JsFiddle"(实际上我最近更喜欢 CodePen),作为展示如何使用 PouchDB 缓存离线栅格地图切片的游乐场.

I have created a "JsFiddle" (actually I prefer CodePen these days), as a playground for showing how to use PouchDB to cache off-line raster map tiles.

它使用的算法如下:

  • 测试 XHR2、IndexedDB 和 Chrome(没有二进制 blob,但 Base64).并显示此状态信息
  • 从 GoogleDrive 获取 PNG 磁贴的 JSON 清单(我有 171 个 PNG瓷砖,每个尺寸为 256x256).清单列出了他们的名字和尺寸.
  • 将 JSON 清单存储在数据库中
  • MVVM 和 UI 控件来自 KendoUI(这次我没有使用他们的出色的网格控制,因为我想探索 CSS3 网格样式).
  • XHR2 来自:https://github.com/pmp/xhr2-lib/blob/master/test/index.html
  • 我正在使用 PouchDB 的夜间版本
  • 所有 PNG 文件都存储在 Google 云端硬盘(NASA Blue Marble.
  • 我使用 Safe FME 2013 Desktop 创建了磁贴金字塔.http://www.safe.com/fme/fme-technology/fme-桌面/概述

在按下下载磁贴"按钮之前检查清单是否已存储在数据库中,并且存在 171 个磁贴.如果您已经运行了测试,那么您的 PouchDB 将已经在 DB 中有磁贴,并且您将收到错误.在这种情况下,请按 Delete DB,然后重新加载页面.

Before Pressing the button "Download Tiles" Check to see that the manifest has been stored in the DB, and that 171 tiles are present. If you already ran the test then your PouchDB is going to already have tiles in the DB, and you will get errors. In that case, Press Delete DB, and then reload the page.

当您按下载瓷砖"时,会发生以下步骤:

When you press "Download Tiles" The following steps occur:

  • Manifest 是从数据库中获取的
  • XHR2 Fetch 循环从 GoogleDrive 抓取 PNG blob.
  • 当循环运行时,它开始将 Blob 保存到 PouchDB 中.
  • 注意:获取和保存是在重叠的线程上(想想协程),因为那些(获取和存储)操作正在运行在单独的线程上异步.
  • 当 Fetch 循环完成后,它会报告经过的时间.
  • 注意:这次不是纯粹的 Fetch 工作,因为 PouchDBputAttachments() 是并行运行的.
  • 当所有的 Tiles 被保存后,它会报告完整的统计信息,并且显示从 PouchDB 获取的磁贴.
  • Blob-Rate 每个 png tile 的总提取和存储时间

现在 Chrome 运行良好.火狐很慢.几个月前,我在做原生 IndexedDB API 时发现了这一点.所以我不认为这是一个 PouchDB 问题.可能更多是因为 FireFox 使用 SQLlite,这是一种非 SQL 数据库的关系方法.

Right now Chrome is running fine. Firefox is very slow. I found this out a few months when I did a native IndexedDB API. So I don't think this is a PouchDB issue. Probably more due to FireFox using SQLlite which is a relational approach to a no-SQL DB.

IE10 不工作.这很可悲,因为我之前对 IE10 的测试表明它有一个非常快速的 IndexedDB 解决方案:为离线网络应用存储图像数据(客户端存储数据库)

IE10 is not working. This is sad, since my prior tests with IE10 shows it has a fantastically fast IndexedDB solution: Storing Image Data for offline web application (client-side storage database)

这篇关于使用 PouchDB 作为离线栅格地图缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆