Skip to content

Commit 58277ce

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

File tree

6 files changed

+148
-3
lines changed

6 files changed

+148
-3
lines changed

src/mapboxgl/core/Util.js

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

src/maplibregl/core/Util.js

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

src/openlayers/core/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
return null;
7777
}
7878
const result = new GeoJSONFormat().read(geoJSON, 'FeatureCollection');
79-
return result[0].geometry;
79+
return result && result[0].geometry;
8080
},
8181

8282
/**

test/mapboxgl/core/UtilSpec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,65 @@ describe('Util', () => {
3939
expect(Util.isMatchAdministrativeName('北京', '北京市')).toBeTruthy();
4040
expect(Util.isMatchAdministrativeName('北京', null)).toBeFalsy();
4141
});
42+
it('toSuperMapGeometry', () => {
43+
var geoJSON = {
44+
type: 'FeatureCollection',
45+
features: [
46+
{
47+
type: 'Feature',
48+
properties: {
49+
attributes: {
50+
SmArea: '1.6060069623493825E15',
51+
SmGeoPosition: '65536',
52+
SmID: '1',
53+
SmPerimeter: '1.6030006674231339E8'
54+
},
55+
id: 1,
56+
layerName: 'World@China',
57+
searchValues: '',
58+
type: 'REGION'
59+
},
60+
geometry: {
61+
type: 'MultiPolygon',
62+
coordinates: [
63+
[
64+
[
65+
[-2, 258],
66+
[258, 258],
67+
[-2, 258],
68+
[-2, 258]
69+
]
70+
]
71+
]
72+
}
73+
}
74+
]
75+
};
76+
var result = Util.toSuperMapGeometry(geoJSON);
77+
expect(result).not.toBeNull();
78+
79+
var geoJSON2 = {
80+
type: 'FeatureCollection',
81+
features: [
82+
{
83+
type: 'Feature',
84+
properties: {
85+
attributes: {
86+
SmArea: '1.6060069623493825E15',
87+
SmGeoPosition: '65536',
88+
SmID: '1',
89+
SmPerimeter: '1.6030006674231339E8'
90+
},
91+
id: 1,
92+
layerName: 'World@China',
93+
searchValues: '',
94+
type: 'REGION'
95+
},
96+
geometry: null
97+
}
98+
]
99+
};
100+
var result2 = Util.toSuperMapGeometry(geoJSON2);
101+
expect(result2).toBeNull();
102+
});
42103
});

test/maplibregl/core/UtilSpec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,65 @@ describe('Util', () => {
3939
expect(Util.isMatchAdministrativeName('北京', '北京市')).toBeTruthy();
4040
expect(Util.isMatchAdministrativeName('北京', null)).toBeFalsy();
4141
});
42+
it('toSuperMapGeometry', () => {
43+
var geoJSON = {
44+
type: 'FeatureCollection',
45+
features: [
46+
{
47+
type: 'Feature',
48+
properties: {
49+
attributes: {
50+
SmArea: '1.6060069623493825E15',
51+
SmGeoPosition: '65536',
52+
SmID: '1',
53+
SmPerimeter: '1.6030006674231339E8'
54+
},
55+
id: 1,
56+
layerName: 'World@China',
57+
searchValues: '',
58+
type: 'REGION'
59+
},
60+
geometry: {
61+
type: 'MultiPolygon',
62+
coordinates: [
63+
[
64+
[
65+
[-2, 258],
66+
[258, 258],
67+
[-2, 258],
68+
[-2, 258]
69+
]
70+
]
71+
]
72+
}
73+
}
74+
]
75+
};
76+
var result = Util.toSuperMapGeometry(geoJSON);
77+
expect(result).not.toBeNull();
78+
79+
var geoJSON2 = {
80+
type: 'FeatureCollection',
81+
features: [
82+
{
83+
type: 'Feature',
84+
properties: {
85+
attributes: {
86+
SmArea: '1.6060069623493825E15',
87+
SmGeoPosition: '65536',
88+
SmID: '1',
89+
SmPerimeter: '1.6030006674231339E8'
90+
},
91+
id: 1,
92+
layerName: 'World@China',
93+
searchValues: '',
94+
type: 'REGION'
95+
},
96+
geometry: null
97+
}
98+
]
99+
};
100+
var result2 = Util.toSuperMapGeometry(geoJSON2);
101+
expect(result2).toBeNull();
102+
});
42103
});

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