Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on trying to create an unsupported feature. #823

Merged
merged 2 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 + '"');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps the line is little too long (I cannot read end-to-end on my browser) but other than that it looks good.

}
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