CiecleScan_20201022170716.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. var Cesium = require("cesium/Cesium");
  2. export default
  3. function addCircleWave(viewer,msgarr,color) {
  4. console.log(msgarr)
  5. viewer.entities.add({
  6. id:msgarr.userid+'',
  7. name: msgarr.username,
  8. position: Cesium.Cartesian3.fromDegrees(msgarr.lng ,msgarr.lat, 0 ),
  9. ellipse: {
  10. height: 0,
  11. semiMinorAxis: 15,
  12. semiMajorAxis: 15,
  13. material: new Cesium.CircleWaveMaterialProperty({
  14. duration: 2e3,
  15. gradient: 0,
  16. color: color,
  17. count: 3
  18. })
  19. },
  20. point: {
  21. pixelSize: 10,
  22. color: Cesium.Color.YELLOW,
  23. },
  24. label: {
  25. text: msgarr.username,
  26. font: "14pt monospace",
  27. style: Cesium.LabelStyle.FILL_AND_OUTLINE,
  28. outlineWidth: 2,
  29. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  30. pixelOffset: new Cesium.Cartesian2(0, -9),
  31. },
  32. });
  33. }
  34. export class CircleWaveMaterialProperty {
  35. constructor(options) {
  36. options = Cesium.defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT);
  37. this._definitionChanged = new Cesium.Event();
  38. this._color = undefined;
  39. this._colorSubscription = undefined;
  40. this.color = options.color;
  41. this.duration = Cesium.defaultValue(options.duration, 1e3);
  42. this.count = Cesium.defaultValue(options.count, 2);
  43. if (this.count <= 0) this.count = 1;
  44. this.gradient = Cesium.defaultValue(options.gradient, 0.1);
  45. if (this.gradient < 0) this.gradient = 0;
  46. else if (this.gradient > 1) this.gradient = 1;
  47. this._time = performance.now();
  48. }
  49. }
  50. Object.defineProperties(CircleWaveMaterialProperty.prototype, {
  51. isConstant: {
  52. get: function() {
  53. return false;
  54. }
  55. },
  56. definitionChanged: {
  57. get: function() {
  58. return this._definitionChanged;
  59. }
  60. },
  61. color: Cesium.createPropertyDescriptor('color')
  62. });
  63. CircleWaveMaterialProperty.prototype.getType = function(time) {
  64. return Cesium.Material.CircleWaveMaterialType;
  65. }
  66. CircleWaveMaterialProperty.prototype.getValue = function(time, result) {
  67. if (!Cesium.defined(result)) {
  68. result = {};
  69. }
  70. result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
  71. result.time = (performance.now() - this._time) / this.duration;
  72. result.count = this.count;
  73. result.gradient = 1 + 10 * (1 - this.gradient);
  74. return result;
  75. }
  76. CircleWaveMaterialProperty.prototype.equals = function(other) {
  77. return this === other ||
  78. (other instanceof CircleWaveMaterialProperty &&
  79. Cesium.Property.equals(this._color, other._color))
  80. }
  81. Cesium.Material.CircleWaveMaterialType = 'CircleWaveMaterial';
  82. Cesium.Material.PolylineTrailSource =
  83. // `czm_material czm_getMaterial(czm_materialInput materialInput)\n
  84. // {\n
  85. // czm_material material = czm_getDefaultMaterial(materialInput);\n
  86. // material.diffuse = 1.5 * color.rgb;\n
  87. // vec2 st = materialInput.st;\n
  88. // vec3 str = materialInput.str;\n
  89. // float dis = distance(st, vec2(0.5, 0.5));\n
  90. // float per = fract(time);\n
  91. // if (abs(str.z) > 0.001) {\n
  92. // discard;\n
  93. // }\n
  94. // if (dis > 0.5) { \n
  95. // discard; \n
  96. // } else { \n
  97. // float perDis = 0.5 / count;\n
  98. // float disNum; \n
  99. // float bl = .0; \n
  100. // for (int i = 0; i <= 999; i++) { \n
  101. // if (float(i) <= count) { \n
  102. // disNum = perDis *float(i) - dis + per / count; \n
  103. // if (disNum > 0.0) { \n
  104. // if (disNum < perDis) { \n
  105. // bl = 1.0 - disNum / perDis;\n
  106. // }\n
  107. // else if(disNum - perDis < perDis) { \n
  108. // bl = 1.0 - abs(1.0 - disNum / perDis); \n
  109. // } \n
  110. // material.alpha = pow(bl, gradient); \n
  111. // } \n
  112. // } \n
  113. // } \n
  114. // } \n
  115. // return material; \n
  116. // } \n`;
  117. "czm_material czm_getMaterial(czm_materialInput materialInput)\n" +
  118. "{\n" +
  119. "czm_material material = czm_getDefaultMaterial(materialInput);\n" +
  120. "material.diffuse = 1.5 * color.rgb;\n" +
  121. "vec2 st = materialInput.st;\n" +
  122. "float dis = distance(st, vec2(0.5, 0.5));\n" +
  123. "float per = fract(time);\n" +
  124. "if(dis > per * 0.5){\n" +
  125. "material.alpha = 0.0;\n"+
  126. "discard;\n" +
  127. "}else {\n" +
  128. "material.alpha = color.a * dis / per / 1.0;\n" +
  129. "}\n" +
  130. "return material;\n" +
  131. "}";
  132. Cesium.Material._materialCache.addMaterial(Cesium.Material.CircleWaveMaterialType, {
  133. fabric: {
  134. type: Cesium.Material.CircleWaveMaterialType,
  135. uniforms: {
  136. color: new Cesium.Color(1.0, 0.0, 0.0, 1.0),
  137. time: 1,
  138. count: 1,
  139. gradient: 0.1
  140. },
  141. source: Cesium.Material.PolylineTrailSource
  142. },
  143. translucent: function(material) {
  144. return !0;
  145. }
  146. });
  147. Cesium.CircleWaveMaterialProperty = CircleWaveMaterialProperty;