Coder Social home page Coder Social logo

magicbyang / cesiumofflinecache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wangshan010/cesiumofflinecache

0.0 0.0 0.0 8.18 MB

这是一个 Cesium 插件,它使用 indexDB 离线缓存技术管理 影像图层、地形、3DTiles模型 等资源数据。

cesiumofflinecache's Introduction

CesiumOfflineCache

这是一个 Cesium 插件,它使用 indexDB 离线缓存技术管理 影像图层、地形、3DTiles模型 等资源数据。

作者 QQ:2394837320

个人网站:http://101.43.223.126:3000/

一、运行原理

在Cesium 通过 Cesium.Resource 发送 资源请求(图层、地形、模型)前,判断本地是否有缓存存在,如果存在则优先使用本地缓存,本地缓存能极大加快场景的二次加载速度。

二、起步

2.1、引入插件

  • script 方式引入
<script src="./CesiumOfflineCache.min.js"></script>
  • ES6 方式引入
<script type="module">
    import './CesiumOfflineCache.min.js';
</script>

2.2、使用方式

  • index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./Cesium/^1.98/Cesium.js"></script>
    <link rel="stylesheet" href="./Cesium/^1.98/Widgets/widgets.css">
</head>
<body>
<div id="MapContainer" style="width: 100%;height: 100%"></div>
<script type="module" src="./js/main.js"></script>
</body>
</html>
  • main.js
import './CesiumOfflineCache.min.js';

CesiumOfflineCache.ruleList.add('*');
let viewer = new Cesium.Viewer('MapContainer', {
    imageryProvider: new Cesium.UrlTemplateImageryProvider({
        url: 'https://c.tile.thunderforest.com/transport/{z}/{x}/{y}.png',
        tilingScheme: new Cesium.WebMercatorTilingScheme(),
        maximumLevel: 19
    }),
    timeline: false,
    animation: false
});

viewer.scene.camera.setView({
    destination: Cesium.Cartesian3.fromDegrees(-122.3472, 47.598, 370),
    orientation: {
        heading: Cesium.Math.toRadians(10),
        pitch: Cesium.Math.toRadians(-10)
    }
});

setTimeout(() => {
    let tileSet = Cesium.createOsmBuildings();
    viewer.scene.primitives.add(tileSet);
}, 3000);

三、API 文档

命名空间:window.CesiumOfflineCache.*

const CesiumOfflineCache = {
    // 缓存规则
    ruleList: new Set(),
    // 判断该资源项是否符合缓存规则
    judgeUrl(url) {},
    async getItem(k) {},
    async setItem(k, v) {},
    async keys() {},
    async clear() {},
    // 计算缓存占用的存储空间大小
    async getUseSize() {}
};
  • 全局缓存
CesiumOfflineCache.ruleList.add('*');
  • 对 OSM 电子地图缓存
CesiumOfflineCache.ruleList.add('https://c.tile.thunderforest.com/');
  • 对指定地址的 3DTile 缓存
CesiumOfflineCache.ruleList.add('http://xxx.xx.xx.xx:3000//3DTiles/');

cesiumofflinecache's People

Contributors

wangshan010 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.