123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- 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 += '<div class="cutline-item">'
- html += '<div class="item-color" style="background-color: '+item.fill+'"></div>'
- html += '<div class="item-name">'+item.title+'</div>'
- html += '</div>'
- }
- $("#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
- }
- }
|