geo_server_context.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. function GeoServerContext(opt,geoserver_path){
  2. this.local_wms_path = geoserver_path+"/wuhan/wms"
  3. this.local_wmts_path = geoserver_path+"/gwc/service/wmts"
  4. this.local_wfs_path = geoserver_path + "/wuhan/ows"
  5. this.actions = {}
  6. this.clicks = {}
  7. this.currentMap = opt.currentMap || window.map
  8. this.currentView = opt.currentView || window.view
  9. this.projection = opt.projection || window.projection
  10. this.wkt = new ol.format.WKT()
  11. let that = this
  12. this.currentMap.on("click", function(event){
  13. for(let id in that.clicks){
  14. let action = that.clicks[id]
  15. if(action && action.click){
  16. action.click(event, action)
  17. }
  18. }
  19. })
  20. }
  21. GeoServerContext.prototype = {
  22. createAction(key, Action, ext){
  23. if(!this.actions[key]){
  24. this.actions[key] = new Action(this, key, ext)
  25. this.actions[key].create()
  26. }
  27. return this.actions[key]
  28. },
  29. stopActions(){
  30. for(let key in this.actions){
  31. if(!this.actions[key].obj.layerData["always"]){
  32. this.actions[key].stop()
  33. }
  34. }
  35. },
  36. getInfo(layerName , coordinate, callback, error) {
  37. // coordinate = ol.proj.transform([coordinate[0],coordinate[1]],"EPSG:4326","EPSG:4526")
  38. console.log(layerName, coordinate)
  39. $.ajax({
  40. type : 'POST',
  41. url : "/postGisInfo/getInfo",
  42. data : {layerName: layerName, x : coordinate[0], y : coordinate[1]},
  43. dataType : 'json',
  44. success : function(res){
  45. callback(res)
  46. },error: function(req){
  47. if(error)
  48. error(req)
  49. }
  50. });
  51. },
  52. //获取图例
  53. getSldStyleSign(styleName){
  54. $.ajax({
  55. type : 'POST',
  56. url : "/sld_style/sign",
  57. data : {styleName: styleName},
  58. dataType : 'json',
  59. success : function(res){
  60. let html = ""
  61. let data = JSON.parse(res.msg)
  62. for(let item of data){
  63. html += '<div class="cutline-item">'
  64. html += '<div class="item-color" style="background-color: '+item.fill+'"></div>'
  65. html += '<div class="item-name">'+item.title+'</div>'
  66. html += '</div>'
  67. }
  68. $("#cutline-items").html(html)
  69. console.log($("#cutline-items").html())
  70. }
  71. });
  72. }
  73. }
  74. function MyGeoJsonLayer(option){
  75. this.url = option.url;
  76. this.zIndex = option.zIndex || 0
  77. this.style = option.style
  78. this.source = new ol.source.Vector({
  79. projection: 'EPSG:4326',
  80. url: this.url, //GeoJSON的文件路径,用户可以根据需求而改变
  81. format: new ol.format.GeoJSON()
  82. })
  83. this.vector = new ol.layer.Vector({
  84. style: this.style,
  85. zIndex: this.zIndex,
  86. source: this.source
  87. });
  88. }
  89. MyGeoJsonLayer.prototype = {
  90. }
  91. function TipLayer(option){
  92. this.features = option.features || [];
  93. this.style = option.style
  94. this.zIndex = option.zIndex || 0
  95. this.source = new ol.source.Vector({
  96. projection: 'EPSG:4326'
  97. })
  98. for(let feature of this.features){
  99. let point = new ol.geom.Point(ol.extent.getCenter(feature.getGeometry().getExtent()))
  100. let pointFeature = new ol.Feature({geometry:point})
  101. let keys = feature.getKeys();
  102. for(let key of keys){
  103. if(key === "geometry"){
  104. continue
  105. }
  106. pointFeature.set(key,feature.get(key))
  107. }
  108. this.source.addFeature(pointFeature)
  109. console.log(pointFeature.getKeys())
  110. }
  111. this.vector = new ol.layer.Vector({
  112. style: this.style,
  113. zIndex: this.zIndex,
  114. source: this.source,
  115. maxZoom: 14
  116. });
  117. }