UNPKG

@dspacev-bundle/vue-cesium

Version:
1,426 lines (1,397 loc) 1.66 MB
/*! VueCesium v3.1.5 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('lodash-es'), require('mitt'), require('echarts')) : typeof define === 'function' && define.amd ? define(['exports', 'vue', 'lodash-es', 'mitt', 'echarts'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VueCesium = {}, global.Vue, global.lodashEs, global.mitt, global.echarts)); })(this, (function (exports, vue, lodashEs, mitt, echarts) { 'use strict'; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return Object.freeze(n); } var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt); var echarts__namespace = /*#__PURE__*/_interopNamespace(echarts); const version$1 = "3.1.5"; const hasSymbol = typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol"; const vcKey = hasSymbol ? Symbol("VueCesium") : "VueCesium"; const fabKey = hasSymbol ? Symbol("_vc_f_") : "_vc_f_"; const configProviderContextKey = Symbol(); /** * Make a map and return a function for checking if a key * is in that map. * IMPORTANT: all calls of this function must be prefixed with * \/\*#\_\_PURE\_\_\*\/ * So that rollup can tree-shake them if necessary. */ const hasOwnProperty$1 = Object.prototype.hasOwnProperty; const hasOwn = (val, key) => hasOwnProperty$1.call(val, key); const isArray = Array.isArray; const isFunction = (val) => typeof val === 'function'; const isString = (val) => typeof val === 'string'; const isObject = (val) => val !== null && typeof val === 'object'; const objectToString = Object.prototype.toString; const toTypeString = (value) => objectToString.call(value); const isPlainObject = (val) => toTypeString(val) === '[object Object]'; const cacheStringFunction = (fn) => { const cache = Object.create(null); return ((str) => { const hit = cache[str]; return hit || (cache[str] = fn(str)); }); }; const camelizeRE = /-(\w)/g; /** * @private */ const camelize = cacheStringFunction((str) => { return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : '')); }); const hyphenateRE = /\B([A-Z])/g; /** * @private */ const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase()); /** * @private */ const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1)); function dirname(path) { if (typeof path !== "string") path = path + ""; if (path.length === 0) return "."; let code = path.charCodeAt(0); const hasRoot = code === 47; let end = -1; let matchedSlash = true; for (let i = path.length - 1; i >= 1; --i) { code = path.charCodeAt(i); if (code === 47) { if (!matchedSlash) { end = i; break; } } else { matchedSlash = false; } } if (end === -1) return hasRoot ? "/" : "."; if (hasRoot && end === 1) { return "/"; } return path.slice(0, end); } function isEmptyObj(obj) { if (lodashEs.isUndefined(obj) || lodashEs.isNull(obj)) { return true; } if (obj instanceof Element) { return false; } const arr = Object.keys(obj); return arr.length === 0; } const kebabCase = hyphenate; function myInstanceof(left, right) { if (typeof left !== "object" || left === null) return false; let proto = Object.getPrototypeOf(left); while (true) { if (proto === null) return false; if (proto === (right == null ? void 0 : right.prototype)) return true; proto = Object.getPrototypeOf(proto); } } function getCesiumClassName(obj) { let result = void 0; const constructorNames = Object.keys(Cesium); for (let i = 0; i < constructorNames.length; i++) { const className = constructorNames[i]; if (myInstanceof(obj, Cesium[className])) { result = className; break; } } return result; } function getObjClassName(obj, findCesiumClass = false) { if (obj && obj.constructor) { if (findCesiumClass) { const cesiumClassName = getCesiumClassName(obj); if (cesiumClassName) { return cesiumClassName; } } return obj.constructor.name; } return typeof obj; } function defaultValue(a, b) { if (a !== void 0 && a !== null) { return a; } return b; } function getDefaultOptionByProps(props, ignores = []) { const defaultOptions = {}; Object.keys(props).forEach((key) => { if (ignores.indexOf(key) === -1) { const value = props[key]; defaultOptions[key] = isFunction(value) ? void 0 : isPlainObject(value) ? isFunction(value.default) ? value.default() : value.default : value; } }); return defaultOptions; } const addCustomProperty = (obj, options, ignores = []) => { for (const prop in options) { if (!obj[prop] && ignores.indexOf(prop) === -1) { obj[prop] = options[prop]; } } }; function isArrayLike(obj) { if (Array.isArray(obj)) return true; if (typeof obj !== "object" || !obj) return false; const length = obj.length; return typeof length === "number" && length >= 0; } function deepMerge(src = {}, target = {}) { let key; for (key in target) { src[key] = isObject(src[key]) ? deepMerge(src[key], target[key]) : src[key] = target[key]; } return src; } function isNumber$1(v) { return typeof v === "number" && isFinite(v); } function getCesiumColor(inputColor, fallbackColor, timestamp) { const { JulianDate, Color } = Cesium; const now = JulianDate.now(); if (inputColor) { if (typeof inputColor.getValue === "function") { inputColor = inputColor.getValue(timestamp || now); } if (typeof inputColor === "string") { return Color.fromCssColorString(inputColor); } else if (typeof inputColor === "function") { return getCesiumColor(inputColor(timestamp), fallbackColor); } else { return inputColor; } } else { return fallbackColor; } } function getCesiumValue(value, valueType, timestamp) { const { JulianDate, Property } = Cesium; const now = JulianDate.now(); if (!value) return value; if (valueType) { if (value instanceof valueType) return value; else { if (value instanceof Property && value._value instanceof valueType) return value._value; } } if (isFunction(value.getValue)) return value.getValue(timestamp || now); return value; } const keysOf = (arr) => Object.keys(arr); const globalConfig = vue.ref(); function useGlobalConfig(key, defaultValue = void 0) { const config = vue.getCurrentInstance() ? vue.inject(configProviderContextKey, globalConfig) : globalConfig; if (key) { return vue.computed(() => { var _a, _b; return (_b = (_a = config.value) == null ? void 0 : _a[key]) != null ? _b : defaultValue; }); } else { return config; } } const provideGlobalConfig = (config, app, global = false) => { var _a; const inSetup = !!vue.getCurrentInstance(); const oldConfig = inSetup ? useGlobalConfig() : void 0; const provideFn = (_a = app == null ? void 0 : app.provide) != null ? _a : inSetup ? vue.provide : void 0; if (!provideFn) { console.warn("provideGlobalConfig", "provideGlobalConfig() can only be used inside setup()."); return; } const context = vue.computed(() => { const cfg = vue.unref(config); if (!(oldConfig == null ? void 0 : oldConfig.value)) return cfg; return mergeConfig(oldConfig.value, cfg); }); if (app == null ? void 0 : app.provide) { app.provide(configProviderContextKey, context); } else { vue.provide(configProviderContextKey, context); } if (global || !globalConfig.value) { globalConfig.value = context.value; } return context; }; const mergeConfig = (a, b) => { var _a; const keys = [.../* @__PURE__ */ new Set([...keysOf(a), ...keysOf(b)])]; const obj = {}; for (const key of keys) { obj[key] = (_a = b[key]) != null ? _a : a[key]; } return obj; }; function useLog(vcInstance) { var _a, _b, _c, _d; const makeLog = (prefix = "") => { return function(...args) { if (prefix) { if (isString(args[0])) { args[0] = prefix.trim() + " " + args[0]; } else { args = [prefix.trim(), ...args]; } } console.log(...args); }; }; const makeWarn = (prefix = "") => { return function(...args) { if (prefix) { if (isString(args[0])) { args[0] = prefix.trim() + " " + args[0]; } else { args = [prefix.trim(), ...args]; } } console.warn(...args); }; }; const makeError = (prefix = "") => { return function(...args) { if (prefix) { if (isString(args[0])) { args[0] = prefix.trim() + " " + args[0]; } else { args = [prefix.trim(), ...args]; } } console.error(...args); }; }; const makeDebug = (prefix = "") => { return function(...args) { if (prefix) { if (isString(args[0])) { args[0] = prefix.trim() + " " + args[0]; } else { args = [prefix.trim(), ...args]; } } }; }; const typeColor = (type = "default") => { let color = ""; switch (type) { case "default": color = "#35495E"; break; case "primary": color = "#3488ff"; break; case "success": color = "#43B883"; break; case "warning": color = "#e6a23c"; break; case "danger": color = "#f56c6c"; break; } return color; }; const capsule = (title, info, type = "primary") => { console.log( `%c ${title} %c ${info} %c`, "background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;", `background:${typeColor(type)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`, "background:transparent" ); }; const colorful = (textArr) => { console.log(`%c${textArr.map((t) => t.text || "").join("%c")}`, ...textArr.map((t) => `color: ${typeColor(t.type)};`)); }; const success = (text) => { colorful([{ text, type: "success" }]); }; const warning = (text) => { colorful([{ text, type: "warning" }]); }; const danger = (text) => { colorful([{ text, type: "danger" }]); }; const primary = (text) => { colorful([{ text, type: "primary" }]); }; return { log: makeLog(`[VueCesium] ${(_a = vcInstance == null ? void 0 : vcInstance.proxy) == null ? void 0 : _a.$options.name}`), warn: makeWarn(`[VueCesium] WARN ${(_b = vcInstance == null ? void 0 : vcInstance.proxy) == null ? void 0 : _b.$options.name}`), error: makeError(`[VueCesium] ERR ${(_c = vcInstance == null ? void 0 : vcInstance.proxy) == null ? void 0 : _c.$options.name}`), debug: makeDebug(`[VueCesium] Debug ${(_d = vcInstance == null ? void 0 : vcInstance.proxy) == null ? void 0 : _d.$options.name}`), capsule, success, warning, danger, primary }; } useLog(void 0); const INSTALLED_KEY = Symbol("INSTALLED_KEY"); const makeInstaller = (components = []) => { const install = (app, opts) => { if (app[INSTALLED_KEY]) return; const defaultConfig = { cesiumPath: "https://unpkg.com/cesium@latest/Build/Cesium/Cesium.js", accessToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2OGE2MjZlOC1mMzhiLTRkZjQtOWEwZi1jZTE0MWY0YzhlMTAiLCJpZCI6MjU5LCJpYXQiOjE2NDM3MjU1NzZ9.ptZ5tVXvMmuWRC0WhjtYTg-17nQh14fgxBsx0HJiVXQ" }; app[INSTALLED_KEY] = true; const options = Object.assign(defaultConfig, opts); components.forEach((c) => { app.use(c, options); }); provideGlobalConfig(options, app, true); }; return { version: version$1, install }; }; /*! * merge-descriptors * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ const hasOwnProperty = Object.prototype.hasOwnProperty; function merge(dest, src, redefine) { if (!dest) { throw new TypeError("argument dest is required"); } if (!src) { throw new TypeError("argument src is required"); } if (redefine === void 0) { redefine = true; } Object.getOwnPropertyNames(src).forEach(function forEachOwnPropertyName(name) { if (!redefine && hasOwnProperty.call(dest, name)) { return; } const descriptor = Object.getOwnPropertyDescriptor(src, name); Object.defineProperty(dest, name, descriptor); }); return dest; } function mergeDescriptors(...args) { let redefine; if (typeof args[args.length - 1] !== "object") { redefine = args.pop(); } return args.slice(1).reduce((dest, src, i) => merge(dest, src, redefine), args[0]); } function vmHasRouter(vm) { return vm.appContext.config.globalProperties.$router !== void 0; } function vmHasListener(vm, listenerName) { return vm.vnode.props !== null && vm.vnode.props[listenerName] !== void 0; } function getInstanceListener(vcInstance, listenerName) { const props = vcInstance.vnode.props; if (props === null) { return void 0; } const propKeys = Object.keys(props); const index = lodashEs.findIndex(propKeys, (o) => { return o.includes(`on${capitalize(listenerName)}`) || o.includes(`on${capitalize(lodashEs.camelCase(listenerName))}`); }); const listener = props[propKeys[index]]; return listener; } function $(ref) { return ref.value; } function getVcParentInstance(instance) { var _a, _b; const parentInstance = instance.parent; return !parentInstance.cesiumClass && ((_a = parentInstance.proxy) == null ? void 0 : _a.$options.name) !== "VcViewer" ? getVcParentInstance(parentInstance) : ((_b = parentInstance.proxy) == null ? void 0 : _b.getVcViewer) ? parentInstance.proxy.getVcViewer().getInstance() : parentInstance; } const semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i; const validateAndParse = (version) => { if (typeof version !== 'string') { throw new TypeError('Invalid argument expected string'); } const match = version.match(semver); if (!match) { throw new Error(`Invalid argument not valid semver ('${version}' received)`); } match.shift(); return match; }; const isWildcard = (s) => s === '*' || s === 'x' || s === 'X'; const tryParse = (v) => { const n = parseInt(v, 10); return isNaN(n) ? v : n; }; const forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b]; const compareStrings = (a, b) => { if (isWildcard(a) || isWildcard(b)) return 0; const [ap, bp] = forceType(tryParse(a), tryParse(b)); if (ap > bp) return 1; if (ap < bp) return -1; return 0; }; const compareSegments = (a, b) => { for (let i = 0; i < Math.max(a.length, b.length); i++) { const r = compareStrings(a[i] || '0', b[i] || '0'); if (r !== 0) return r; } return 0; }; /** * Compare [semver](https://semver.org/) version strings to find greater, equal or lesser. * This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`. * @param v1 - First version to compare * @param v2 - Second version to compare * @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters). */ const compareVersions = (v1, v2) => { // validate input and split into segments const n1 = validateAndParse(v1); const n2 = validateAndParse(v2); // pop off the patch const p1 = n1.pop(); const p2 = n2.pop(); // validate numbers const r = compareSegments(n1, n2); if (r !== 0) return r; // validate pre-release if (p1 && p2) { return compareSegments(p1.split('.'), p2.split('.')); } else if (p1 || p2) { return p1 ? -1 : 1; } return 0; }; /** * Compare [semver](https://semver.org/) version strings using the specified operator. * * @param v1 First version to compare * @param v2 Second version to compare * @param operator Allowed arithmetic operator to use * @returns `true` if the comparison between the firstVersion and the secondVersion satisfies the operator, `false` otherwise. * * @example * ``` * compare('10.1.8', '10.0.4', '>'); // return true * compare('10.0.1', '10.0.1', '='); // return true * compare('10.1.1', '10.2.2', '<'); // return true * compare('10.1.1', '10.2.2', '<='); // return true * compare('10.1.1', '10.2.2', '>='); // return false * ``` */ const compare = (v1, v2, operator) => { // validate input operator assertValidOperator(operator); // since result of compareVersions can only be -1 or 0 or 1 // a simple map can be used to replace switch const res = compareVersions(v1, v2); return operatorResMap[operator].includes(res); }; const operatorResMap = { '>': [1], '>=': [0, 1], '=': [0], '<=': [-1, 0], '<': [-1], '!=': [-1, 1], }; const allowedOperators = Object.keys(operatorResMap); const assertValidOperator = (op) => { if (typeof op !== 'string') { throw new TypeError(`Invalid operator type, expected string but got ${typeof op}`); } if (allowedOperators.indexOf(op) === -1) { throw new Error(`Invalid operator, expected one of ${allowedOperators.join('|')}`); } }; var VcCircleWaveMaterial = ` czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material material = czm_getDefaultMaterial(materialInput); material.diffuse = 1.5 * color.rgb; vec2 st = materialInput.st; vec3 str = materialInput.str; float dis = distance(st, vec2(0.5, 0.5)); float per = fract(time); if (abs(str.z) > 0.001) { discard; } if (dis > 0.5) { discard; } else { float perDis = 0.5 / count; float disNum; float bl = .0; for (int i = 0; i <= 9; i++) { if (float(i) <= count) { disNum = perDis *float(i) - dis + per / count; if (disNum > 0.0) { if (disNum < perDis) { bl = 1.0 - disNum / perDis; } else if(disNum - perDis < perDis) { bl = 1.0 - abs(1.0 - disNum / perDis); } material.alpha = pow(bl, gradient); } } } } return material; }`; var VcLineFlowMaterial = ` uniform float globalAlpha; uniform bool axisY; uniform bool mixt; czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material material = czm_getDefaultMaterial(materialInput); vec2 st = repeat * materialInput.st; vec4 colorImage; if (speed != 0.0) { float currTime; if (time < 0.0) { currTime = speed * czm_frameNumber / 1000.0; } else { currTime = time; } colorImage = texture(image, vec2(fract((axisY ? st.t : st.s) - currTime), st.t)); } else { colorImage = texture(image, st); } if (color.a == 0.0) { if (colorImage.rgb == vec3(1.0)) { discard; } } if (color.rgb == vec3(1.0)) { material.alpha = colorImage.a * globalAlpha; material.diffuse = colorImage.rgb; } else { material.alpha = colorImage.a * color.a * globalAlpha; if (mixt) material.diffuse = max(colorImage.rgb * color.rgb * material.alpha * 3.0, colorImage.rgb * color.rgb); else material.diffuse = max(color.rgb * material.alpha * 3.0, color.rgb); } if (hasImage2) { vec4 colorBG = texture(image2, materialInput.st); if (colorBG.a > 0.5) { material.diffuse = color2.rgb; } } return material; } `; let isExtended$2 = false; class MaterialExtend { static extend(viewer) { var _a; if (isExtended$2) { return; } const { Material, Color, Cartesian2 } = Cesium; const webgl2 = (_a = viewer.scene.context) == null ? void 0 : _a.webgl2; let shaderSourceTextVcLine = VcLineFlowMaterial; let shaderSourceTextVcCircle = VcCircleWaveMaterial; if (!webgl2) { shaderSourceTextVcLine = shaderSourceTextVcLine.replace(/texture\(/g, "texture2D("); shaderSourceTextVcCircle = shaderSourceTextVcCircle.replace(/texture\(/g, "texture2D("); } Material["VcCircleWave"] = "VcCircleWave"; Cesium.Material["_materialCache"].addMaterial(Material["VcCircleWave"], { fabric: { type: Material["VcCircleWave"], uniforms: { color: new Color(1, 0, 0, 1), time: 1, count: 1, gradient: 0.1 }, source: shaderSourceTextVcCircle }, translucent() { return true; } }); Material["VcLineFlow"] = "VcLineFlow"; Cesium.Material["_materialCache"].addMaterial(Material["VcLineFlow"], { fabric: { type: Material["VcLineFlow"], uniforms: { image: Material.DefaultImageId, color: new Color(1, 1, 1, 1), repeat: new Cartesian2(1, 1), axisY: false, mixt: false, speed: 10, time: -1, hasImage2: false, image2: Material.DefaultImageId, color2: new Color(1, 1, 1), globalAlpha: 1 }, source: shaderSourceTextVcLine }, translucent() { return true; } }); isExtended$2 = true; } static revoke(viewer) { if (!isExtended$2) { return; } isExtended$2 = false; } } class BaseMaterialProperty { constructor(options = {}) { this.options = options; this._definitionChanged = new Cesium.Event(); } get isConstant() { return true; } get definitionChanged() { return this._definitionChanged; } getType(parameter) { return null; } getValue(context, defaultValue = {}) { return defaultValue; } equals(other) { return this === other; } } class VcCircleWaveMaterialProperty extends BaseMaterialProperty { constructor(options) { super(options); const { Event, defaultValue } = Cesium; if (!Object.getOwnPropertyDescriptor(VcCircleWaveMaterialProperty.prototype, "color")) { Object.defineProperties(VcCircleWaveMaterialProperty.prototype, { color: Cesium["createPropertyDescriptor"]("color") }); } this._definitionChanged = new Event(); this._color = new Cesium.ConstantProperty(options.color); this._duration = defaultValue(options.duration, 1e3); this.count = defaultValue(options.count, 2); if (this.count <= 0) { this.count = 1; } this._gradient = defaultValue(options.gradient, 0.1); if (this._gradient === 0) { this._gradient = 0; } if (this._gradient > 1) { this._gradient = 1; } this._time = (/* @__PURE__ */ new Date()).getTime(); } get isConstant() { return false; } get definitionChanged() { return this._definitionChanged; } get color() { return this._color; } set color(value) { const oldValue = this._color; if (oldValue !== value) { this._color = new Cesium.ConstantProperty(value); this._definitionChanged.raiseEvent(this, "color", value, oldValue); } } get duration() { return this._duration; } set duration(value) { const oldValue = this._duration; if (oldValue !== value) { this._duration = value; this._definitionChanged.raiseEvent(this, "duration", value, oldValue); } } get count() { return this._count; } set count(value) { const oldValue = this._count; if (oldValue !== value) { this._count = value; this._definitionChanged.raiseEvent(this, "count", value, oldValue); } } getType() { return "VcCircleWave"; } getValue(time, result) { if (!Cesium.defined(result)) { result = {}; } result.color = Cesium.Property["getValueOrClonedDefault"](this._color, time, Cesium.Color.YELLOW, result.color); result.time = ((/* @__PURE__ */ new Date()).getTime() - this._time) % this.duration / this.duration; result.count = this.count; result.gradient = 1 + 10 * (1 - this._gradient); return result; } equals(other) { const reData = this === other || other instanceof VcCircleWaveMaterialProperty && Cesium.Property["equals"](this._color, other._color); return reData; } } class VcLineFlowMaterialProperty extends BaseMaterialProperty { constructor(options = {}) { var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; super(options); const { Color, Cartesian2, defined } = Cesium; this.image = (_a = options.image) != null ? _a : options.url; this.color = (_b = options.color) != null ? _b : new Color(1, 1, 1, 0); this.axisY = (_c = options.axisY) != null ? _c : false; this.mixt = (_d = options.mixt) != null ? _d : false; this.speed = (_e = options.speed) != null ? _e : 10; this.duration = options.duration; this.repeat = (_f = options.repeat) != null ? _f : new Cartesian2(1, 1); this.image2 = (_g = options.image2) != null ? _g : options.bgUrl; this.color2 = (_i = (_h = options.color2) != null ? _h : options.bgColor) != null ? _i : new Color(1, 1, 1, 0); this.hasImage2 = defined(this.image2); this.globalAlpha = (_j = options.globalAlpha) != null ? _j : true; } getType(value) { return "VcLineFlow"; } getValue(time, result) { const { Color, Cartesian2, defined } = Cesium; !defined(result) && (result = {}); result.image = this.image; result.color = getCesiumColor(this.color, new Color(1, 1, 1, 0), time); result.repeat = getCesiumValue(this.repeat, Cartesian2, time); result.axisY = this.axisY; result.mixt = this.mixt; result.speed = getCesiumValue(this.speed, Number, time); if (this.duration) { if (this._time === void 0) { this._time = (/* @__PURE__ */ new Date()).getTime(); result.time = ((/* @__PURE__ */ new Date()).getTime() - this._time) / (this.duration * 1e3); } } else { result.time = -1; } result.hasImage2 = this.hasImage2; result.image2 = this.image2; result.color2 = getCesiumColor(this.color2, new Color(1, 1, 1, 0), time); result.globalAlpha = this.globalAlpha; return result; } equals(other) { const reData = this === other || other instanceof VcLineFlowMaterialProperty && Cesium.Property["equals"](this.color, other.color) && Cesium.Property["equals"](this.repeat, other.repeat) && this.image === other.image && this.axisY === other.axisY && this.speed === other.speed && this.hasImage2 === other.hasImage2 && this.image2 === other.image2 && this.image2 === other.image2 && Cesium.Property["equals"](this.color2, other.color2); return reData; } } function makeCartesian2(val, isConstant = false) { const { Cartesian2, CallbackProperty } = Cesium; if (val instanceof Cesium.Cartesian2 || val instanceof CallbackProperty) { return val; } if (isPlainObject(val)) { if (hasOwn(val, "x") && hasOwn(val, "y")) { const value = val; return new Cartesian2(value.x, value.y); } } if (isArray(val)) { return new Cartesian2(val[0], val[1]); } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return void 0; } function makeCartesian3(val, ellipsoid, isConstant = false) { const { CallbackProperty, Cartesian3, Ellipsoid, SampledPositionProperty, CompositePositionProperty, ConstantPositionProperty, TimeIntervalCollectionPositionProperty } = Cesium; if (val instanceof Cartesian3 || val instanceof CallbackProperty || val instanceof SampledPositionProperty || val instanceof CompositePositionProperty || val instanceof ConstantPositionProperty || val instanceof TimeIntervalCollectionPositionProperty) { return val; } ellipsoid = ellipsoid || Ellipsoid.WGS84; if (isPlainObject(val)) { if (hasOwn(val, "x") && hasOwn(val, "y") && hasOwn(val, "z")) { const value = val; return new Cartesian3(value.x, value.y, value.z); } else if (hasOwn(val, "lng") && hasOwn(val, "lat")) { const value = val; return Cartesian3.fromDegrees(value.lng, value.lat, value.height || 0, ellipsoid); } } if (isArray(val)) { return Cartesian3.fromDegrees(val[0], val[1], val[2] || 0, ellipsoid); } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return void 0; } function makeCartesian3Array(vals, ellipsoid, isConstant = false) { const { CallbackProperty, Cartesian3, Ellipsoid } = Cesium; if (vals instanceof CallbackProperty) { return vals; } if (isFunction(vals)) { return new CallbackProperty(vals, isConstant); } ellipsoid = ellipsoid || Ellipsoid.WGS84; if (isArray(vals)) { if (isArray(vals[0]) || isPlainObject(vals[0])) { const results = []; vals.forEach((val) => { results.push(makeCartesian3(val, ellipsoid)); }); return results; } return Cartesian3.fromDegreesArrayHeights(vals, ellipsoid); } return void 0; } function makeCartesian2Array(vals, isConstant) { const { CallbackProperty } = Cesium; if (vals instanceof CallbackProperty) { return vals; } if (isFunction(vals)) { return new CallbackProperty(vals, isConstant); } if (isArray(vals)) { const points = []; vals.forEach((val) => { points.push(makeCartesian2(val)); }); return points; } return void 0; } function makeQuaternion(val, isConstant = false) { const { CallbackProperty, Quaternion, VelocityOrientationProperty } = Cesium; if (val instanceof Quaternion || val instanceof CallbackProperty || val instanceof VelocityOrientationProperty) { return val; } if (isPlainObject(val) && hasOwn(val, "x") && hasOwn(val, "y")) { const value = val; return new Quaternion(value.x, value.y, value.z, value.w); } if (isArray(val)) { return new Quaternion(val[0], val[1], val[2], val[3]); } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return void 0; } function parsePolygonHierarchyJson(val, ellipsoid) { val.forEach((item) => { item.positions = makeCartesian3Array(item.positions, ellipsoid); if (item.holes) { parsePolygonHierarchyJson(item.holes, ellipsoid); } }); } function makePolygonHierarchy(val, ellipsoid, isConstant = false) { var _a; const { PolygonHierarchy, CallbackProperty } = Cesium; if (val instanceof PolygonHierarchy || val instanceof CallbackProperty) { return val; } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } if (isArray(val) && val.length >= 3) { const points = makeCartesian3Array(val, ellipsoid); return new PolygonHierarchy(points); } if (isPlainObject(val) && hasOwn(val, "positions")) { const value = val; value.positions = makeCartesian3Array(value.positions, ellipsoid); ((_a = value.holes) == null ? void 0 : _a.length) && parsePolygonHierarchyJson(value.holes, ellipsoid); return value; } return void 0; } function makeNearFarScalar(val, isConstant = false) { const { NearFarScalar, CallbackProperty } = Cesium; if (val instanceof NearFarScalar || val instanceof CallbackProperty) { return val; } if (isPlainObject(val) && hasOwn(val, "near") && hasOwn(val, "far")) { const value = val; return new NearFarScalar(value.near, value.nearValue || 0, value.far, value.farValue || 1); } if (isArray(val)) { return new NearFarScalar(val[0], val[1], val[2], val[3]); } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return void 0; } function makeDistanceDisplayCondition(val, isConstant = false) { const { DistanceDisplayCondition, CallbackProperty } = Cesium; if (val instanceof DistanceDisplayCondition || val instanceof CallbackProperty) { return val; } if (isPlainObject(val) && hasOwn(val, "near") && hasOwn(val, "far")) { const value = val; return new DistanceDisplayCondition(value.near, value.far); } if (isArray(val)) { return new DistanceDisplayCondition(val[0], val[1]); } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return void 0; } function makeColor(val, isConstant = false) { const { Color, CallbackProperty, defaultValue } = Cesium; if (val instanceof Color || val instanceof CallbackProperty) { return val; } if (isString(val)) { return Color.fromCssColorString(val); } if (isPlainObject(val)) { if (hasOwn(val, "red")) { const value = val; return Color.fromBytes( defaultValue(value.red, 255), defaultValue(value.green, 255), defaultValue(value.blue, 255), defaultValue(value.alpha, 255) ); } else if (hasOwn(val, "x")) { const value = val; return new Color(defaultValue(value.x, 1), defaultValue(value.y, 1), defaultValue(value.z, 1), defaultValue(value.w, 1)); } } if (isArray(val)) { return Color.fromBytes(val[0], val[1], val[2], defaultValue(val[3], 255)); } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return void 0; } function makeColors(vals) { if (isArray(vals)) { const results = []; vals.forEach((val) => { results.push(makeColor(val)); }); return results; } else { return vals; } } function makeMaterialProperty(val, isConstant = false) { const { CallbackProperty, Color, CheckerboardMaterialProperty, ColorMaterialProperty, CompositeMaterialProperty, GridMaterialProperty, ImageMaterialProperty, MaterialProperty, PolylineArrowMaterialProperty, PolylineDashMaterialProperty, PolylineGlowMaterialProperty, PolylineOutlineMaterialProperty, StripeMaterialProperty, StripeOrientation, defaultValue, Cartesian2, Material } = Cesium; if (val instanceof CallbackProperty || val instanceof Color || val instanceof CheckerboardMaterialProperty || val instanceof ColorMaterialProperty || val instanceof CompositeMaterialProperty || val instanceof GridMaterialProperty || val instanceof ImageMaterialProperty || val instanceof MaterialProperty || val instanceof PolylineArrowMaterialProperty || val instanceof PolylineDashMaterialProperty || val instanceof PolylineGlowMaterialProperty || val instanceof PolylineOutlineMaterialProperty || val instanceof StripeMaterialProperty || val instanceof VcCircleWaveMaterialProperty || val instanceof VcLineFlowMaterialProperty) { return val; } if (isString(val) && /(.*)\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$/.test(val) || val instanceof HTMLImageElement || val instanceof HTMLCanvasElement || val instanceof HTMLVideoElement) { return new ImageMaterialProperty({ image: val, repeat: makeCartesian2({ x: 1, y: 1 }), color: Color.WHITE, transparent: true }); } if (isArray(val) || isString(val)) { return new ColorMaterialProperty(makeColor(val)); } if (isPlainObject(val) && hasOwn(val, "fabric")) { const value = val; switch (value.fabric.type) { case "Image": return new ImageMaterialProperty({ image: value.fabric.uniforms.image, repeat: makeCartesian2(defaultValue(value.fabric.uniforms.repeat, { x: 1, y: 1 })), color: defaultValue(makeColor(value.fabric.uniforms.color), Color.WHITE), transparent: defaultValue(value.fabric.uniforms.transparent, false) }); case "Color": return new ColorMaterialProperty(makeColor(defaultValue(value.fabric.uniforms.color, Color.WHITE))); case "PolylineArrow": return new PolylineArrowMaterialProperty(makeColor(defaultValue(value.fabric.uniforms.color, Color.WHITE))); case "PolylineDash": return new PolylineDashMaterialProperty({ color: makeColor(defaultValue(value.fabric.uniforms.color, "white")), gapColor: makeColor(defaultValue(value.fabric.uniforms.gapColor, Color.TRANSPARENT)), dashLength: defaultValue(value.fabric.uniforms.taperPower, 16), dashPattern: defaultValue(value.fabric.uniforms.taperPower, 255) }); case "PolylineGlow": return new PolylineGlowMaterialProperty({ color: makeColor(defaultValue(value.fabric.uniforms.color, Color.WHITE)), glowPower: defaultValue(value.fabric.uniforms.glowPower, 0.25), taperPower: defaultValue(value.fabric.uniforms.taperPower, 1) }); case "PolylineOutline": return new PolylineOutlineMaterialProperty({ color: makeColor(defaultValue(value.fabric.uniforms.color, Color.WHITE)), outlineColor: makeColor(defaultValue(value.fabric.uniforms.outlineColor, Color.BLACK)), outlineWidth: defaultValue(value.fabric.uniforms.outlineWidth, 1) }); case "Checkerboard": return new CheckerboardMaterialProperty({ evenColor: makeColor(defaultValue(value.fabric.uniforms.evenColor, Color.WHITE)), oddColor: makeColor(defaultValue(value.fabric.uniforms.oddColor, Color.BLACK)), repeat: defaultValue(makeCartesian2(value.fabric.uniforms.repeat), { x: 2, y: 2 }) }); case "Grid": return new GridMaterialProperty({ color: makeColor(defaultValue(value.fabric.uniforms.color, Color.WHITE)), cellAlpha: defaultValue(value.fabric.uniforms.cellAlpha, 0.1), lineCount: defaultValue(makeCartesian2(value.fabric.uniforms.lineCount), { x: 8, y: 8 }), lineThickness: defaultValue(makeCartesian2(value.fabric.uniforms.lineThickness), { x: 1, y: 1 }), lineOffset: defaultValue(makeCartesian2(value.fabric.uniforms.lineOffset), { x: 0, y: 0 }) }); case "Stripe": return new StripeMaterialProperty({ orientation: defaultValue(value.fabric.uniforms.orientation, StripeOrientation.HORIZONTAL), evenColor: makeColor(defaultValue(value.fabric.uniforms.evenColor, "white")), oddColor: makeColor(defaultValue(value.fabric.uniforms.oddColor, "black")), offset: defaultValue(value.fabric.uniforms.offset, 0), repeat: defaultValue(value.fabric.uniforms.repeat, 1) }); case "VcCircleWave": { return new VcCircleWaveMaterialProperty({ duration: defaultValue(value.fabric.uniforms.duration, 3e3), gradient: defaultValue(value.fabric.uniforms.gradient, 0.5), color: makeColor(defaultValue(value.fabric.uniforms.color, Color.RED)), count: defaultValue(value.fabric.uniforms.count, 3) }); } case "VcLineFlow": { return new VcLineFlowMaterialProperty({ image: defaultValue(value.fabric.uniforms.image, Material.DefaultImageId), color: makeColor(defaultValue(value.fabric.uniforms.color, new Color(1, 1, 1, 1))), repeat: makeCartesian2(defaultValue(value.fabric.uniforms.repeat, new Cartesian2(1, 1))), axisY: defaultValue(value.fabric.uniforms.axisY, false), mixt: defaultValue(value.fabric.uniforms.mixt, false), speed: defaultValue(value.fabric.uniforms.speed, 10), time: defaultValue(value.fabric.uniforms.time, -1) }); } } } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return val; } function makeMaterial(val) { var _a; const vcInstance = this; const cmpName = (_a = vcInstance == null ? void 0 : vcInstance.proxy) == null ? void 0 : _a.$options.name; if (cmpName && (cmpName.indexOf("Graphics") !== -1 || cmpName.indexOf("Datasource") !== -1 || cmpName === "VcOverlayDynamic" || cmpName === "VcEntity")) { return makeMaterialProperty(val); } const { Material, combine } = Cesium; if (val instanceof Material) { return val; } if (isPlainObject(val) && hasOwn(val, "fabric")) { const f = (obj) => { for (const i in obj) { if (!isArray(obj[i]) && isPlainObject(obj[i])) { f(obj[i]); } else { if (i.toLocaleLowerCase().indexOf("color") !== -1 && !isEmptyObj(obj[i])) { const result = makeColor(obj[i]); obj[i] = combine(result, result, true); } } } }; f(val); return new Material(val); } if (isArray(val) || isString(val)) { const material = Material.fromType("Color"); material.uniforms.color = makeColor(val); return material; } return void 0; } function makeAppearance(val) { var _a; const { Appearance, DebugAppearance, MaterialAppearance, PolylineColorAppearance, EllipsoidSurfaceAppearance, PerInstanceColorAppearance, PolylineMaterialAppearance } = Cesium; if (val instanceof Appearance || val instanceof DebugAppearance || val instanceof MaterialAppearance || val instanceof PolylineColorAppearance || val instanceof EllipsoidSurfaceAppearance || val instanceof PerInstanceColorAppearance || val instanceof PolylineMaterialAppearance) { return val; } if (isPlainObject(val) && hasOwn(val, "type")) { const options = { ...val.options }; if ((_a = val.options) == null ? void 0 : _a.material) { options.material = makeMaterial.call(this, val.options.material); } return new Cesium[val.type]({ ...options }); } return void 0; } function makeRectangle(val, isConstant = false) { const { Rectangle, RectangleGraphics, CallbackProperty } = Cesium; if (val instanceof RectangleGraphics || val instanceof Rectangle || val instanceof CallbackProperty) { return val; } if (isArray(val)) { return Rectangle.fromDegrees(val[0], val[1], val[2], val[3]); } if (isPlainObject(val)) { if (hasOwn(val, "west")) { const value = val; return Rectangle.fromDegrees(value.west, value.south, value.east, value.north); } else if (hasOwn(val, "x")) { const value = val; return new Rectangle(value.x, value.y, value.z, value.w); } } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return void 0; } function makeBoundingRectangle(val, isConstant = false) { const { BoundingRectangle, CallbackProperty } = Cesium; if (val instanceof BoundingRectangle || val instanceof CallbackProperty) { return val; } if (isPlainObject(val) && hasOwn(val, "x")) { const value = val; return new BoundingRectangle(value.x, value.y, value.width, value.height); } if (isArray(val)) { return new BoundingRectangle(val[0], val[1], val[2], val[3]); } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return void 0; } function makePlane(val, isConstant = false) { const { Cartesian3, Plane, PlaneGraphics, CallbackProperty } = Cesium; if (val instanceof PlaneGraphics || val instanceof Plane || val instanceof CallbackProperty) { return val; } if (isPlainObject(val) && hasOwn(val, "normal")) { const value = val; Cartesian3.normalize(makeCartesian3(value.normal), value.normal); return new Plane(value.normal, value.distance); } if (isArray(val)) { const point3D = makeCartesian3(val[0]); const normalizePoint3D = Cartesian3.normalize(point3D, new Cartesian3()); return new Plane(normalizePoint3D, val[1]); } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return void 0; } function makeTranslationRotationScale(val, isConstant = false) { const { TranslationRotationScale, CallbackProperty } = Cesium; if (val instanceof CallbackProperty || val instanceof TranslationRotationScale) { return val; } if (isPlainObject(val) && hasOwn(val, "translation")) { const value = val; return new TranslationRotationScale( makeCartesian3(value.translation), makeQuaternion(value.rotation), makeCartesian3(value.scale) ); } if (isArray(val)) { return new TranslationRotationScale( makeCartesian3(val[0]), makeQuaternion(val[1]), makeCartesian3(val[2]) ); } if (isFunction(val)) { return new CallbackProperty(val, isConstant); } return val; } function makeOptions(val) { var _a; const vcInstance = this; const cmpName = (_a = vcInstance.proxy) == null ? void 0 : _a.$options.name; const result = {}; switch (cmpName) { case "VcDatasourceGeojson": Object.assign(result, val); result && result.markerColor && (result.markerColor = makeColor(result.markerColor)); result && result.stroke && (result.stroke = makeColor(result.stroke)); result && result.fill && (result.fill = makeColor(result.fill)); return result; } return val; } function captureScreenshot(viewer) { const scene = viewer.scene; const promise = new Promise((resolve, reject) => { const removeCallback = viewer.scene.postRender.addEventListener(() => { removeCallback(); try { const cesiumCanvas = viewer.scene.canvas; const canvas = cesiumCanvas; resolve(canvas.toDataURL("image/png")); } catch (e) { reject(e); } }); }); scene.render(viewer.clock.currentTime); return promise; } function makeCameraOptions(camera, ellipsoid) { const { Math: CesiumMath, Rectangle, defaultValue } = Cesium; let destination = void 0; let orientation = {}; if (hasOwn(camera, "position")) { const position = camera.position; destination = makeCartesian3(position, ellipsoid); if (hasOwn(position, "lng") && hasOwn(position, "lat") || isArray(position)) { orientation = { heading: CesiumMath.toRadians(defaultValue(camera.heading, 360)), pitch: CesiumMath.toRadians(defaultValue(camera.pitch, -90)), roll: CesiumMath.toRadians(defaultValue(camera.roll, 0)) }; } else { orientation = { heading: defaultValue(camera.heading, 2 * Math.PI), pitch: defaultValue(camera.pitch, -Math.PI / 2), roll: defaultValue(camera.roll, 0) }; } } else if (hasOwn(camera, "rectangle")) { const rectangle = camera.rectangle; destination = makeRectangle(rectangle); Rectangle.validate(destination); if (hasOwn(rectangle, "west") && hasOwn(rectangle, "south") && hasOwn(rectangle, "east") && hasOwn(rectangle, "north") || isArray(rectangle)) { orientation = { heading: CesiumMath.toRadians(defaultValue(camera.heading, 360)), pitch: CesiumMath.toRadians(defaultValue(camera.pitch, -90)), roll: CesiumMath.toRadians(defaultValue(camera.roll, 0)) }; } else { orientation = { heading: defaultValue(camera.heading, 2 * Math.PI), pitch: defaultValue(camera.pitch, -Math.PI / 2), roll: defaultValue(camera.roll, 0) }; } } return { destination, orientation }; } function setViewerCamera(viewer, camera) { const { destination, orientation } = makeCameraOptions(camera, viewer.scene.globe.ellipsoid); viewer.camera.setView({ destination, orientation }); } function flyToCamera(viewer, cameraOpts, options