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

Method changeExcel2Geojson

src/openlayers/mapping/WebMap.js:2742–2776  ·  view source on GitHub ↗

* @private * @function WebMap.prototype.changeExcel2Geojson * @description 将excel和csv数据转换成标准geojson数据 * @param {Array} features - feature对象 * @param {Array} datas - 数据内容 * @param {string} divisionType - 行政区划类型 * @param {string} divisionField - 行政区划字段 * @returns {Object} geojson对

(features, datas, divisionType, divisionField)

Source from the content-addressed store, hash-verified

2740 * @returns {Object} geojson对象
2741 */
2742 changeExcel2Geojson(features, datas, divisionType, divisionField) {
2743 let geojson = {
2744 type: 'FeatureCollection',
2745 features: []
2746 };
2747 if (datas.length < 2) {
2748 return geojson; //只有一行数据时为标题
2749 }
2750 let titles = datas[0],
2751 rows = datas.slice(1),
2752 fieldIndex = titles.findIndex((title) => title === divisionField);
2753 rows.forEach((row) => {
2754 let feature;
2755 if (divisionType === 'GB-T_2260') {
2756 feature = features.find((item) => item.properties.GB === row[fieldIndex]);
2757 } else {
2758 feature = Util.getHighestMatchAdministration(features, row[fieldIndex]);
2759 }
2760 //todo 需提示忽略无效数据
2761 if (feature) {
2762 let newFeature = (window.cloneDeep || cloneDeep)(feature);
2763 newFeature.properties = {};
2764 const titleLen = titles.length;
2765 row.forEach((item, idx) => {
2766 //空格问题,看见DV多处处理空格问题,TODO统一整理
2767 if (idx < titleLen) {
2768 let key = titles[idx].trim();
2769 newFeature.properties[key] = item;
2770 }
2771 });
2772 geojson.features.push(newFeature);
2773 }
2774 });
2775 return geojson;
2776 }
2777
2778 /**
2779 * @private

Callers 2

successCallbackFunction · 0.80

Calls 4

forEachMethod · 0.80
trimMethod · 0.80
pushMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected