export default { cartesianToLnglat:(cartesian)=>{ // //笛卡尔空间坐标转WGS84弧度. // const ellipsoid84 = Cesium.Ellipsoid.wgs84; // const cartographicPosition = ellipsoid84.cartesianToCartographic(cartesian); const cartographicPosition = Cesium.Cartographic.fromCartesian(cartesian); return [ Cesium.Math.toDegrees(cartographicPosition.longitude), Cesium.Math.toDegrees(cartographicPosition.latitude), ] }, getCenterByPositions:(cartesianArr)=>{ let points = []; cartesianArr.forEach(cartesianCoor=>{ let cartesian = new Cesium.Cartesian3(cartesianCoor.x, cartesianCoor.y, cartesianCoor.z) points.push(cUtil.cartesianToLnglat(cartesian)) }) var features = turf.points(points); let center = turf.center(features); return center.geometry.coordinates; }, /** * 全局唯一标识符(GUID,Globally Unique Identifier)也称作 UUID(Universally Unique IDentifier) 。 * 可以指定长度 * @param len * @param radix * @returns {string} */ uuid:function(len, radix) { var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); var uuid = [], i; radix = radix || chars.length; if (len) { // Compact form for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix]; } else { // rfc4122, version 4 form var r; // rfc4122 requires these characters uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[14] = '4'; // Fill in random data. At i==19 set the high bits of clock sequence as // per rfc4122, sec. 4.1.5 for (i = 0; i < 36; i++) { if (!uuid[i]) { r = 0 | Math.random() * 16; uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; } } } return uuid.join(''); }, focus:(data,angle=-45,h=200)=>{ const length = (Math.PI * Cesium.Ellipsoid.WGS84.minimumRadius) / 180; let dist = h/Math.tan( Math.abs(angle) * Math.PI/180)/length; viewer.camera.flyTo({ destination : Cesium.Cartesian3.fromDegrees(data.lng, data.lat-dist, 200.0), orientation: { heading: 0.0, pitch: Cesium.Math.toRadians(angle), roll: 0.0, }, }); }, } // 对Date的扩展,将 Date 转化为指定格式的String // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }