diff --git a/CHANGELOG.md b/CHANGELOG.md index 918545a462..41527ac3fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ - Layers that use webgl renderers automatically share contexts when possible. Layers can switch renderers manually as well. This largely avoids the limitation of number of webgl contexts in a browser. - Support affine transforms in the proj4 string (#986) +### Improvements +- Spped up rendering geojson features by using constant values for constant geojson styles (#987) + ### Changes - The point clustering radius value is now in display pixels (#983) diff --git a/src/geojsonReader.js b/src/geojsonReader.js index f770eb42f1..80c5dd5e94 100644 --- a/src/geojsonReader.js +++ b/src/geojsonReader.js @@ -346,7 +346,9 @@ var geojsonReader = function (arg) { .style( [{}].concat(Object.keys(m_options.pointStyle)).reduce( (styleObj, key) => ({ - [key]: m_this._style(key, m_options.pointStyle[key]), + [key]: points.some(d => d.properties && d.properties[key] !== undefined) ? + m_this._style(key, m_options.pointStyle[key]) : + m_options.pointStyle[key], ...styleObj } )) @@ -369,7 +371,9 @@ var geojsonReader = function (arg) { .style( [{}].concat(Object.keys(m_options.lineStyle)).reduce( (styleObj, key) => ({ - [key]: m_this._style(key, m_options.lineStyle[key]), + [key]: lines.some(d => d.properties && d.properties[key] !== undefined) ? + m_this._style(key, m_options.lineStyle[key]) : + m_options.lineStyle[key], ...styleObj } )) @@ -395,7 +399,9 @@ var geojsonReader = function (arg) { .style( [{}].concat(Object.keys(m_options.polygonStyle)).reduce( (styleObj, key) => ({ - [key]: m_this._style(key, m_options.polygonStyle[key]), + [key]: polygons.some(d => d.properties && d.properties[key] !== undefined) ? + m_this._style(key, m_options.polygonStyle[key]) : + m_options.polygonStyle[key], ...styleObj } ))