企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ //请勿修改此处命名参数 vsPluginComponentModule.factory('$vcPlugin_extwidgets_openlayers4_map', ['$vsPluginRegister', '$timeout', function ($vsPluginRegister, $timeout) { var factory = { //配置面板中显示[数据]配置 showDataCategory: true, //配置面板中显示[边框]配置 showBorderCategory: true, //配置面板中显示[基本]配置 showBasicCategory: true, //配置面板中显示[浮动]配置 showFixedCategory: true, //配置面板中显示[事件]配置 showEventCategory: true, //配置面板中显示[标题]配置 showTitleCategory: true, /* 控件的初始化 */ init: function(scope, element, component, $compile){ scope.element = element; scope.component = component; //控件的图形维度数量 scope.component.config.chartDimensionCount = 1; //当控件尺寸改变时,改变echarts的尺寸 component.context.resize = function(){ $timeout(function(){ // console.log('234243') }, 100); } }, /* * 构建数据描述,此方法中对控件的数据进行处理 */ buildDataDescription: function(dataDescription, scope, element, component, $compile){ //接收控件刷新数据的事件 scope.$on(event_refreshComponentData, function(target, param){ //如果刷新数据事件的发出者是当前控件,不处理本次通知 if(param.component != null && scope.component.id === param.component.id){ return; } scope.queryComponentData(param, { onSuccess: function(){ refreshChartView(scope, element, component, $compile); } }); }); }, /* * 构建图形描述,此方法中定义控件的配置面板 */ buildChartDescription: function(scope, element, component, $compile){ scope.component = component; //控件需要的HTML var html = []; html.push('<div id="mapContainer" style="width:100%;height:100%;" class="map" ondragover="DragHandler.allowDrop(event)">'); var el = $compile(html.join(""))( scope ); element.append(el); /* * 构建[设置]配置面板 */ buildSettingDescription(scope, element, component, $compile); /* * TODO: 可构建更多配置面板 * 例如:buildOtherDescription(scope, element, component, $compile); */ } }; var buildSettingDescription = function(scope, element, component, $compile){ scope.element = element; scope.component = component; scope.calculateBackgroundSize = function (i) { return element.width() > element.height() ? "auto 100%" : "100% auto" }; var html = []; html.push('<div id="mapContainer" class="map" ondragover="DragHandler.allowDrop(event)">'); var h = $compile(html.join(""))(scope); element.html(h); //轨迹line layer scope.component.context.vsource = new ol.source.Vector({ type: 'LineString', features: [] }); scope.component.context.linelayers = new ol.layer.Vector({ source: scope.component.context.vsource, style: new ol.style.Style({ fill: new ol.style.Fill({ color: '#66cc00' }), stroke: new ol.style.Stroke({ color: '#66cc00', width: 4 }) }) }); //地图基础参数 scope.component.context.center = [116.403963,39.915125]; scope.component.context.source = new ol.source.Vector({ wrapX: false }); scope.component.context.projection = new ol.proj.Projection({ code: 'EPSG:4326', units: 'degrees', axisOrientation: 'neu' }); scope.component.context.view = new ol.View({ projection: scope.component.context.projection, center: scope.component.context.center, zoom: 16 }); scope.component.context.layers = [new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'http://webrd03.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=8' }), }),scope.component.context.linelayers]; //样式,供上述代码调用 scope.component.context.iconStyle = new ol.style.Style({ image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({ anchor: [0.5, 0.8], anchorXUnits: 'fraction', anchorYUnits: 'pi/xels', opacity: 0.75, src: 'http://webapi.amap.com/theme/v1.3/markersn/mark_b.png' })) }); scope.component.context.startStyle = new ol.style.Style({ image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({ anchor: [0.5, 0.8], opacity: 0.8, src: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png', // anchorXUnits: 'fraction', // anchorYUnits: 'pixels', // opacity: 0.75, })) }); scope.component.context.endStyle = new ol.style.Style({ image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({ src: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png', anchor: [0.5, 0.8], })) }); // 实例化 scope.component.context.map = new ol.Map({ logo: false, target: document.getElementById('mapContainer'), layers: scope.component.context.layers, view: scope.component.context.view }); } //刷新控件渲染 var refreshChartView = function(scope, element, component, $compile){ // 对象数据 var map // var k = component.config; var k = component.context; var data = component.context.data; // console.log(data) var lineArr = new Array(); var dimensions = component.config.datasourceConfig.dimensions; var measures = component.config.datasourceConfig.measures; if (data == null) { return } // console.log(data) var measureIdx = 0; if (component.config.receiveMeasureLink != null && component.config.receiveMeasureLink === true) { var newMeasures = scope.getSelectedLinkMeasure(component, component.config.datasourceConfig.measures); for (var i = 0; i < measures.length; i++) { if (newMeasures[i] != null) { measureIdx = i; break } } } var chartData = []; var chartDataMap = []; for (var i = 0; i < data.length; i++) { var dimValue = data[i][dimensions[dimensions.length - 1].name]; if (VSUtils.isEmpty(dimValue)) { continue } chartData.push([dimValue,data[i][measures[measureIdx].name] == null ? 0 : data[i][measures[measureIdx].name]]); chartDataMap.push(dimValue) } if (chartData.length == 0) { chartData = [""]; chartDataMap = [""] } // console.log(chartData) for(var i = 0;i<chartData.length;i++){ // console.log(parseFloat(chartData[i][0].split(',')[0])) // console.log(parseFloat(chartData[i][0].split(',')[1])) lineArr.push([parseFloat(chartData[i][0].split(',')[1]), parseFloat(chartData[i][0].split(',')[0])]); } // console.log(lineArr) // 上来清空画的路线 // console.log(k) k.linelayers.getSource().clear(true); // 调用画线函数 // console.log(lineArr) AddLayer(lineArr); // 画线方法 function AddLayer() { try { k.lineFeature = new ol.Feature({//路线 geometry: new ol.geom.LineString(lineArr), }); k.linelayers.getSource().addFeature(k.lineFeature); k.startFeature = new ol.Feature({//起点 geometry: new ol.geom.Point(lineArr[0]), population: 4000, rainfall: 500 }); k.startFeature.setStyle(k.startStyle); k.linelayers.getSource().addFeature(k.startFeature); k.endFeature = new ol.Feature({//终点 geometry: new ol.geom.Point(lineArr[lineArr.length-1]), population: 4000, rainfall: 500 }); k.endFeature.setStyle(k.endStyle); k.linelayers.getSource().addFeature(k.endFeature); k.extent = k.linelayers.getSource().getExtent();//合适比例缩放居中 k.view.fit(k.extent,undefined); // map.getSize() } catch(e){ console.log(e); } } //接收控件刷新数据的事件 scope.$on(event_refreshComponentData, function(target, param){ scope.queryComponentData(param, { onSuccess: function(){ refreshChartView(scope, element, component, $compile); } }); }); }; var internalFindKvValue = function(component, value){ if (component.config.kvKeys != null) { for (var v in component.config.kvKeys) { if (component.config.kvKeys[v] === value) { return component.config.kvValues[v] } } } return value } //请勿修改此处命名参数 $vsPluginRegister.register("extwidgets", "openlayers4_map", factory); }]); ~~~