* @private * @function WebMap.prototype.geojsonToFeature * @description geojson 转换为 feature * @param {Object} layerInfo - 图层信息 * @returns {Array} ol.feature的数组集合
(geojson, layerInfo)
| 2783 | * @returns {Array} ol.feature的数组集合 |
| 2784 | */ |
| 2785 | geojsonToFeature(geojson, layerInfo) { |
| 2786 | let allFeatures = geojson.features, |
| 2787 | features = []; |
| 2788 | for (let i = 0, len = allFeatures.length; i < len; i++) { |
| 2789 | //转换前删除properties,这样转换后属性不会重复存储 |
| 2790 | let featureAttr = allFeatures[i].properties || {}; |
| 2791 | delete allFeatures[i].properties; |
| 2792 | let feature = transformTools.readFeature(allFeatures[i], { |
| 2793 | dataProjection: layerInfo.projection || 'EPSG:4326', |
| 2794 | featureProjection: this.baseProjection || 'ESPG:4326' |
| 2795 | }); |
| 2796 | //geojson格式的feature属性没有坐标系字段,为了统一,再次加上 |
| 2797 | let coordinate = feature.getGeometry().getCoordinates(); |
| 2798 | if (allFeatures[i].geometry.type === 'Point') { |
| 2799 | // 标注图层 还没有属性值时候不加 |
| 2800 | if (allFeatures[i].properties) { |
| 2801 | |
| 2802 | allFeatures[i].properties.lon = coordinate[0]; |
| 2803 | allFeatures[i].properties.lat = coordinate[1]; |
| 2804 | } |
| 2805 | } |
| 2806 | |
| 2807 | // 标注图层特殊处理 |
| 2808 | let isMarker = false; |
| 2809 | let attributes; |
| 2810 | let useStyle; |
| 2811 | if (allFeatures[i].dv_v5_markerInfo) { |
| 2812 | //因为优化代码之前,属性字段都存储在propertise上,markerInfo没有 |
| 2813 | attributes = Object.assign({}, allFeatures[i].dv_v5_markerInfo, featureAttr); |
| 2814 | if (attributes.lon) { |
| 2815 | //标注图层不需要 |
| 2816 | delete attributes.lon; |
| 2817 | delete attributes.lat; |
| 2818 | } |
| 2819 | } |
| 2820 | if (allFeatures[i].dv_v5_markerStyle) { |
| 2821 | useStyle = allFeatures[i].dv_v5_markerStyle; |
| 2822 | isMarker = true; |
| 2823 | } |
| 2824 | let properties; |
| 2825 | if (isMarker) { |
| 2826 | properties = Object.assign( |
| 2827 | {}, |
| 2828 | { |
| 2829 | attributes |
| 2830 | }, |
| 2831 | { |
| 2832 | useStyle |
| 2833 | } |
| 2834 | ); |
| 2835 | //feature上添加图层的id,为了对应图层 |
| 2836 | feature.layerId = layerInfo.timeId; |
| 2837 | } else if (layerInfo.featureStyles) { |
| 2838 | //V4 版本标注图层处理 |
| 2839 | let style = JSON.parse(layerInfo.featureStyles[i].style); |
| 2840 | let attr = featureAttr; |
| 2841 | let imgUrl; |
| 2842 | if (attr._smiportal_imgLinkUrl.indexOf('http://') > -1 || attr._smiportal_imgLinkUrl.indexOf('https://') > -1) { |
no test coverage detected