Merge pull request #7880 from tschaub/named-exports

Named exports from ol/style/Style
This commit is contained in:
Tim Schaub
2018-02-23 09:04:03 -08:00
committed by GitHub
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 InteractionProperty from '../interaction/Property.js';
import VectorLayer from '../layer/Vector.js'; import VectorLayer from '../layer/Vector.js';
import VectorSource from '../source/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. * @return {ol.StyleFunction} Styles.
*/ */
function getDefaultStyleFunction() { function getDefaultStyleFunction() {
const styles = Style.createDefaultEditing(); const styles = createEditingStyle();
return function(feature, resolution) { return function(feature, resolution) {
return styles[feature.getGeometry().getType()]; 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 PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js';
import VectorLayer from '../layer/Vector.js'; import VectorLayer from '../layer/Vector.js';
import VectorSource from '../source/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 * @return {ol.StyleFunction} Default Extent style
*/ */
function getDefaultExtentStyleFunction() { function getDefaultExtentStyleFunction() {
const style = Style.createDefaultEditing(); const style = createEditingStyle();
return function(feature, resolution) { return function(feature, resolution) {
return style[GeometryType.POLYGON]; return style[GeometryType.POLYGON];
}; };
@@ -275,7 +275,7 @@ function getDefaultExtentStyleFunction() {
* @return {ol.StyleFunction} Default pointer style * @return {ol.StyleFunction} Default pointer style
*/ */
function getDefaultPointerStyleFunction() { function getDefaultPointerStyleFunction() {
const style = Style.createDefaultEditing(); const style = createEditingStyle();
return function(feature, resolution) { return function(feature, resolution) {
return style[GeometryType.POINT]; return style[GeometryType.POINT];
}; };

View File

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

View File

@@ -13,7 +13,7 @@ import Interaction from '../interaction/Interaction.js';
import VectorLayer from '../layer/Vector.js'; import VectorLayer from '../layer/Vector.js';
import {clear} from '../obj.js'; import {clear} from '../obj.js';
import VectorSource from '../source/Vector.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. * @return {ol.StyleFunction} Styles.
*/ */
Select.getDefaultStyleFunction = function() { Select.getDefaultStyleFunction = function() {
const styles = Style.createDefaultEditing(); const styles = createEditingStyle();
extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]); extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]);
extend(styles[GeometryType.GEOMETRY_COLLECTION], 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 Layer from '../layer/Layer.js';
import VectorRenderType from '../layer/VectorRenderType.js'; import VectorRenderType from '../layer/VectorRenderType.js';
import {assign} from '../obj.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 * @api
*/ */
VectorLayer.prototype.setStyle = function(style) { VectorLayer.prototype.setStyle = function(style) {
this.style_ = style !== undefined ? style : Style.defaultFunction; this.style_ = style !== undefined ? style : createDefaultStyle;
this.styleFunction_ = style === null ? this.styleFunction_ = style === null ?
undefined : Style.createFunction(this.style_); undefined : toStyleFunction(this.style_);
this.changed(); this.changed();
}; };

View File

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

View File

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

View File

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