* @private * @function WebMap.prototype.excelData2Feature * @description 将csv和xls文件内容转换成ol.feature * @param {Object} content - 文件内容 * @param {Object} layerInfo - 图层信息 * @returns {Array} ol.feature的数组集合
(content, layerInfo)
| 2570 | * @returns {Array} ol.feature的数组集合 |
| 2571 | */ |
| 2572 | async excelData2Feature(content, layerInfo) { |
| 2573 | let rows = content.rows, |
| 2574 | colTitles = content.colTitles; |
| 2575 | // 解决V2恢复的数据中含有空格 |
| 2576 | for (let i in colTitles) { |
| 2577 | if (Util.isString(colTitles[i])) { |
| 2578 | colTitles[i] = Util.trim(colTitles[i]); |
| 2579 | } |
| 2580 | } |
| 2581 | let fileCode = layerInfo.projection, |
| 2582 | dataSource = layerInfo.dataSource, |
| 2583 | baseLayerEpsgCode = this.baseProjection, |
| 2584 | features = [], |
| 2585 | xField = Util.trim((layerInfo.xyField && layerInfo.xyField.xField) || (layerInfo.from && layerInfo.from.xField)), |
| 2586 | yField = Util.trim((layerInfo.xyField && layerInfo.xyField.yField) || (layerInfo.from && layerInfo.from.yField)), |
| 2587 | xIdx = colTitles.indexOf(xField), |
| 2588 | yIdx = colTitles.indexOf(yField); |
| 2589 | |
| 2590 | // todo 优化 暂时这样处理 |
| 2591 | if (layerInfo.layerType === 'MIGRATION') { |
| 2592 | try { |
| 2593 | if (dataSource.type === 'PORTAL_DATA') { |
| 2594 | const requestUrl = `${this.server}web/datas/${dataSource.serverId}.json`; |
| 2595 | const { dataMetaInfo } = await FetchRequest.get(requestUrl, null, { |
| 2596 | withCredentials: this.isCredentail(requestUrl) |
| 2597 | }).then((res) => res.json()); |
| 2598 | // eslint-disable-next-line require-atomic-updates |
| 2599 | layerInfo.xyField = { |
| 2600 | xField: dataMetaInfo.xField, |
| 2601 | yField: dataMetaInfo.yField |
| 2602 | }; |
| 2603 | if (!dataMetaInfo.xIndex) { |
| 2604 | xIdx = colTitles.indexOf(dataMetaInfo.xField); |
| 2605 | yIdx = colTitles.indexOf(dataMetaInfo.yField); |
| 2606 | } else { |
| 2607 | xIdx = dataMetaInfo.xIndex; |
| 2608 | yIdx = dataMetaInfo.yIndex; |
| 2609 | } |
| 2610 | } else if (dataSource.type === 'SAMPLE_DATA') { |
| 2611 | // 示例数据从本地拿xyField |
| 2612 | const sampleData = SampleDataInfo.find((item) => item.id === dataSource.name) || {}; |
| 2613 | xField = sampleData.xField; |
| 2614 | yField = sampleData.yField; |
| 2615 | layerInfo.xyField = { |
| 2616 | xField, |
| 2617 | yField |
| 2618 | }; |
| 2619 | xIdx = colTitles.findIndex((item) => item === xField); |
| 2620 | yIdx = colTitles.findIndex((item) => item === yField); |
| 2621 | } |
| 2622 | } catch (error) { |
| 2623 | console.error(error); |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | for (let i = 0, len = rows.length; i < len; i++) { |
| 2628 | let rowDatas = rows[i], |
| 2629 | attributes = {}, |