最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

cesium開發(fā)之如何在vue項(xiàng)目中使用cesium,使用離線地圖資源

 更新時(shí)間:2023年04月29日 11:25:06   作者:下一次就是永遠(yuǎn)  
這篇文章主要介紹了cesium開發(fā)之如何在vue項(xiàng)目中使用cesium,使用離線地圖資源問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

vue使用cesium,使用離線地圖資源

第一步:創(chuàng)建vue項(xiàng)目并下載最新版本的Cesium

注意最好下載最新的版本(當(dāng)前是1.91),以確??梢粤鲿呈褂霉俜紸PI。博主有過因?yàn)槭褂门f版本Cesium導(dǎo)致無法調(diào)用API的情況。

npm cesium

第二步:在node_modules文件夾中補(bǔ)充離線資源

在項(xiàng)目根目錄的node_modules文件夾中,找到cesium文件夾

根據(jù)以下2個(gè)路徑:node_modules\cesium\Build\Cesium\Assets\Textures和node_modules\cesium\Source\Assets\Textures找到用于存放離線地圖的文件夾。

在這個(gè)文件夾下,補(bǔ)充離線地圖數(shù)據(jù)(這個(gè)資源需要大家自己在網(wǎng)絡(luò)上找)。

離線地圖資源

第三步:使用cesium生成地球

1.在vue文件中創(chuàng)建html結(jié)構(gòu)

<div id="container"></div>

2.利用cesium構(gòu)造函數(shù)初始化地球

別忘了在data中定義空對(duì)象viewer

this.viewer = new Cesium.Viewer("container", {
      geocoder: false,
      timeline: false,
      fullscreenButton: false,
      animation: false,
      shouldAnimate: true,
    });

第四步:使用離線地圖資源替換網(wǎng)絡(luò)地圖資源

在構(gòu)造函數(shù)中補(bǔ)充以下2個(gè)屬性:

this.viewer = new Cesium.Viewer("container", {
      imageryProvider: new Cesium.TileMapServiceImageryProvider({
        url: Cesium.buildModuleUrl("Assets/Textures/MyEarthII"),
      }),
      baseLayerPicker: false
    });

最后附上cesium官網(wǎng)對(duì)imageryProvider用法的解釋:

The imagery provider to use. This value is only valid if baseLayerPicker is set to false.

用于提供地圖圖像。僅當(dāng)baseLayerPicker為false時(shí)有效。

cesium添加百度地圖

百度地圖的瓦塊切片規(guī)則與大多數(shù)地圖不同,其中心點(diǎn)位于地理坐標(biāo)的0,0點(diǎn),多數(shù)地圖的切片是以地圖左上角為瓦塊切片的起點(diǎn)。

Cesium中默認(rèn)的切片地圖(UrlTemplateImageryProvider)包括經(jīng)緯度模式和投影(墨卡托)模式都是以左上角切片為基準(zhǔn)。所以當(dāng)我們加載百度地圖瓦塊地圖時(shí),需要自定義地圖影像地圖類。

BaiduImageryProvider = function(options) {
    this._errorEvent = new Cesium.Event();
    this._tileWidth = 256;
    this._tileHeight = 256;
    this._maximumLevel = 18;
    this._minimumLevel = 1;
    let southwestInMeters = new Cesium.Cartesian2(-33554054, -33746824);
    let northeastInMeters = new Cesium.Cartesian2(33554054, 33746824);
    this._tilingScheme = new Cesium.WebMercatorTilingScheme({
        rectangleSouthwestInMeters: southwestInMeters,
        rectangleNortheastInMeters: northeastInMeters
    });
    this._rectangle = this._tilingScheme.rectangle;
    this._resource = Cesium.Resource.createIfNeeded(options.url);
    this._tileDiscardPolicy = undefined;
    this._credit = undefined;
    this._readyPromise = undefined;
};
 
Object.defineProperties(Cesium.gm.BaiduImageryProvider.prototype, {
    url: {
        get: function () {
            return this._resource.url;
        }
    },
    proxy: {
        get: function () {
            return this._resource.proxy;
        }
    },
    tileWidth: {
        get: function () {
            if (!this.ready) {
                throw new Cesium.DeveloperError('tileWidth must not be called before the imagery provider is ready.');
            }
            return this._tileWidth;
        }
    },
 
    tileHeight: {
        get: function () {
            if (!this.ready) {
                throw new Cesium.DeveloperError('tileHeight must not be called before the imagery provider is ready.');
            }
            return this._tileHeight;
        }
    },
 
    maximumLevel: {
        get: function () {
            if (!this.ready) {
                throw new Cesium.DeveloperError('maximumLevel must not be called before the imagery provider is ready.');
            }
            return this._maximumLevel;
        }
    },
 
    minimumLevel: {
        get: function () {
            if (!this.ready) {
                throw new Cesium.DeveloperError('minimumLevel must not be called before the imagery provider is ready.');
            }
            return this._minimumLevel;
        }
    },
 
    tilingScheme: {
        get: function () {
            if (!this.ready) {
                throw new Cesium.DeveloperError('tilingScheme must not be called before the imagery provider is ready.');
            }
            return this._tilingScheme;
        }
    },
 
    tileDiscardPolicy: {
        get: function () {
            if (!this.ready) {
                throw new Cesium.DeveloperError('tileDiscardPolicy must not be called before the imagery provider is ready.');
            }
            return this._tileDiscardPolicy;
        }
    },
 
    rectangle: {
        get: function () {
            if (!this.ready) {
                throw new Cesium.DeveloperError('rectangle must not be called before the imagery provider is ready.');
            }
            return this._rectangle;
        }
    },
 
    errorEvent: {
        get: function () {
            return this._errorEvent;
        }
    },
    ready: {
        get: function () {
            return this._resource;
        }
    },
    readyPromise: {
        get: function () {
            return this._readyPromise;
        }
    },
    credit: {
        get: function () {
            if (!this.ready) {
                throw new Cesium.DeveloperError('credit must not be called before the imagery provider is ready.');
            }
            return this._credit;
        }
    },
});
 
BaiduImageryProvider.prototype.requestImage = function (x, y, level, request) {
    let xTileCount = this._tilingScheme.getNumberOfXTilesAtLevel(level);
    let yTileCount = this._tilingScheme.getNumberOfYTilesAtLevel(level);
    let url = this.url
        .replace("{x}", x - xTileCount / 2)
        .replace("{y}", yTileCount / 2 - y - 1)
        .replace("{z}", level)
        .replace("{s}", Math.floor(10 * Math.random()));
    console.log("zxy:" + level + ", " + x + ", " + y + "; " + url);
    return Cesium.ImageryProvider.loadImage(this, url);
};

調(diào)用時(shí),傳入url參數(shù)即可,url服務(wù)可以使在線服務(wù),也可以是代理服務(wù)(按百度地圖切片索引規(guī)則)。例如:

let baiduImageryProvider = new BaiduImageryProvider({
? ? url: "http://online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1"
});
?
let viewer = new Cesium.Viewer('cesiumContainer', {
? ? imageryProvider: baiduImageryProvider,
? ? ...
}

這時(shí)就可以在Cesium中正常加載百度地圖了。

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 談?wù)剬?duì)Vue?Router的理解

    談?wù)剬?duì)Vue?Router的理解

    vue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,適合用于構(gòu)建單頁面應(yīng)用,這篇文章主要介紹了對(duì)Vue?Router的理解,需要的朋友可以參考下
    2022-11-11
  • vue項(xiàng)目,代碼提交至碼云,iconfont的用法說明

    vue項(xiàng)目,代碼提交至碼云,iconfont的用法說明

    這篇文章主要介紹了vue項(xiàng)目,代碼提交至碼云,iconfont的用法說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • Vue 富文本編輯器tinymce的安裝配置使用教程

    Vue 富文本編輯器tinymce的安裝配置使用教程

    TinyMCE是一個(gè)輕量級(jí)的基于瀏覽器的所見即所得編輯器,由JavaScript寫成,TinyMCE是一個(gè)根據(jù)LGPL license發(fā)布的自由軟件,你可以把它用于商業(yè)應(yīng)用,這篇文章主要介紹了Vue 富文本編輯器tinymce的安裝教程,需要的朋友可以參考下
    2023-09-09
  • 如何一步步基于element-ui封裝查詢組件

    如何一步步基于element-ui封裝查詢組件

    這篇文章主要給大家介紹了關(guān)于如何一步步基于element-ui封裝查詢組件的相關(guān)資料,本文通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue.js具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-10-10
  • 使用use注冊(cè)Vue全局組件和全局指令的方法

    使用use注冊(cè)Vue全局組件和全局指令的方法

    下面小編就為大家分享一篇使用use注冊(cè)Vue全局組件和全局指令的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • 詳解vue-cli 快速搭建單頁應(yīng)用之遇到的問題及解決辦法

    詳解vue-cli 快速搭建單頁應(yīng)用之遇到的問題及解決辦法

    這篇文章主要介紹了詳解vue-cli 快速搭建單頁應(yīng)用之遇到的問題及解決辦法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03
  • 基于Vue中使用節(jié)流Lodash throttle詳解

    基于Vue中使用節(jié)流Lodash throttle詳解

    今天小編就為大家分享一篇基于Vue中使用節(jié)流Lodash throttle詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • elementui導(dǎo)出數(shù)據(jù)為xlsx、excel表格

    elementui導(dǎo)出數(shù)據(jù)為xlsx、excel表格

    本文主要介紹了elementui導(dǎo)出數(shù)據(jù)為xlsx、excel表格,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • 關(guān)于el-table-column的formatter的使用及說明

    關(guān)于el-table-column的formatter的使用及說明

    這篇文章主要介紹了關(guān)于el-table-column的formatter的使用及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • Vue項(xiàng)目中首頁長(zhǎng)時(shí)間白屏的原因以及解決過程

    Vue項(xiàng)目中首頁長(zhǎng)時(shí)間白屏的原因以及解決過程

    這篇文章主要介紹了Vue項(xiàng)目中首頁長(zhǎng)時(shí)間白屏的原因以及解決過程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01

最新評(píng)論

九寨沟县| 德惠市| 来宾市| 襄垣县| 南开区| 疏勒县| 白玉县| 香港| 泰兴市| 扬中市| 磐石市| 铜鼓县| 汾阳市| 古浪县| 额济纳旗| 辛集市| 汤原县| 金堂县| 宜兴市| 马鞍山市| 府谷县| 西乌珠穆沁旗| 建德市| 九龙城区| 灵璧县| 泰和县| 信阳市| 曲周县| 康保县| 永年县| 盐池县| 寻甸| 永福县| 新乐市| 彩票| 江陵县| 株洲市| 泾川县| 盐池县| 织金县| 东方市|