栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

cesium 图层构建的那些事 (二十)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

cesium 图层构建的那些事 (二十)

接上一篇风场文章

请求工具类

export class FetchUtil {

private static obj2String(obj: any = {}, arr: any = [], idx: any = 0) {
for (let item in obj) {
arr[idx++] = [item, obj[item]]
}
return new URLSearchParams(arr).toString()
}


static async commonFetcdh(url: any, options: any, method: any = ‘GET’) {
const searchStr = this.obj2String(options)
let initObj = {}
if (method === ‘GET’) { // 如果是GET请求,拼接url
if (searchStr) {
url += ‘?’ + searchStr
}
initObj = {
method: method,
credentials: ‘include’
}
} else {
initObj = {
method: method,
credentials: ‘include’,
headers: new Headers({
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/x-www-form-urlencoded’
}),
body: searchStr
}
}
const res = await fetch(url, initObj);
const result = await res.json();
return result;
}


static GET(url: any, options?: any):Promise {
return this.commonFetcdh(url, options, ‘GET’)
}


static POST(url: any, options?: any):Promise {
return this.commonFetcdh(url, options, ‘POST’)
}
}
风场主类

import {FetchUtil} from "./FetchUtil";
import {Layer} from "./Layer";
import Field from "./Field";
import WindCanvas from "./WindCanvas";

export class VectorFieldLayer extends Layer {
private option: any = {
globalAlpha: 0.9,
lineWidth: 1,
colorScale: '#fff',
velocityScale: 1 / 25,
maxAge: 90,
paths: 800,
frameRate: 20,
useCoordsDraw: true,
gpet: true
};
private _data: any;
private url: string;
private canvas: any = document.createElement('canvas')

constructor(url: string, option: any) {
super(option.name)
this.url = url;
this.setOptions(option);
this.isAdd2LoadCesium = true;
}
 
protected _addToMap(map: any): void {
if (this.url) {
FetchUtil.GET(this.url).then((data: any) => {
this._mountCanvas();
let ctx = this.canvas.getContext('2d')
this.cesiumObj = new WindCanvas(ctx, map, this.option);
this.setData(data);
})
} else {
throw new Error("没有填写url");
}
 
}
 
protected _removeByMap(destroy?: boolean): void {
if (this.cesiumObj) {
this.cesiumObj.clearCanvas();
}
if (this.canvas) {
this.map.container.removeChild(this.canvas)
}
this.canvas = null;
}
 更多参考 https://xiaozhuanlan.com/topic/3590618724
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/724274.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号