Cesium流動(dòng)線紋理

注:流動(dòng)效果使用的圖片是漸進(jìn)色


colors.png
colors1.png
Cesium流動(dòng)線效果.gif

1.擴(kuò)展類PolylineTrailMaterialProperty (Cesium? 1.67-1.68)

import Cesium from "cesium/Cesium";

export class PolylineTrailMaterialProperty {

? ? constructor(options) {

? ? ? ? options = Cesium.defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT);

? ? ? ? this._definitionChanged = new Cesium.Event();

? ? ? ? this._color = undefined;

? ? ? ? this._colorSubscription = undefined;

? ? ? ? this.color = options.color;

? ? ? ? this.duration = options.duration;

? ? ? ? this.trailImage = options.trailImage;

? ? ? ? this._time = performance.now();

? ? }

}

Cesium.defineProperties(PolylineTrailMaterialProperty.prototype, {

? ? isConstant: {

? ? ? ? get: function() {

? ? ? ? ? ? return false;

? ? ? ? }

? ? },

? ? definitionChanged: {

? ? ? ? get: function() {

? ? ? ? ? ? return this._definitionChanged;

? ? ? ? }

? ? },

? ? color: Cesium.createPropertyDescriptor('color')

});

PolylineTrailMaterialProperty.prototype.getType = function(time) {

? ? return 'PolylineTrail';

}

PolylineTrailMaterialProperty.prototype.getValue = function(time, result) {

? ? if (!Cesium.defined(result)) {

? ? ? ? result = {};

? ? }

? ? result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);

? ? //result.image = Cesium.Material.PolylineTrailImage;

? ? result.image = this.trailImage;

? ? result.time = ((performance.now() - this._time) % this.duration) / this.duration;

? ? return result;

}

PolylineTrailMaterialProperty.prototype.equals = function(other) {

? ? return this === other ||

? ? ? ? (other instanceof PolylineTrailMaterialProperty &&

? ? ? ? ? ? Cesium.Property.equals(this._color, other._color))

}

Cesium.Material.PolylineTrailType = 'PolylineTrail';

Cesium.Material.PolylineTrailImage = "images/colors.png";

Cesium.Material.PolylineTrailSource = "czm_material czm_getMaterial(czm_materialInput materialInput)\n\

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {\n\

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? czm_material material = czm_getDefaultMaterial(materialInput);\n\

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? vec2 st = materialInput.st;\n\

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n\

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? material.alpha = colorImage.a * color.a;\n\

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return material;\n\

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }";

Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineTrailType, {

? ? fabric: {

? ? ? ? type: Cesium.Material.PolylineTrailType,

? ? ? ? uniforms: {

? ? ? ? ? ? color: new Cesium.Color(1.0, 0.0, 0.0, 0.5),

? ? ? ? ? ? image: Cesium.Material.PolylineTrailImage,

? ? ? ? ? ? time: 0

? ? ? ? },

? ? ? ? source: Cesium.Material.PolylineTrailSource

? ? },

? ? translucent: function(material) {

? ? ? ? return true;

? ? }

});

Cesium.PolylineTrailMaterialProperty = PolylineTrailMaterialProperty;

2.使用

<template>

? <div class="fullSize" id="cesiumContainer"></div>

</template>

<script>

import "cesium/Widgets/widgets.css";

import Cesium from "cesium/Cesium";

import CesiumFactory from "@/js/cesium/CesiumFactory";

import PolylineTrailMaterialProperty from "@/js/cesium/overlay/PolylineTrailMaterialProperty";

export default {

? name: "CesiumDynamicLine1",

? data() {

? ? return {

? ? ? viewer: null

? ? };

? },

? mounted() {

? ? const factory = new CesiumFactory();

? ? this.viewer = factory.getViewer();

? ? this.create();

? },

? methods: {

? ? create() {

? ? ? //創(chuàng)建射線

? ? ? var data = {

? ? ? ? center: {

? ? ? ? ? id: 0,

? ? ? ? ? lon: 114.302312702,

? ? ? ? ? lat: 30.598026044,

? ? ? ? ? size: 20,

? ? ? ? ? color: Cesium.Color.PURPLE

? ? ? ? },

? ? ? ? points: [

? ? ? ? ? {

? ? ? ? ? ? id: 1,

? ? ? ? ? ? lon: 115.028495718,

? ? ? ? ? ? lat: 30.200814617,

? ? ? ? ? ? color: Cesium.Color.YELLOW,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 2,

? ? ? ? ? ? lon: 110.795000473,

? ? ? ? ? ? lat: 32.638540762,

? ? ? ? ? ? color: Cesium.Color.RED,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 3,

? ? ? ? ? ? lon: 111.267729446,

? ? ? ? ? ? lat: 30.698151246,

? ? ? ? ? ? color: Cesium.Color.BLUE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 4,

? ? ? ? ? ? lon: 112.126643144,

? ? ? ? ? ? lat: 32.058588576,

? ? ? ? ? ? color: Cesium.Color.GREEN,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 5,

? ? ? ? ? ? lon: 114.885884938,

? ? ? ? ? ? lat: 30.395401912,

? ? ? ? ? ? color: Cesium.Color.BLUE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 6,

? ? ? ? ? ? lon: 112.190419415,

? ? ? ? ? ? lat: 31.043949588,

? ? ? ? ? ? color: Cesium.Color.BLUE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 7,

? ? ? ? ? ? lon: 113.903569642,

? ? ? ? ? ? lat: 30.93205405,

? ? ? ? ? ? color: Cesium.Color.BLUE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 8,

? ? ? ? ? ? lon: 112.226648859,

? ? ? ? ? ? lat: 30.367904255,

? ? ? ? ? ? color: Cesium.Color.BLUE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 9,

? ? ? ? ? ? lon: 114.86171677,

? ? ? ? ? ? lat: 30.468634833,

? ? ? ? ? ? color: Cesium.Color.BLUE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 10,

? ? ? ? ? ? lon: 114.317846048,

? ? ? ? ? ? lat: 29.848946148,

? ? ? ? ? ? color: Cesium.Color.BLUE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 11,

? ? ? ? ? ? lon: 113.371985426,

? ? ? ? ? ? lat: 31.70498833,

? ? ? ? ? ? color: Cesium.Color.BLUE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 12,

? ? ? ? ? ? lon: 109.468884533,

? ? ? ? ? ? lat: 30.289012191,

? ? ? ? ? ? color: Cesium.Color.BLUE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 13,

? ? ? ? ? ? lon: 113.414585069,

? ? ? ? ? ? lat: 30.368350431,

? ? ? ? ? ? color: Cesium.Color.SALMON,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 14,

? ? ? ? ? ? lon: 112.892742589,

? ? ? ? ? ? lat: 30.409306203,

? ? ? ? ? ? color: Cesium.Color.WHITE,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 15,

? ? ? ? ? ? lon: 113.16085371,

? ? ? ? ? ? lat: 30.667483468,

? ? ? ? ? ? color: Cesium.Color.SALMON,

? ? ? ? ? ? size: 15

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? id: 16,

? ? ? ? ? ? lon: 110.670643354,

? ? ? ? ? ? lat: 31.74854078,

? ? ? ? ? ? color: Cesium.Color.PINK,

? ? ? ? ? ? size: 15

? ? ? ? ? }

? ? ? ? ],

? ? ? ? options: {

? ? ? ? ? name: "",

? ? ? ? ? polyline: {

? ? ? ? ? ? width: 2,

? ? ? ? ? ? material: [Cesium.Color.GREEN, 3000]

? ? ? ? ? }

? ? ? ? }

? ? ? };

? ? ? this.createFlyLines(data);

? ? },

? ? createFlyLines(data) {

? ? ? const center = data.center;

? ? ? const cities = data.points;

? ? ? const startPoint = Cesium.Cartesian3.fromDegrees(

? ? ? ? center.lon,

? ? ? ? center.lat,

? ? ? ? 0

? ? ? );

? ? ? //中心點(diǎn)

? ? ? this.viewer.entities.add({

? ? ? ? position: startPoint,

? ? ? ? point: {

? ? ? ? ? pixelSize: center.size,

? ? ? ? ? color: center.color

? ? ? ? }

? ? ? });

? ? ? //大批量操作時(shí)冈在,臨時(shí)禁用事件可以提高性能

? ? ? this.viewer.entities.suspendEvents();

? ? ? //散點(diǎn)

? ? ? cities.map(city => {

? ? ? ? let material = new Cesium.PolylineTrailMaterialProperty({

? ? ? ? ? color: Cesium.Color.GREEN,

? ? ? ? ? duration: 3000,

? ? ? ? ? trailImage: "images/colors1.png"

? ? ? ? });

? ? ? ? const endPoint = Cesium.Cartesian3.fromDegrees(city.lon, city.lat, 0);

? ? ? ? this.viewer.entities.add({

? ? ? ? ? position: endPoint,

? ? ? ? ? point: {

? ? ? ? ? ? pixelSize: city.size - 10,

? ? ? ? ? ? color: city.color

? ? ? ? ? }

? ? ? ? });

? ? ? ? this.viewer.entities.add({

? ? ? ? ? polyline: {

? ? ? ? ? ? positions: this.generateCurve(startPoint, endPoint),

? ? ? ? ? ? width: 2,

? ? ? ? ? ? material: material

? ? ? ? ? }

? ? ? ? });

? ? ? });

? ? ? this.viewer.entities.resumeEvents();

? ? ? this.viewer.flyTo(this.viewer.entities);

? ? },

? ? /**

? ? * 生成流動(dòng)曲線

? ? * @param startPoint 起點(diǎn)

? ? * @param endPoint 終點(diǎn)

? ? * @returns {Array}

? ? */

? ? generateCurve(startPoint, endPoint) {

? ? ? let addPointCartesian = new Cesium.Cartesian3();

? ? ? Cesium.Cartesian3.add(startPoint, endPoint, addPointCartesian);

? ? ? let midPointCartesian = new Cesium.Cartesian3();

? ? ? Cesium.Cartesian3.divideByScalar(addPointCartesian, 2, midPointCartesian);

? ? ? let midPointCartographic = Cesium.Cartographic.fromCartesian(

? ? ? ? midPointCartesian

? ? ? );

? ? ? midPointCartographic.height =

? ? ? ? Cesium.Cartesian3.distance(startPoint, endPoint) / 5;

? ? ? let midPoint = new Cesium.Cartesian3();

? ? ? Cesium.Ellipsoid.WGS84.cartographicToCartesian(

? ? ? ? midPointCartographic,

? ? ? ? midPoint

? ? ? );

? ? ? let spline = new Cesium.CatmullRomSpline({

? ? ? ? times: [0.0, 0.5, 1.0],

? ? ? ? points: [startPoint, midPoint, endPoint]

? ? ? });

? ? ? let curvePoints = [];

? ? ? for (let i = 0, len = 200; i < len; i++) {

? ? ? ? curvePoints.push(spline.evaluate(i / len));

? ? ? }

? ? ? return curvePoints;

? ? }

? }

};

</script>

<style lang="scss" >

</style>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末氧吐,一起剝皮案震驚了整個(gè)濱河市洲尊,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖蚣常,帶你破解...
    沈念sama閱讀 221,695評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡余黎,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,569評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門(mén)灸蟆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)驯耻,“玉大人,你說(shuō)我怎么就攤上這事炒考】筛浚” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 168,130評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵斋枢,是天一觀的道長(zhǎng)帘靡。 經(jīng)常有香客問(wèn)我,道長(zhǎng)瓤帚,這世上最難降的妖魔是什么描姚? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 59,648評(píng)論 1 297
  • 正文 為了忘掉前任,我火速辦了婚禮戈次,結(jié)果婚禮上轩勘,老公的妹妹穿的比我還像新娘。我一直安慰自己怯邪,他們只是感情好绊寻,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,655評(píng)論 6 397
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著,像睡著了一般澄步。 火紅的嫁衣襯著肌膚如雪冰蘑。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 52,268評(píng)論 1 309
  • 那天村缸,我揣著相機(jī)與錄音祠肥,去河邊找鬼。 笑死梯皿,一個(gè)胖子當(dāng)著我的面吹牛仇箱,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播索烹,決...
    沈念sama閱讀 40,835評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼工碾,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了百姓?” 一聲冷哼從身側(cè)響起渊额,我...
    開(kāi)封第一講書(shū)人閱讀 39,740評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎垒拢,沒(méi)想到半個(gè)月后旬迹,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,286評(píng)論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡求类,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,375評(píng)論 3 340
  • 正文 我和宋清朗相戀三年奔垦,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片尸疆。...
    茶點(diǎn)故事閱讀 40,505評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡椿猎,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出寿弱,到底是詐尸還是另有隱情犯眠,我是刑警寧澤,帶...
    沈念sama閱讀 36,185評(píng)論 5 350
  • 正文 年R本政府宣布症革,位于F島的核電站筐咧,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏噪矛。R本人自食惡果不足惜量蕊,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,873評(píng)論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望艇挨。 院中可真熱鬧残炮,春花似錦、人聲如沸缩滨。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,357評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至蛋勺,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間鸠删,已是汗流浹背抱完。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,466評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留刃泡,地道東北人巧娱。 一個(gè)月前我還...
    沈念sama閱讀 48,921評(píng)論 3 376
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像烘贴,于是被迫代替她去往敵國(guó)和親禁添。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,515評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容

  • 因gif截圖問(wèn)題桨踪,動(dòng)畫(huà)效果看起來(lái)不夠流暢老翘。 1.調(diào)用方法 <!DOCTYPE html> 圓形波紋 ...
    happy_port閱讀 6,078評(píng)論 11 6
  • 那株不愿向著陽(yáng)光的桃花 傲然的獨(dú)自生長(zhǎng) 只因在這山間中 一覽江畔人家 螢火 鳴蟲(chóng) 鴻雁 借驟雨中的漣漪 與...
    陌允諾閱讀 273評(píng)論 0 1
  • 今天上午辦公之余,閑來(lái)伸伸懶腰锻离,轉(zhuǎn)到窗臺(tái)铺峭,看見(jiàn)榛子,隨手嗑了幾個(gè)汽纠,竟嗑出些許感慨來(lái)卫键。 榛子這東西,睹物可以思人虱朵。 ...
    放下皆得閱讀 2,771評(píng)論 20 195
  • 拼車羞福!拼車!拼車回家蚯涮!有沒(méi)有2月12號(hào)從惠州白石或者深圳坪山回湖北黃岡的還沒(méi)買(mǎi)到車票的老鄉(xiāng)治专,我們一起拼車回家,還差...
    飄_a1ad閱讀 270評(píng)論 0 0