Skip to content

Commit

Permalink
Merge pull request #823 from OpenGeoscience/improve-feature-warnings
Browse files Browse the repository at this point in the history
Warn on trying to create an unsupported feature.
  • Loading branch information
manthey authored May 25, 2018
2 parents 2a100ef + bb870c0 commit 8ca5b61
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/featureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var featureLayer = function (arg) {
featureName, m_this, m_this.renderer(), arg);
if (newFeature) {
this.addFeature(newFeature);
} else {
console.warn('Layer renderer (' + m_this.rendererName() + ') does not support feature type "' + featureName + '"');
}
return newFeature;
};
Expand Down
32 changes: 19 additions & 13 deletions src/jsonReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,16 @@ var jsonReader = function (arg) {
this.read = function (file, done, progress) {

function _done(object) {
var features, allFeatures = [], points, lines, polygons;
var features, allFeatures = [], points, lines, polygons, feature;

features = m_this._featureArray(object);

// process points
points = features.filter(function (f) { return f.geometry.type === 'Point'; });
if (points.length) {
allFeatures.push(
m_this.layer().createFeature('point')
feature = m_this.layer().createFeature('point');
if (feature) {
feature
.data(points)
.position(function (d) {
return m_this._position(d.geometry.coordinates);
Expand All @@ -238,15 +239,17 @@ var jsonReader = function (arg) {
strokeWidth: m_this._style('strokeWidth', 1),
strokeOpacity: m_this._style('strokeOpacity', 1),
radius: m_this._style('radius', 8)
})
);
});
allFeatures.push(feature);
}
}

// process lines
lines = features.filter(function (f) { return f.geometry.type === 'LineString'; });
if (lines.length) {
allFeatures.push(
m_this.layer().createFeature('line')
feature = m_this.layer().createFeature('line');
if (feature) {
feature
.data(lines)
.line(function (d) {
return d.geometry.coordinates;
Expand All @@ -260,15 +263,17 @@ var jsonReader = function (arg) {
lineCap: m_this._style('lineCap', 'butt', lines),
lineJoin: m_this._style('lineCap', 'miter', lines),
closed: m_this._style('closed', false, lines)
})
);
});
allFeatures.push(feature);
}
}

// process polygons
polygons = features.filter(function (f) { return f.geometry.type === 'Polygon'; });
if (polygons.length) {
allFeatures.push(
m_this.layer().createFeature('polygon')
feature = m_this.layer().createFeature('polygon');
if (feature) {
feature
.data(polygons)
.polygon(function (d, i) {
return {
Expand All @@ -285,8 +290,9 @@ var jsonReader = function (arg) {
strokeColor: m_this._style('strokeColor', '#999999', polygons, convertColor),
strokeWidth: m_this._style('strokeWidth', 2, polygons),
strokeOpacity: m_this._style('strokeOpacity', 1, polygons)
})
);
});
allFeatures.push(feature);
}
}
if (done) {
done(allFeatures);
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('geo.feature', function () {

feat = geo.feature.create(layer, {type: 'no_feature'});
expect(feat).toBeNull();
expect(console.warn.calledOnce).toBe(true);
expect(console.warn.called).toBe(true);
expect(console.warn.calledWith(
'Could not create feature type "no_feature"')).toBe(true);
console.warn.reset();
Expand Down

0 comments on commit 8ca5b61

Please sign in to comment.