Skip to content

Commit 5ba11fe

Browse files
修复 ol webmap csv 处理报错
1 parent b54bdf0 commit 5ba11fe

File tree

2 files changed

+224
-2
lines changed

2 files changed

+224
-2
lines changed

Diff for: src/openlayers/mapping/WebMap.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -2640,10 +2640,13 @@ export class WebMap extends Observable {
26402640
if (feature) {
26412641
let newFeature = window.cloneDeep(feature);
26422642
newFeature.properties = {};
2643+
const titleLen = titles.length;
26432644
row.forEach((item, idx) => {
26442645
//空格问题,看见DV多处处理空格问题,TODO统一整理
2645-
let key = titles[idx].trim();
2646-
newFeature.properties[key] = item;
2646+
if (idx < titleLen) {
2647+
let key = titles[idx].trim();
2648+
newFeature.properties[key] = item;
2649+
}
26472650
});
26482651
geojson.features.push(newFeature);
26492652
}

Diff for: test/openlayers/mapping/WebMapSpec.js

+219
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Feature from 'ol/Feature';
2323
import * as olProj from 'ol/proj';
2424
import proj4 from 'proj4';
2525
import * as olLayer from 'ol/layer';
26+
import cloneDeep from 'lodash.clonedeep';
2627

2728
window.jsonsql = { query: () => { } };
2829

@@ -1805,4 +1806,222 @@ describe('openlayers_WebMap', () => {
18051806
done();
18061807
}
18071808
});
1809+
1810+
it('fix csv property length over title length', (done) => {
1811+
window.cloneDeep = function(feature) {
1812+
return cloneDeep(feature);
1813+
}
1814+
let options = {
1815+
server: server,
1816+
webMap: defaultServeRequest,
1817+
successCallback,
1818+
errorCallback: function () { }
1819+
};
1820+
spyOn(FetchRequest, 'get').and.callFake((url) => {
1821+
if (url.indexOf('map.json') > -1) {
1822+
var mapJson = datavizWebMap_noServerIdMarker;
1823+
return Promise.resolve(new Response(mapJson));
1824+
}
1825+
return Promise.resolve();
1826+
});
1827+
var datavizWebmap = new WebMap(options);
1828+
function successCallback() {
1829+
const features = [
1830+
{
1831+
"geometry": {
1832+
"coordinates": [
1833+
[
1834+
[
1835+
117.9612792600001,
1836+
31.50179038417261
1837+
],
1838+
[
1839+
117.6538350116667,
1840+
31.36421118000805
1841+
],
1842+
[
1843+
117.5036929400001,
1844+
31.00564246918011
1845+
],
1846+
[
1847+
117.2036532125,
1848+
31.06033994834594
1849+
],
1850+
[
1851+
117.0296223400001,
1852+
31.2610837141762
1853+
],
1854+
[
1855+
117.1815134989584,
1856+
31.55480553729684
1857+
],
1858+
[
1859+
116.7638726916668,
1860+
31.61569306000427
1861+
],
1862+
[
1863+
116.7663789980209,
1864+
31.90478239979175
1865+
],
1866+
[
1867+
117.0149495701043,
1868+
32.09548291728905
1869+
],
1870+
[
1871+
116.9956159214584,
1872+
32.11601320312207
1873+
],
1874+
[
1875+
117.0107175175001,
1876+
32.16395522082976
1877+
],
1878+
[
1879+
117.00395803,
1880+
32.39582160415978
1881+
],
1882+
[
1883+
117.1965708000001,
1884+
32.53416217415796
1885+
],
1886+
[
1887+
117.3470498758334,
1888+
32.45553657999236
1889+
],
1890+
[
1891+
117.3796553844792,
1892+
32.43855426426338
1893+
],
1894+
[
1895+
117.4034777350001,
1896+
32.38868854999331
1897+
],
1898+
[
1899+
117.3973120916668,
1900+
32.29735015499454
1901+
],
1902+
[
1903+
117.5562772865626,
1904+
32.22039671520397
1905+
],
1906+
[
1907+
117.8666145383334,
1908+
32.13696457999682
1909+
],
1910+
[
1911+
117.8979449009376,
1912+
31.93163098958303
1913+
],
1914+
[
1915+
117.9540050100001,
1916+
31.90536486416671
1917+
],
1918+
[
1919+
117.9612792600001,
1920+
31.50179038417261
1921+
]
1922+
]
1923+
],
1924+
"type": "Polygon"
1925+
},
1926+
"properties": {
1927+
"Name": "合肥市",
1928+
"PAC": 340102,
1929+
"UserID": 0,
1930+
"Province": "安徽省"
1931+
},
1932+
"type": "Feature"
1933+
},{
1934+
"geometry": {
1935+
"coordinates": [
1936+
[
1937+
[
1938+
116.9620359318751,
1939+
30.63692908460247
1940+
],
1941+
[
1942+
116.9626803625001,
1943+
30.63792411335244
1944+
],
1945+
[
1946+
116.9636623712501,
1947+
30.63948495199823
1948+
],
1949+
[
1950+
116.9647166275001,
1951+
30.64103160251904
1952+
],
1953+
[
1954+
116.9655092789584,
1955+
30.64199830803986
1956+
],
1957+
[
1958+
116.9661609391667,
1959+
30.64248322168568
1960+
],
1961+
[
1962+
116.9668600346876,
1963+
30.64271652616482
1964+
],
1965+
[
1966+
116.9676117783334,
1967+
30.64279261251899
1968+
],
1969+
[
1970+
116.9683829830209,
1971+
30.64278320543566
1972+
],
1973+
[
1974+
116.9691700758334,
1975+
30.64280515585233
1976+
]
1977+
]
1978+
],
1979+
"type": "Polygon"
1980+
},
1981+
"properties": {
1982+
"Name": "安庆市",
1983+
"PAC": 340823,
1984+
"UserID": 0,
1985+
"Province": "安徽省"
1986+
},
1987+
"type": "Feature"
1988+
}];
1989+
const datas = [[
1990+
"SmUserID",
1991+
"NAME",
1992+
"CODE",
1993+
"PROVINCE",
1994+
"Geometry"
1995+
],[
1996+
"0",
1997+
"安庆市",
1998+
"130100",
1999+
"HEBEI",
2000+
"POLYGON ((113.8395751199999495 38.7583869546093496",
2001+
"113.8408729199999811 38.7573249546098353",
2002+
"113.8452159599999476 38.7550289646109007",
2003+
"113.8183570799999416 38.7584829846093086",
2004+
"113.8292251199999754 38.7564389946102565",
2005+
"113.8395751199999495 38.7583869546093496))"
2006+
],
2007+
[
2008+
"1",
2009+
"合肥市",
2010+
"130100",
2011+
"HEBEI",
2012+
"POLYGON ((113.8395751199999495 38.7583869546093496",
2013+
"113.8408729199999811 38.7573249546098353",
2014+
"113.8452159599999476 38.7550289646109007",
2015+
"113.8183570799999416 38.7584829846093086",
2016+
"113.8292251199999754 38.7564389946102565",
2017+
"113.8395751199999495 38.7583869546093496))"
2018+
]];
2019+
const divisionType = 'City';
2020+
const divisionField = 'NAME';
2021+
const geojson = datavizWebmap.changeExcel2Geojson(features, datas, divisionType, divisionField);
2022+
expect(geojson.features.length).toBe(2);
2023+
expect(geojson.features[0].properties.hasOwnProperty(undefined)).toBeFalse();
2024+
done();
2025+
}
2026+
});
18082027
});

0 commit comments

Comments
 (0)