city.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. function CityAction(context, id){
  2. this.context = context
  3. this.id = id
  4. this.selected = {}
  5. this.vectorLayer = null
  6. this.obj = new City({
  7. url : context.local_wfs_path
  8. })
  9. }
  10. CityAction.prototype = {
  11. clickLock:false,
  12. startStatus : false,
  13. createStatus : false,
  14. create(){
  15. this.obj.getTileLayer()
  16. this.initInteraction()
  17. this.createStatus = true;
  18. },
  19. start(){
  20. if(this.startStatus){
  21. console.log("startStatus is true")
  22. return
  23. }
  24. this.context.clicks[this.id] = this
  25. this.context.currentMap.addLayer(this.obj.layerData.layer)
  26. this.startStatus = true;
  27. },
  28. stop(){
  29. if(!this.startStatus){
  30. console.log("startStatus is false")
  31. return
  32. }
  33. this.context.currentMap.removeLayer(this.obj.layerData.layer)
  34. console.log("vectorLayer cleared")
  35. this.context.clicks[this.id] = null
  36. console.log("remove click")
  37. this.startStatus = false;
  38. },
  39. find(code, success){
  40. let level;
  41. let endZeroCount = this.endZeroCount(code)
  42. switch (endZeroCount){
  43. case 2:
  44. case 3:
  45. level = 1
  46. break;
  47. case 4:
  48. level = 0
  49. break;
  50. default:
  51. level = 2
  52. }
  53. if(level == 0)
  54. return
  55. $.ajax({
  56. type : 'POST',
  57. url : "/city/findJson",
  58. data : {level: level, code: code},
  59. dataType : 'json',
  60. success : success
  61. });
  62. },
  63. fit(code){
  64. let that = this
  65. this.find(code, function(res){
  66. if(res.code == 0)
  67. that.context.currentView.fit(new ol.format.WKT().readGeometry(res.data).getExtent(),{duration: 1000})
  68. })
  69. },
  70. endZeroCount(code){
  71. let count = 0;
  72. while(code % 10 == 0 && code != 0){
  73. code = code / 10;
  74. count++;
  75. }
  76. return count;
  77. },
  78. clearEndZero(code){
  79. return code.replace(/(0+)\b/gi,"")
  80. },
  81. initInteraction(){
  82. let move = new ol.interaction.Select({
  83. condition: ol.events.condition.pointerMove,
  84. layers:[this.obj.layerData.layer],
  85. style: this.obj.selectedStyle()
  86. })
  87. let select = new ol.interaction.Select({
  88. condition: ol.events.condition.singleClick,
  89. layers:[this.obj.layerData.layer],
  90. style: this.obj.selectedStyle()
  91. })
  92. this.context.currentMap.addInteraction(move)
  93. this.context.currentMap.addInteraction(select)
  94. select.on("select",function(f,g){
  95. console.log(f.selected[0])
  96. window.location = "/qyz/zzjg"
  97. })
  98. }
  99. }
  100. function City(opt){
  101. this.name = "Qyz"
  102. this.wmsData = {
  103. layers:"wuhan:qy-z",
  104. url: opt.url,
  105. }
  106. this.layerData = {
  107. layer : null,
  108. source : null,
  109. select : null,
  110. always : false
  111. }
  112. }
  113. City.prototype = {
  114. getTileLayer(){
  115. let url = this.wmsData.url +
  116. "?service=WFS&version=1.0.0&request=GetFeature&typeName="+this.wmsData.layers+"&maxFeatures=1000&outputFormat=application/json"
  117. url+="&Filter=(<Filter>" +
  118. "<ogc:PropertyIsLike wildCard=\"*\" singleChar=\".\" escape=\"!\" xmlns:ogc=\"http://www.opengis.net/ogc\" ><ogc:PropertyName>pac</ogc:PropertyName>" +
  119. "<ogc:Literal>441821*</ogc:Literal></ogc:PropertyIsLike></Filter>)"
  120. console.log(url)
  121. let myGeoJsonLayer = new MyGeoJsonLayer({url: url, zIndex:2, style: this.style()})
  122. this.layerData.layer = myGeoJsonLayer.vector;
  123. },style(){
  124. return new ol.style.Style({
  125. stroke: new ol.style.Stroke({
  126. color: 'rgb(20,200,44)',
  127. width: 1,
  128. }),
  129. fill: new ol.style.Fill({
  130. color: 'rgba(200,20,20,0.0)',
  131. })
  132. });
  133. },selectedStyle(){
  134. return new ol.style.Style({
  135. stroke: new ol.style.Stroke({
  136. color: 'rgba(200,20,20)',
  137. width: 1,
  138. }),
  139. fill: new ol.style.Fill({
  140. color: 'rgba(200,20,20,0.1)',
  141. })
  142. });
  143. }
  144. }