CiecleScan.js 6.7 KB

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