Skip to content

Commit c386e5e

Browse files
修复 ol webmap csv 处理报错
1 parent 77e9293 commit c386e5e

File tree

2 files changed

+224
-3
lines changed

2 files changed

+224
-3
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,10 +2692,13 @@ export class WebMap extends Observable {
26922692
if (feature) {
26932693
let newFeature = (window.cloneDeep || cloneDeep)(feature);
26942694
newFeature.properties = {};
2695+
const titleLen = titles.length;
26952696
row.forEach((item, idx) => {
26962697
//空格问题,看见DV多处处理空格问题,TODO统一整理
2697-
let key = titles[idx].trim();
2698-
newFeature.properties[key] = item;
2698+
if (idx < titleLen) {
2699+
let key = titles[idx].trim();
2700+
newFeature.properties[key] = item;
2701+
}
26992702
});
27002703
geojson.features.push(newFeature);
27012704
}

test/openlayers/mapping/WebMapSpec.js

Lines changed: 219 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Feature from 'ol/Feature';
2424
import * as olProj from 'ol/proj';
2525
import proj4 from 'proj4';
2626
import * as olLayer from 'ol/layer';
27+
import cloneDeep from 'lodash.clonedeep';
2728

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

@@ -1980,5 +1981,222 @@ describe('openlayers_WebMap', () => {
19801981
done();
19811982
}
19821983
});
1983-
1984+
1985+
it('fix csv property length over title length', (done) => {
1986+
window.cloneDeep = function(feature) {
1987+
return cloneDeep(feature);
1988+
}
1989+
let options = {
1990+
server: server,
1991+
webMap: defaultServeRequest,
1992+
successCallback,
1993+
errorCallback: function () { }
1994+
};
1995+
spyOn(FetchRequest, 'get').and.callFake((url) => {
1996+
if (url.indexOf('map.json') > -1) {
1997+
var mapJson = datavizWebMap_noServerIdMarker;
1998+
return Promise.resolve(new Response(mapJson));
1999+
}
2000+
return Promise.resolve();
2001+
});
2002+
var datavizWebmap = new WebMap(options);
2003+
function successCallback() {
2004+
const features = [
2005+
{
2006+
"geometry": {
2007+
"coordinates": [
2008+
[
2009+
[
2010+
117.9612792600001,
2011+
31.50179038417261
2012+
],
2013+
[
2014+
117.6538350116667,
2015+
31.36421118000805
2016+
],
2017+
[
2018+
117.5036929400001,
2019+
31.00564246918011
2020+
],
2021+
[
2022+
117.2036532125,
2023+
31.06033994834594
2024+
],
2025+
[
2026+
117.0296223400001,
2027+
31.2610837141762
2028+
],
2029+
[
2030+
117.1815134989584,
2031+
31.55480553729684
2032+
],
2033+
[
2034+
116.7638726916668,
2035+
31.61569306000427
2036+
],
2037+
[
2038+
116.7663789980209,
2039+
31.90478239979175
2040+
],
2041+
[
2042+
117.0149495701043,
2043+
32.09548291728905
2044+
],
2045+
[
2046+
116.9956159214584,
2047+
32.11601320312207
2048+
],
2049+
[
2050+
117.0107175175001,
2051+
32.16395522082976
2052+
],
2053+
[
2054+
117.00395803,
2055+
32.39582160415978
2056+
],
2057+
[
2058+
117.1965708000001,
2059+
32.53416217415796
2060+
],
2061+
[
2062+
117.3470498758334,
2063+
32.45553657999236
2064+
],
2065+
[
2066+
117.3796553844792,
2067+
32.43855426426338
2068+
],
2069+
[
2070+
117.4034777350001,
2071+
32.38868854999331
2072+
],
2073+
[
2074+
117.3973120916668,
2075+
32.29735015499454
2076+
],
2077+
[
2078+
117.5562772865626,
2079+
32.22039671520397
2080+
],
2081+
[
2082+
117.8666145383334,
2083+
32.13696457999682
2084+
],
2085+
[
2086+
117.8979449009376,
2087+
31.93163098958303
2088+
],
2089+
[
2090+
117.9540050100001,
2091+
31.90536486416671
2092+
],
2093+
[
2094+
117.9612792600001,
2095+
31.50179038417261
2096+
]
2097+
]
2098+
],
2099+
"type": "Polygon"
2100+
},
2101+
"properties": {
2102+
"Name": "合肥市",
2103+
"PAC": 340102,
2104+
"UserID": 0,
2105+
"Province": "安徽省"
2106+
},
2107+
"type": "Feature"
2108+
},{
2109+
"geometry": {
2110+
"coordinates": [
2111+
[
2112+
[
2113+
116.9620359318751,
2114+
30.63692908460247
2115+
],
2116+
[
2117+
116.9626803625001,
2118+
30.63792411335244
2119+
],
2120+
[
2121+
116.9636623712501,
2122+
30.63948495199823
2123+
],
2124+
[
2125+
116.9647166275001,
2126+
30.64103160251904
2127+
],
2128+
[
2129+
116.9655092789584,
2130+
30.64199830803986
2131+
],
2132+
[
2133+
116.9661609391667,
2134+
30.64248322168568
2135+
],
2136+
[
2137+
116.9668600346876,
2138+
30.64271652616482
2139+
],
2140+
[
2141+
116.9676117783334,
2142+
30.64279261251899
2143+
],
2144+
[
2145+
116.9683829830209,
2146+
30.64278320543566
2147+
],
2148+
[
2149+
116.9691700758334,
2150+
30.64280515585233
2151+
]
2152+
]
2153+
],
2154+
"type": "Polygon"
2155+
},
2156+
"properties": {
2157+
"Name": "安庆市",
2158+
"PAC": 340823,
2159+
"UserID": 0,
2160+
"Province": "安徽省"
2161+
},
2162+
"type": "Feature"
2163+
}];
2164+
const datas = [[
2165+
"SmUserID",
2166+
"NAME",
2167+
"CODE",
2168+
"PROVINCE",
2169+
"Geometry"
2170+
],[
2171+
"0",
2172+
"安庆市",
2173+
"130100",
2174+
"HEBEI",
2175+
"POLYGON ((113.8395751199999495 38.7583869546093496",
2176+
"113.8408729199999811 38.7573249546098353",
2177+
"113.8452159599999476 38.7550289646109007",
2178+
"113.8183570799999416 38.7584829846093086",
2179+
"113.8292251199999754 38.7564389946102565",
2180+
"113.8395751199999495 38.7583869546093496))"
2181+
],
2182+
[
2183+
"1",
2184+
"合肥市",
2185+
"130100",
2186+
"HEBEI",
2187+
"POLYGON ((113.8395751199999495 38.7583869546093496",
2188+
"113.8408729199999811 38.7573249546098353",
2189+
"113.8452159599999476 38.7550289646109007",
2190+
"113.8183570799999416 38.7584829846093086",
2191+
"113.8292251199999754 38.7564389946102565",
2192+
"113.8395751199999495 38.7583869546093496))"
2193+
]];
2194+
const divisionType = 'City';
2195+
const divisionField = 'NAME';
2196+
const geojson = datavizWebmap.changeExcel2Geojson(features, datas, divisionType, divisionField);
2197+
expect(geojson.features.length).toBe(2);
2198+
expect(geojson.features[0].properties.hasOwnProperty(undefined)).toBeFalse();
2199+
done();
2200+
}
2201+
});
19842202
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy