2017-09-22 14:43:40 -07:00
|
|
|
import React from 'react';
|
2017-09-26 13:32:27 -07:00
|
|
|
import MapboxStyleSheet from '../utils/MapboxStyleSheet';
|
2017-09-22 14:43:40 -07:00
|
|
|
|
|
|
|
|
class AbstractLayer extends React.Component {
|
|
|
|
|
get baseProps () {
|
|
|
|
|
return {
|
|
|
|
|
id: this.props.id,
|
|
|
|
|
sourceID: this.props.sourceID,
|
2017-09-26 13:32:27 -07:00
|
|
|
reactStyle: this.getStyle(),
|
2017-09-22 14:43:40 -07:00
|
|
|
minZoomLevel: this.props.minZoomLevel,
|
|
|
|
|
maxZoomLevel: this.props.maxZoomLevel,
|
|
|
|
|
aboveLayerID: this.props.aboveLayerID,
|
|
|
|
|
belowLayerID: this.props.belowLayerID,
|
|
|
|
|
layerIndex: this.props.layerIndex,
|
|
|
|
|
filter: this.getFilter(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFilter () {
|
|
|
|
|
if (!this.props.filter) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let flattenedFilter = [];
|
|
|
|
|
for (let i = 0; i < this.props.filter.length; i++) {
|
|
|
|
|
const item = this.props.filter[i];
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(item)) {
|
|
|
|
|
flattenedFilter = flattenedFilter.concat(item);
|
|
|
|
|
} else {
|
|
|
|
|
flattenedFilter.push(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flattenedFilter.join(';');
|
|
|
|
|
}
|
2017-09-26 13:32:27 -07:00
|
|
|
|
|
|
|
|
getStyle () {
|
|
|
|
|
if (!this.props.style) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MapboxStyleSheet.isStyleSheet(this.props.style)) {
|
|
|
|
|
return this.props.style;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MapboxStyleSheet.create(this.props.style);
|
|
|
|
|
}
|
2017-09-22 14:43:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default AbstractLayer;
|