(layerInfo, properties)
| 3 | import provincialCenterData from '../config/ProvinceCenter.json'; // eslint-disable-line import/extensions |
| 4 | |
| 5 | export function createLinesData(layerInfo, properties) { |
| 6 | const data = []; |
| 7 | if (properties && properties.length) { |
| 8 | // 重新获取数据 |
| 9 | const from = layerInfo.from; |
| 10 | const to = layerInfo.to; |
| 11 | let fromCoord; |
| 12 | let toCoord; |
| 13 | if (from.type === 'XY_FIELD' && from.xField && from.yField && to.xField && to.yField) { |
| 14 | properties.forEach((property) => { |
| 15 | const fromX = property[from.xField]; |
| 16 | const fromY = property[from.yField]; |
| 17 | const toX = property[to.xField]; |
| 18 | const toY = property[to.yField]; |
| 19 | if (!fromX || !fromY || !toX || !toY) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | fromCoord = [property[from.xField], property[from.yField]]; |
| 24 | toCoord = [property[to.xField], property[to.yField]]; |
| 25 | data.push({ |
| 26 | coords: [fromCoord, toCoord] |
| 27 | }); |
| 28 | }); |
| 29 | } else if (from.type === 'PLACE_FIELD' && from.field && to.field) { |
| 30 | const centerDatas = provincialCenterData.concat(municipalCenterData); |
| 31 | |
| 32 | properties.forEach((property) => { |
| 33 | const fromField = property[from.field]; |
| 34 | const toField = property[to.field]; |
| 35 | fromCoord = centerDatas.find((item) => { |
| 36 | return isMatchAdministrativeName(item.name, fromField); |
| 37 | }); |
| 38 | toCoord = centerDatas.find((item) => { |
| 39 | return isMatchAdministrativeName(item.name, toField); |
| 40 | }); |
| 41 | if (!fromCoord || !toCoord) { |
| 42 | return; |
| 43 | } |
| 44 | data.push({ |
| 45 | coords: [fromCoord.coord, toCoord.coord] |
| 46 | }); |
| 47 | }); |
| 48 | } |
| 49 | } |
| 50 | return data; |
| 51 | } |
| 52 | |
| 53 | export function isMatchAdministrativeName(featureName, fieldName) { |
| 54 | if (isString(fieldName)) { |
no test coverage detected