* @private * @function WebMap.prototype.createDataflowLayer * @description 创建数据流图层 * @param {Object} layerInfo- 图层信息 * @param {number} layerIndex - 图层的zindex * @returns {ol.layer.Vector} 数据流图层
(layerInfo, layerIndex)
| 3870 | * @returns {ol.layer.Vector} 数据流图层 |
| 3871 | */ |
| 3872 | async createDataflowLayer(layerInfo, layerIndex) { |
| 3873 | let layerStyle = layerInfo.pointStyle, |
| 3874 | style; |
| 3875 | //获取样式 |
| 3876 | style = await StyleUtils.getOpenlayersStyle(layerStyle, layerInfo.featureType); |
| 3877 | |
| 3878 | let source = new Vector({ |
| 3879 | wrapX: false |
| 3880 | }), |
| 3881 | labelLayer, |
| 3882 | labelSource, |
| 3883 | pathLayer, |
| 3884 | pathSource; |
| 3885 | let layer = new olLayer.Vector({ |
| 3886 | styleOL: style, |
| 3887 | source: source |
| 3888 | }); |
| 3889 | if (layerInfo.labelStyle && layerInfo.visible) { |
| 3890 | //有标签图层 |
| 3891 | labelLayer = this.addLabelLayer(layerInfo); |
| 3892 | //和编辑页面保持一致 |
| 3893 | labelLayer.setZIndex(1000); |
| 3894 | labelSource = labelLayer.getSource(); |
| 3895 | } |
| 3896 | const { visibleScale } = layerInfo; |
| 3897 | if (layerInfo.lineStyle && layerInfo.visible) { |
| 3898 | pathLayer = await this.createVectorLayer({ style: layerInfo.lineStyle, featureType: 'LINE' }); |
| 3899 | pathSource = pathLayer.getSource(); |
| 3900 | pathLayer.setZIndex(layerIndex); |
| 3901 | this.map.addLayer(pathLayer); |
| 3902 | visibleScale && this.setVisibleScales(pathLayer, visibleScale); |
| 3903 | // 挂载到layerInfo上,便于删除 |
| 3904 | layerInfo.pathLayer = pathLayer; |
| 3905 | } |
| 3906 | let featureCache = {}, |
| 3907 | labelFeatureCache = {}, |
| 3908 | pathFeatureCache = {}, |
| 3909 | that = this; |
| 3910 | this.createDataflowService( |
| 3911 | layerInfo, |
| 3912 | (function (featureCache, labelFeatureCache, pathFeatureCache) { |
| 3913 | return function (feature) { |
| 3914 | that.events.triggerEvent('updateDataflowFeature', { |
| 3915 | feature: feature, |
| 3916 | identifyField: layerInfo.identifyField, |
| 3917 | layerID: layerInfo.layerID |
| 3918 | }); |
| 3919 | if (layerInfo.filterCondition) { |
| 3920 | //过滤条件 |
| 3921 | const condition = that.parseFilterCondition(layerInfo.filterCondition); |
| 3922 | const properties = feature.get('attributes'); |
| 3923 | const conditions = parseCondition(condition, Object.keys(properties)); |
| 3924 | const filterFeature = parseConditionFeature(properties); |
| 3925 | const sql = 'select * from json where (' + conditions + ')'; |
| 3926 | let filterResult = window.jsonsql.query(sql, { attributes: filterFeature }); |
| 3927 | if (filterResult && filterResult.length > 0) { |
| 3928 | that.addDataflowFeature(feature, layerInfo.identifyField, { |
| 3929 | dataflowSource: source, |
no test coverage detected