Skip to content

Commit b5a4687

Browse files
committed
Merge pull request #162 from gberaudo/handle_features_without_geometry
Handle features without geometry
2 parents c99f203 + 3e9393c commit b5a4687

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

examples/vectors.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ var styles = {
106106
};
107107

108108
var styleFunction = function(feature, resolution) {
109-
return styles[feature.getGeometry().getType()];
109+
var geo = feature.getGeometry();
110+
// always assign a style to prevent feature skipping
111+
return geo ? styles[geo.getType()] : styles['Point'];
110112
};
111113

112114
var vectorSource = new ol.source.GeoJSON(
@@ -120,6 +122,13 @@ var vectorSource = new ol.source.GeoJSON(
120122
}
121123
},
122124
'features': [
125+
{
126+
'type': 'Feature',
127+
'geometry': null,
128+
'properties': {
129+
'type': 'without geometry as allowed in spec',
130+
}
131+
},
123132
{
124133
'type': 'Feature',
125134
'geometry': {

src/core.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,11 @@ goog.require('olcs.core.OlLayerPrimitive');
10891089
olcs.core.olFeatureToCesium = function(feature, style, context, opt_geom) {
10901090
var geom = opt_geom || feature.getGeometry();
10911091
var proj = context.projection;
1092+
if (!geom) {
1093+
// Ol3 features may not have a geometry
1094+
// See http://geojson.org/geojson-spec.html#feature-objects
1095+
return null;
1096+
}
10921097

10931098
var id = function(object) {
10941099
object.olFeature = feature;

0 commit comments

Comments
 (0)