Named exports from ol/style/Style

This commit is contained in:
Tim Schaub
2018-02-22 23:34:52 -08:00
parent ca4dfb9ec3
commit 580c2c6545
8 changed files with 35 additions and 34 deletions

View File

@@ -26,7 +26,7 @@ import PointerInteraction, {handleEvent as handlePointerEvent} from '../interact
import InteractionProperty from '../interaction/Property.js';
import VectorLayer from '../layer/Vector.js';
import VectorSource from '../source/Vector.js';
import Style from '../style/Style.js';
import {createEditingStyle} from '../style/Style.js';
/**
@@ -377,7 +377,7 @@ inherits(Draw, PointerInteraction);
* @return {ol.StyleFunction} Styles.
*/
function getDefaultStyleFunction() {
const styles = Style.createDefaultEditing();
const styles = createEditingStyle();
return function(feature, resolution) {
return styles[feature.getGeometry().getType()];
};

View File

@@ -15,7 +15,7 @@ import ExtentEventType from '../interaction/ExtentEventType.js';
import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js';
import VectorLayer from '../layer/Vector.js';
import VectorSource from '../source/Vector.js';
import Style from '../style/Style.js';
import {createEditingStyle} from '../style/Style.js';
/**
@@ -263,7 +263,7 @@ function handleUpEvent(mapBrowserEvent) {
* @return {ol.StyleFunction} Default Extent style
*/
function getDefaultExtentStyleFunction() {
const style = Style.createDefaultEditing();
const style = createEditingStyle();
return function(feature, resolution) {
return style[GeometryType.POLYGON];
};
@@ -275,7 +275,7 @@ function getDefaultExtentStyleFunction() {
* @return {ol.StyleFunction} Default pointer style
*/
function getDefaultPointerStyleFunction() {
const style = Style.createDefaultEditing();
const style = createEditingStyle();
return function(feature, resolution) {
return style[GeometryType.POINT];
};

View File

@@ -22,7 +22,7 @@ import VectorLayer from '../layer/Vector.js';
import VectorSource from '../source/Vector.js';
import VectorEventType from '../source/VectorEventType.js';
import RBush from '../structs/RBush.js';
import Style from '../style/Style.js';
import {createEditingStyle} from '../style/Style.js';
/**
* @classdesc
@@ -1180,7 +1180,7 @@ Modify.prototype.updateSegmentIndices_ = function(
* @return {ol.StyleFunction} Styles.
*/
Modify.getDefaultStyleFunction = function() {
const style = Style.createDefaultEditing();
const style = createEditingStyle();
return function(feature, resolution) {
return style[GeometryType.POINT];
};

View File

@@ -13,7 +13,7 @@ import Interaction from '../interaction/Interaction.js';
import VectorLayer from '../layer/Vector.js';
import {clear} from '../obj.js';
import VectorSource from '../source/Vector.js';
import Style from '../style/Style.js';
import {createEditingStyle} from '../style/Style.js';
/**
@@ -334,7 +334,7 @@ Select.prototype.setMap = function(map) {
* @return {ol.StyleFunction} Styles.
*/
Select.getDefaultStyleFunction = function() {
const styles = Style.createDefaultEditing();
const styles = createEditingStyle();
extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]);
extend(styles[GeometryType.GEOMETRY_COLLECTION], styles[GeometryType.LINE_STRING]);

View File

@@ -6,7 +6,7 @@ import LayerType from '../LayerType.js';
import Layer from '../layer/Layer.js';
import VectorRenderType from '../layer/VectorRenderType.js';
import {assign} from '../obj.js';
import Style from '../style/Style.js';
import {createDefaultStyle, toFunction as toStyleFunction} from '../style/Style.js';
/**
@@ -207,9 +207,9 @@ VectorLayer.prototype.setRenderOrder = function(renderOrder) {
* @api
*/
VectorLayer.prototype.setStyle = function(style) {
this.style_ = style !== undefined ? style : Style.defaultFunction;
this.style_ = style !== undefined ? style : createDefaultStyle;
this.styleFunction_ = style === null ?
undefined : Style.createFunction(this.style_);
undefined : toStyleFunction(this.style_);
this.changed();
};

View File

@@ -32,7 +32,7 @@ const Style = function(opt_options) {
* @private
* @type {!ol.StyleGeometryFunction}
*/
this.geometryFunction_ = Style.defaultGeometryFunction;
this.geometryFunction_ = defaultGeometryFunction;
if (options.geometry !== undefined) {
this.setGeometry(options.geometry);
@@ -249,7 +249,7 @@ Style.prototype.setGeometry = function(geometry) {
return /** @type {ol.geom.Geometry} */ (feature.get(geometry));
};
} else if (!geometry) {
this.geometryFunction_ = Style.defaultGeometryFunction;
this.geometryFunction_ = defaultGeometryFunction;
} else if (geometry !== undefined) {
this.geometryFunction_ = function() {
return /** @type {ol.geom.Geometry} */ (geometry);
@@ -278,7 +278,7 @@ Style.prototype.setZIndex = function(zIndex) {
* A style function, a single style, or an array of styles.
* @return {ol.StyleFunction} A style function.
*/
Style.createFunction = function(obj) {
export function toFunction(obj) {
let styleFunction;
if (typeof obj === 'function') {
@@ -300,7 +300,7 @@ Style.createFunction = function(obj) {
};
}
return styleFunction;
};
}
/**
@@ -314,7 +314,7 @@ let defaultStyles = null;
* @param {number} resolution Resolution.
* @return {Array.<ol.style.Style>} Style.
*/
Style.defaultFunction = function(feature, resolution) {
export function createDefaultStyle(feature, resolution) {
// We don't use an immediately-invoked function
// and a closure so we don't get an error at script evaluation time in
// browsers that do not support Canvas. (ol.style.Circle does
@@ -341,14 +341,14 @@ Style.defaultFunction = function(feature, resolution) {
];
}
return defaultStyles;
};
}
/**
* Default styles for editing features.
* @return {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} Styles
*/
Style.createDefaultEditing = function() {
export function createEditingStyle() {
/** @type {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} */
const styles = {};
const white = [255, 255, 255, 1];
@@ -412,7 +412,7 @@ Style.createDefaultEditing = function() {
);
return styles;
};
}
/**
@@ -421,7 +421,8 @@ Style.createDefaultEditing = function() {
* for.
* @return {ol.geom.Geometry|ol.render.Feature|undefined} Geometry to render.
*/
Style.defaultGeometryFunction = function(feature) {
function defaultGeometryFunction(feature) {
return feature.getGeometry();
};
}
export default Style;

View File

@@ -1,7 +1,7 @@
import Layer from '../../../../src/ol/layer/Layer.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import Style from '../../../../src/ol/style/Style.js';
import Style, {createDefaultStyle} from '../../../../src/ol/style/Style.js';
describe('ol.layer.Vector', function() {
@@ -74,10 +74,10 @@ describe('ol.layer.Vector', function() {
});
it('updates the internal style function', function() {
expect(layer.getStyleFunction()).to.be(Style.defaultFunction);
expect(layer.getStyleFunction()).to.be(createDefaultStyle);
layer.setStyle(style);
expect(layer.getStyleFunction()).not.to.be(
Style.defaultFunction);
createDefaultStyle);
});
it('allows setting an null style', function() {
@@ -89,8 +89,8 @@ describe('ol.layer.Vector', function() {
it('sets the default style when passing undefined', function() {
layer.setStyle(style);
layer.setStyle(undefined);
expect(layer.getStyle()).to.be(Style.defaultFunction);
expect(layer.getStyleFunction()).to.be(Style.defaultFunction);
expect(layer.getStyle()).to.be(createDefaultStyle);
expect(layer.getStyleFunction()).to.be(createDefaultStyle);
});
});
@@ -105,7 +105,7 @@ describe('ol.layer.Vector', function() {
source: source
});
expect(layer.getStyle()).to.be(Style.defaultFunction);
expect(layer.getStyle()).to.be(createDefaultStyle);
layer.setStyle(style);
expect(layer.getStyle()).to.be(style);

View File

@@ -1,6 +1,6 @@
import Feature from '../../../../src/ol/Feature.js';
import Point from '../../../../src/ol/geom/Point.js';
import Style from '../../../../src/ol/style/Style.js';
import Style, {toFunction} from '../../../../src/ol/style/Style.js';
import Fill from '../../../../src/ol/style/Fill.js';
import CircleStyle from '../../../../src/ol/style/Circle.js';
import Stroke from '../../../../src/ol/style/Stroke.js';
@@ -240,16 +240,16 @@ describe('ol.style.Style', function() {
});
describe('ol.style.Style.createFunction()', function() {
describe('toFunction()', function() {
const style = new Style();
it('creates a style function from a single style', function() {
const styleFunction = Style.createFunction(style);
const styleFunction = toFunction(style);
expect(styleFunction()).to.eql([style]);
});
it('creates a style function from an array of styles', function() {
const styleFunction = Style.createFunction([style]);
const styleFunction = toFunction([style]);
expect(styleFunction()).to.eql([style]);
});
@@ -257,13 +257,13 @@ describe('ol.style.Style.createFunction()', function() {
const original = function() {
return [style];
};
const styleFunction = Style.createFunction(original);
const styleFunction = toFunction(original);
expect(styleFunction).to.be(original);
});
it('throws on (some) unexpected input', function() {
expect(function() {
Style.createFunction({bogus: 'input'});
toFunction({bogus: 'input'});
}).to.throwException();
});