MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / excelData2Feature

Method excelData2Feature

src/openlayers/mapping/WebMap.js:2572–2660  ·  view source on GitHub ↗

* @private * @function WebMap.prototype.excelData2Feature * @description 将csv和xls文件内容转换成ol.feature * @param {Object} content - 文件内容 * @param {Object} layerInfo - 图层信息 * @returns {Array} ol.feature的数组集合

(content, layerInfo)

Source from the content-addressed store, hash-verified

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 = {},

Callers 2

addLayersMethod · 0.80
addGeojsonFromUrlMethod · 0.80

Calls 6

isCredentailMethod · 0.95
trimMethod · 0.80
indexOfMethod · 0.80
pushMethod · 0.80
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected