欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

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

注意最好下載最新的版本(當(dāng)前是1.91),以確??梢粤鲿呈褂霉俜紸PI。博主有過(guò)因?yàn)槭褂门f版本Cesium導(dǎo)致無(wú)法調(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)文章

  • 關(guān)于vue中媒體查詢不起效的原因總結(jié)

    關(guān)于vue中媒體查詢不起效的原因總結(jié)

    這篇文章主要介紹了關(guān)于vue中媒體查詢不起效的原因總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • vue中注冊(cè)組件的兩種方式詳解(全局注冊(cè)&& 局部注冊(cè))

    vue中注冊(cè)組件的兩種方式詳解(全局注冊(cè)&& 局部注冊(cè))

    vue 是一個(gè)完全支持組件化開發(fā)的框架, 組件之間可以進(jìn)行相互的引用,這篇文章主要介紹了vue中注冊(cè)組件的兩種方式詳解(全局注冊(cè)&& 局部注冊(cè)),需要的朋友可以參考下
    2023-06-06
  • vue3中setup聲明變量的方式匯總

    vue3中setup聲明變量的方式匯總

    本文給大家介紹Vue3中setup()函數(shù)中聲明變量的幾種方法,希望本文能夠幫助你更好地理解Vue3的開發(fā)方式,感興趣的朋友跟隨小編一起看看吧
    2023-11-11
  • 詳解vue實(shí)現(xiàn)坐標(biāo)拾取器功能示例

    詳解vue實(shí)現(xiàn)坐標(biāo)拾取器功能示例

    這篇文章主要介紹了詳解vue實(shí)現(xiàn)坐標(biāo)拾取器功能示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • 在vue中對(duì)數(shù)組值變化的監(jiān)聽(tīng)與重新響應(yīng)渲染操作

    在vue中對(duì)數(shù)組值變化的監(jiān)聽(tīng)與重新響應(yīng)渲染操作

    這篇文章主要介紹了在vue中對(duì)數(shù)組值變化的監(jiān)聽(tīng)與重新響應(yīng)渲染操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • Vuex unknown action type報(bào)錯(cuò)問(wèn)題及解決

    Vuex unknown action type報(bào)錯(cuò)問(wèn)題及解決

    這篇文章主要介紹了Vuex unknown action type報(bào)錯(cuò)問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • vue3中setup語(yǔ)法糖下父子組件間傳遞數(shù)據(jù)的方式

    vue3中setup語(yǔ)法糖下父子組件間傳遞數(shù)據(jù)的方式

    Vue3中父組件指的是包含一個(gè)或多個(gè)子組件的組件,它們通過(guò)props和事件等方式來(lái)傳遞數(shù)據(jù)和通信,這篇文章主要介紹了vue3中setup語(yǔ)法糖下父子組件間傳遞數(shù)據(jù)的方式,需要的朋友可以參考下
    2023-06-06
  • vite+vue3+element-plus搭建項(xiàng)目的踩坑記錄

    vite+vue3+element-plus搭建項(xiàng)目的踩坑記錄

    這篇文章主要介紹了vite+vue3+element-plus搭建項(xiàng)目的踩坑記錄,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue開發(fā)項(xiàng)目中如何使用Font Awesome 5

    Vue開發(fā)項(xiàng)目中如何使用Font Awesome 5

    Font Awesome是一套流行的圖標(biāo)字體庫(kù),我們?cè)趯?shí)際開發(fā)的過(guò)程中會(huì)經(jīng)常遇到需要使用圖標(biāo)的場(chǎng)景,對(duì)于一些常用的圖標(biāo),我們可以直接在Font Awesome中找到并且使用,這篇文章主要給大家介紹了關(guān)于Vue開發(fā)項(xiàng)目中如何使用Font Awesome5的相關(guān)資料,需要的朋友可以參考下
    2021-11-11
  • 如何使用vue slot創(chuàng)建一個(gè)模態(tài)框的實(shí)例代碼

    如何使用vue slot創(chuàng)建一個(gè)模態(tài)框的實(shí)例代碼

    這篇文章主要介紹了如何使用vue slot創(chuàng)建一個(gè)模態(tài)框,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-05-05

最新評(píng)論