Skip to content

Commit 59192ea

Browse files
committed
ICL-1580 修复编辑要素时feature不添加geometry无法更新成功 review by luox
1 parent 3816a2b commit 59192ea

File tree

6 files changed

+156
-3
lines changed

6 files changed

+156
-3
lines changed

src/mapboxgl/core/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const Util = {
4545
if (geoJSON && geoJSON.type) {
4646
var format = new GeoJSONFormat();
4747
var result = format.read(geoJSON, "FeatureCollection");
48-
return result[0].geometry;
48+
return result && result[0].geometry;
4949
}
5050
},
5151

src/maplibregl/core/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const Util = {
4545
if (geoJSON && geoJSON.type) {
4646
var format = new GeoJSONFormat();
4747
var result = format.read(geoJSON, "FeatureCollection");
48-
return result[0].geometry;
48+
return result && result[0].geometry;
4949
}
5050
},
5151

src/openlayers/core/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
return null;
7373
}
7474
const result = new GeoJSONFormat().read(geoJSON, 'FeatureCollection');
75-
return result[0].geometry;
75+
return result && result[0].geometry;
7676
},
7777

7878
/**

test/mapboxgl/core/UtilSpec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Util } from '../../../src/mapboxgl/core/Util';
2+
3+
describe('Util', () => {
4+
it('toSuperMapGeometry', () => {
5+
var geoJSON = {
6+
type: 'FeatureCollection',
7+
features: [
8+
{
9+
type: 'Feature',
10+
properties: {
11+
attributes: {
12+
SmArea: '1.6060069623493825E15',
13+
SmGeoPosition: '65536',
14+
SmID: '1',
15+
SmPerimeter: '1.6030006674231339E8'
16+
},
17+
id: 1,
18+
layerName: 'World@China',
19+
searchValues: '',
20+
type: 'REGION'
21+
},
22+
geometry: {
23+
type: 'MultiPolygon',
24+
coordinates: [
25+
[
26+
[
27+
[-2, 258],
28+
[258, 258],
29+
[-2, 258],
30+
[-2, 258]
31+
]
32+
]
33+
]
34+
}
35+
}
36+
]
37+
};
38+
var result = Util.toSuperMapGeometry(geoJSON);
39+
expect(result).not.toBeNull();
40+
41+
var geoJSON2 = {
42+
type: 'FeatureCollection',
43+
features: [
44+
{
45+
type: 'Feature',
46+
properties: {
47+
attributes: {
48+
SmArea: '1.6060069623493825E15',
49+
SmGeoPosition: '65536',
50+
SmID: '1',
51+
SmPerimeter: '1.6030006674231339E8'
52+
},
53+
id: 1,
54+
layerName: 'World@China',
55+
searchValues: '',
56+
type: 'REGION'
57+
},
58+
geometry: null
59+
}
60+
]
61+
};
62+
var result2 = Util.toSuperMapGeometry(geoJSON2);
63+
expect(result2).toBeNull();
64+
});
65+
});

test/maplibregl/core/UtilSpec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Util } from '../../../src/maplibregl/core/Util';
2+
3+
describe('Util', () => {
4+
it('toSuperMapGeometry', () => {
5+
var geoJSON = {
6+
type: 'FeatureCollection',
7+
features: [
8+
{
9+
type: 'Feature',
10+
properties: {
11+
attributes: {
12+
SmArea: '1.6060069623493825E15',
13+
SmGeoPosition: '65536',
14+
SmID: '1',
15+
SmPerimeter: '1.6030006674231339E8'
16+
},
17+
id: 1,
18+
layerName: 'World@China',
19+
searchValues: '',
20+
type: 'REGION'
21+
},
22+
geometry: {
23+
type: 'MultiPolygon',
24+
coordinates: [
25+
[
26+
[
27+
[-2, 258],
28+
[258, 258],
29+
[-2, 258],
30+
[-2, 258]
31+
]
32+
]
33+
]
34+
}
35+
}
36+
]
37+
};
38+
var result = Util.toSuperMapGeometry(geoJSON);
39+
expect(result).not.toBeNull();
40+
41+
var geoJSON2 = {
42+
type: 'FeatureCollection',
43+
features: [
44+
{
45+
type: 'Feature',
46+
properties: {
47+
attributes: {
48+
SmArea: '1.6060069623493825E15',
49+
SmGeoPosition: '65536',
50+
SmID: '1',
51+
SmPerimeter: '1.6030006674231339E8'
52+
},
53+
id: 1,
54+
layerName: 'World@China',
55+
searchValues: '',
56+
type: 'REGION'
57+
},
58+
geometry: null
59+
}
60+
]
61+
};
62+
var result2 = Util.toSuperMapGeometry(geoJSON2);
63+
expect(result2).toBeNull();
64+
});
65+
});

test/openlayers/core/UtilSpec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,29 @@ describe('openlayers_Util', () => {
121121
expect(point instanceof Point).toBeTruthy();
122122
expect(point.x).toBe(-2);
123123
expect(point.y).toBe(258);
124+
var geoJSON2 = {
125+
type: 'FeatureCollection',
126+
features: [
127+
{
128+
type: 'Feature',
129+
properties: {
130+
attributes: {
131+
SmArea: '1.6060069623493825E15',
132+
SmGeoPosition: '65536',
133+
SmID: '1',
134+
SmPerimeter: '1.6030006674231339E8'
135+
},
136+
id: 1,
137+
layerName: 'World@China',
138+
searchValues: '',
139+
type: 'REGION'
140+
},
141+
geometry: null
142+
}
143+
]
144+
};
145+
var result2 = Util.toSuperMapGeometry(geoJSON2);
146+
expect(result2).toBeNull();
124147
});
125148

126149
it('resolutionToScale', () => {

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