function GeoServerContext(opt,geoserver_path){ this.local_wms_path = geoserver_path+"/wuhan/wms" this.local_wmts_path = geoserver_path+"/gwc/service/wmts" this.local_wfs_path = geoserver_path + "/wuhan/ows" this.actions = {} this.clicks = {} this.currentMap = opt.currentMap || window.map this.currentView = opt.currentView || window.view this.projection = opt.projection || window.projection this.wkt = new ol.format.WKT() let that = this this.currentMap.on("click", function(event){ for(let id in that.clicks){ let action = that.clicks[id] if(action && action.click){ action.click(event, action) } } }) } GeoServerContext.prototype = { createAction(key, Action, ext){ if(!this.actions[key]){ this.actions[key] = new Action(this, key, ext) this.actions[key].create() } return this.actions[key] }, stopActions(currentKey){ for(let key in this.actions){ let always = false; if(this.actions[key].obj && this.actions[key].obj.layerData){ always = this.actions[key].obj.layerData["always"] } if(!always && currentKey != key){ this.actions[key].stop() } } }, getInfo(layerName , coordinate, callback, error) { // coordinate = ol.proj.transform([coordinate[0],coordinate[1]],"EPSG:4326","EPSG:4526") console.log(layerName, coordinate) $.ajax({ type : 'POST', url : "/crop/getInfo", data : {layerName: layerName, x : coordinate[0], y : coordinate[1]}, dataType : 'json', success : function(res){ callback(res) },error: function(req){ if(error) error(req) } }); },getBuffer(coordinate,m, callback, error) { // coordinate = ol.proj.transform([coordinate[0],coordinate[1]],"EPSG:4326","EPSG:4526") $.ajax({ type : 'POST', url : "/crop/getBuffer", data : { x : coordinate[0], y : coordinate[1], m:m}, dataType : 'json', success : function(res){ callback(res) },error: function(req){ if(error) error(req) } }); }, //获取图例 getSldStyleSign(styleName){ $.ajax({ type : 'POST', url : "/sld_style/sign", data : {styleName: styleName}, dataType : 'json', success : function(res){ let html = "" let data = JSON.parse(res.msg) for(let item of data){ html += '
' html += '
' html += '
'+item.title+'
' html += '
' } $("#cutline-items").html(html) console.log($("#cutline-items").html()) } }); } } function MyGeoJsonLayer(option){ this.url = option.url; this.zIndex = option.zIndex || 0 this.style = option.style this.source = new ol.source.Vector({ projection: 'EPSG:4326', url: this.url, //GeoJSON的文件路径,用户可以根据需求而改变 format: new ol.format.GeoJSON() }) this.vector = new ol.layer.Vector({ style: this.style, zIndex: this.zIndex, source: this.source }); } MyGeoJsonLayer.prototype = { } function TipLayer(option){ this.features = option.features || []; this.style = option.style this.zIndex = option.zIndex || 0 this.source = new ol.source.Vector({ projection: 'EPSG:4326' }) for(let feature of this.features){ let point = new ol.geom.Point(ol.extent.getCenter(feature.getGeometry().getExtent())) let pointFeature = new ol.Feature({geometry:point}) pointFeature.setId(feature.getId().substring(feature.getId().indexOf(".") + 1)) let keys = feature.getKeys(); for(let key of keys){ if(key === "geometry"){ continue } pointFeature.set(key,feature.get(key)) } this.source.addFeature(pointFeature) } this.vector = new ol.layer.Vector({ style: this.style, zIndex: this.zIndex, source: this.source, maxZoom: 14 }); } String.prototype.format = function(){ let str = this; if(arguments.length == 0){ return str; }else{ Object.keys(arguments).forEach((item,index)=>{ str = str.replace(/\!/,arguments[item]) }) return str } }