vectorStyle.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import Style from 'ol/style/Style.js';
  2. import Fill from 'ol/style/Fill.js';
  3. import Text from 'ol/style/Text.js';
  4. import Stroke from 'ol/style/Stroke.js';
  5. import Icon from 'ol/style/Icon.js';
  6. import Circle from "ol/style/Circle";
  7. function cityLand(gridcode) {
  8. let fillColor = ["#6E7F8580","#7B9CFB80","#979B4980","#E9920980","#182F1380","#30791380","#0D53AF80"];
  9. return new Style({
  10. fill: new Fill({
  11. color: fillColor[gridcode],
  12. })
  13. });
  14. }
  15. function pointStyle(f){
  16. let style = new Style({
  17. text: new Text({
  18. text:f.getId() ? f.getId() : f.get("id"),
  19. stroke: new Stroke({
  20. color: 'rgba(239,236,236)',
  21. width: 1,
  22. }),
  23. fill: new Fill({
  24. color: 'rgba(239,236,236)',
  25. }),
  26. font:"14px sans-serif"
  27. }),
  28. image: new Icon({
  29. src:"../status_"+f.get("status")+".png",
  30. scale:0.3,
  31. anchor:[0.5,1],
  32. })
  33. });
  34. return style
  35. }
  36. function areaStyle(f){
  37. let style = new Style({
  38. fill: new Fill({
  39. color: f.get("color")+"10"
  40. }),
  41. stroke: new Stroke({
  42. color: f.get("color"),
  43. width: 1,
  44. }),
  45. });
  46. return style;
  47. }
  48. let selectStyle = (f)=>{
  49. if(f.get("nodeType") === "area"){
  50. return areaStyle(f)
  51. }
  52. if(f.get("nodeType") === "town"){
  53. return cropStyle(f)
  54. }
  55. let color = f.get("color");
  56. let radius = 10;
  57. if(!color || color == ""){
  58. color = "green"
  59. radius = 5;
  60. }
  61. let style = new Style({
  62. image: new Circle({
  63. radius: radius, // 半径
  64. stroke: new Stroke({ // 边界样式
  65. color: 'red', // 边界颜色
  66. width: 3 // 边界宽度
  67. }),
  68. fill: new Fill({ // 填充样式
  69. color: color // 填充颜色
  70. })
  71. })
  72. });
  73. return style
  74. }
  75. function cropStyle(f){
  76. const fill = new Fill({
  77. color: 'rgba(255,255,255,0.1)',
  78. });
  79. return new Style({
  80. fill:fill
  81. });
  82. }
  83. function selectedCropStyle(f){
  84. if(f.get("isPoint")){
  85. return pointStyle(f)
  86. }
  87. const stroke = new Stroke({
  88. color: 'rgb(10,241,23)',
  89. width: 2
  90. });
  91. return new Style({
  92. stroke:stroke
  93. });
  94. };
  95. function fitPointStyle(f){
  96. if(f.get("nodeType") == "fitPoint"){
  97. let color = "#ffffff"
  98. let radius = 2;
  99. if(f.get("sort") == 0){
  100. color = "yellow";
  101. radius = "6"
  102. }
  103. let style = new Style({
  104. image: new Circle({
  105. radius: radius, // 半径
  106. fill: new Fill({ // 填充样式
  107. color: color// 填充颜色
  108. })
  109. })
  110. });
  111. return style
  112. }else{
  113. let style = new Style({
  114. fill: new Fill({ // 填充样式
  115. color: '#23DB9E'// 填充颜色
  116. }),
  117. stroke: new Stroke({
  118. color: "#23DB9E",
  119. width: 2,
  120. }),
  121. });
  122. return style
  123. }
  124. }
  125. function numberPointStyle(f){
  126. if(f.get("nodeType") == "fitPoint") {
  127. let style = new Style({
  128. text: new Text({
  129. offsetY:-10,
  130. offsetX:-10,
  131. text: f.get("sort")+"",
  132. stroke: new Stroke({
  133. color: 'red',
  134. width: 1,
  135. }),
  136. fill: new Fill({
  137. color: 'red',
  138. }),
  139. font: "12px sans-serif"
  140. })
  141. });
  142. return style
  143. }
  144. }
  145. export {
  146. cityLand,
  147. selectedCropStyle,
  148. cropStyle,
  149. pointStyle,
  150. selectStyle,
  151. fitPointStyle,
  152. numberPointStyle,
  153. }