Manual class transform
This commit is contained in:
@@ -149,260 +149,246 @@ import Stroke from '../style/Stroke.js';
|
||||
* @param {module:ol/style/Style~Options=} opt_options Style options.
|
||||
* @api
|
||||
*/
|
||||
const Style = function(opt_options) {
|
||||
class Style {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options || {};
|
||||
const options = opt_options || {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction}
|
||||
*/
|
||||
this.geometry_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!module:ol/style/Style~GeometryFunction}
|
||||
*/
|
||||
this.geometryFunction_ = defaultGeometryFunction;
|
||||
|
||||
if (options.geometry !== undefined) {
|
||||
this.setGeometry(options.geometry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Fill}
|
||||
*/
|
||||
this.fill_ = options.fill !== undefined ? options.fill : null;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Image}
|
||||
* @type {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction}
|
||||
*/
|
||||
this.image_ = options.image !== undefined ? options.image : null;
|
||||
this.geometry_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Style~RenderFunction|null}
|
||||
*/
|
||||
this.renderer_ = options.renderer !== undefined ? options.renderer : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Stroke}
|
||||
*/
|
||||
this.stroke_ = options.stroke !== undefined ? options.stroke : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Text}
|
||||
*/
|
||||
this.text_ = options.text !== undefined ? options.text : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.zIndex_ = options.zIndex;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Clones the style.
|
||||
* @return {module:ol/style/Style} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.clone = function() {
|
||||
let geometry = this.getGeometry();
|
||||
if (geometry && geometry.clone) {
|
||||
geometry = geometry.clone();
|
||||
}
|
||||
return new Style({
|
||||
geometry: geometry,
|
||||
fill: this.getFill() ? this.getFill().clone() : undefined,
|
||||
image: this.getImage() ? this.getImage().clone() : undefined,
|
||||
stroke: this.getStroke() ? this.getStroke().clone() : undefined,
|
||||
text: this.getText() ? this.getText().clone() : undefined,
|
||||
zIndex: this.getZIndex()
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the custom renderer function that was configured with
|
||||
* {@link #setRenderer} or the `renderer` constructor option.
|
||||
* @return {module:ol/style/Style~RenderFunction|null} Custom renderer function.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.getRenderer = function() {
|
||||
return this.renderer_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets a custom renderer function for this style. When set, `fill`, `stroke`
|
||||
* and `image` options of the style will be ignored.
|
||||
* @param {module:ol/style/Style~RenderFunction|null} renderer Custom renderer function.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.setRenderer = function(renderer) {
|
||||
this.renderer_ = renderer;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the geometry to be rendered.
|
||||
* @return {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction}
|
||||
* Feature property or geometry or function that returns the geometry that will
|
||||
* be rendered with this style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.getGeometry = function() {
|
||||
return this.geometry_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the function used to generate a geometry for rendering.
|
||||
* @return {!module:ol/style/Style~GeometryFunction} Function that is called with a feature
|
||||
* and returns the geometry to render instead of the feature's geometry.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.getGeometryFunction = function() {
|
||||
return this.geometryFunction_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the fill style.
|
||||
* @return {module:ol/style/Fill} Fill style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.getFill = function() {
|
||||
return this.fill_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the fill style.
|
||||
* @param {module:ol/style/Fill} fill Fill style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.setFill = function(fill) {
|
||||
this.fill_ = fill;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the image style.
|
||||
* @return {module:ol/style/Image} Image style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.getImage = function() {
|
||||
return this.image_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the image style.
|
||||
* @param {module:ol/style/Image} image Image style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.setImage = function(image) {
|
||||
this.image_ = image;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke style.
|
||||
* @return {module:ol/style/Stroke} Stroke style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.getStroke = function() {
|
||||
return this.stroke_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the stroke style.
|
||||
* @param {module:ol/style/Stroke} stroke Stroke style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.setStroke = function(stroke) {
|
||||
this.stroke_ = stroke;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the text style.
|
||||
* @return {module:ol/style/Text} Text style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.getText = function() {
|
||||
return this.text_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the text style.
|
||||
* @param {module:ol/style/Text} text Text style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.setText = function(text) {
|
||||
this.text_ = text;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the z-index for the style.
|
||||
* @return {number|undefined} ZIndex.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.getZIndex = function() {
|
||||
return this.zIndex_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set a geometry that is rendered instead of the feature's geometry.
|
||||
*
|
||||
* @param {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction} geometry
|
||||
* Feature property or geometry or function returning a geometry to render
|
||||
* for this style.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.setGeometry = function(geometry) {
|
||||
if (typeof geometry === 'function') {
|
||||
this.geometryFunction_ = geometry;
|
||||
} else if (typeof geometry === 'string') {
|
||||
this.geometryFunction_ = function(feature) {
|
||||
return (
|
||||
/** @type {module:ol/geom/Geometry} */ (feature.get(geometry))
|
||||
);
|
||||
};
|
||||
} else if (!geometry) {
|
||||
/**
|
||||
* @private
|
||||
* @type {!module:ol/style/Style~GeometryFunction}
|
||||
*/
|
||||
this.geometryFunction_ = defaultGeometryFunction;
|
||||
} else if (geometry !== undefined) {
|
||||
this.geometryFunction_ = function() {
|
||||
return (
|
||||
/** @type {module:ol/geom/Geometry} */ (geometry)
|
||||
);
|
||||
};
|
||||
|
||||
if (options.geometry !== undefined) {
|
||||
this.setGeometry(options.geometry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Fill}
|
||||
*/
|
||||
this.fill_ = options.fill !== undefined ? options.fill : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Image}
|
||||
*/
|
||||
this.image_ = options.image !== undefined ? options.image : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Style~RenderFunction|null}
|
||||
*/
|
||||
this.renderer_ = options.renderer !== undefined ? options.renderer : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Stroke}
|
||||
*/
|
||||
this.stroke_ = options.stroke !== undefined ? options.stroke : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/style/Text}
|
||||
*/
|
||||
this.text_ = options.text !== undefined ? options.text : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.zIndex_ = options.zIndex;
|
||||
|
||||
}
|
||||
this.geometry_ = geometry;
|
||||
};
|
||||
|
||||
/**
|
||||
* Clones the style.
|
||||
* @return {module:ol/style/Style} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
let geometry = this.getGeometry();
|
||||
if (geometry && geometry.clone) {
|
||||
geometry = geometry.clone();
|
||||
}
|
||||
return new Style({
|
||||
geometry: geometry,
|
||||
fill: this.getFill() ? this.getFill().clone() : undefined,
|
||||
image: this.getImage() ? this.getImage().clone() : undefined,
|
||||
stroke: this.getStroke() ? this.getStroke().clone() : undefined,
|
||||
text: this.getText() ? this.getText().clone() : undefined,
|
||||
zIndex: this.getZIndex()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the z-index.
|
||||
*
|
||||
* @param {number|undefined} zIndex ZIndex.
|
||||
* @api
|
||||
*/
|
||||
Style.prototype.setZIndex = function(zIndex) {
|
||||
this.zIndex_ = zIndex;
|
||||
};
|
||||
/**
|
||||
* Get the custom renderer function that was configured with
|
||||
* {@link #setRenderer} or the `renderer` constructor option.
|
||||
* @return {module:ol/style/Style~RenderFunction|null} Custom renderer function.
|
||||
* @api
|
||||
*/
|
||||
getRenderer() {
|
||||
return this.renderer_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a custom renderer function for this style. When set, `fill`, `stroke`
|
||||
* and `image` options of the style will be ignored.
|
||||
* @param {module:ol/style/Style~RenderFunction|null} renderer Custom renderer function.
|
||||
* @api
|
||||
*/
|
||||
setRenderer(renderer) {
|
||||
this.renderer_ = renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the geometry to be rendered.
|
||||
* @return {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction}
|
||||
* Feature property or geometry or function that returns the geometry that will
|
||||
* be rendered with this style.
|
||||
* @api
|
||||
*/
|
||||
getGeometry() {
|
||||
return this.geometry_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the function used to generate a geometry for rendering.
|
||||
* @return {!module:ol/style/Style~GeometryFunction} Function that is called with a feature
|
||||
* and returns the geometry to render instead of the feature's geometry.
|
||||
* @api
|
||||
*/
|
||||
getGeometryFunction() {
|
||||
return this.geometryFunction_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fill style.
|
||||
* @return {module:ol/style/Fill} Fill style.
|
||||
* @api
|
||||
*/
|
||||
getFill() {
|
||||
return this.fill_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fill style.
|
||||
* @param {module:ol/style/Fill} fill Fill style.
|
||||
* @api
|
||||
*/
|
||||
setFill(fill) {
|
||||
this.fill_ = fill;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image style.
|
||||
* @return {module:ol/style/Image} Image style.
|
||||
* @api
|
||||
*/
|
||||
getImage() {
|
||||
return this.image_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the image style.
|
||||
* @param {module:ol/style/Image} image Image style.
|
||||
* @api
|
||||
*/
|
||||
setImage(image) {
|
||||
this.image_ = image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stroke style.
|
||||
* @return {module:ol/style/Stroke} Stroke style.
|
||||
* @api
|
||||
*/
|
||||
getStroke() {
|
||||
return this.stroke_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the stroke style.
|
||||
* @param {module:ol/style/Stroke} stroke Stroke style.
|
||||
* @api
|
||||
*/
|
||||
setStroke(stroke) {
|
||||
this.stroke_ = stroke;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text style.
|
||||
* @return {module:ol/style/Text} Text style.
|
||||
* @api
|
||||
*/
|
||||
getText() {
|
||||
return this.text_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text style.
|
||||
* @param {module:ol/style/Text} text Text style.
|
||||
* @api
|
||||
*/
|
||||
setText(text) {
|
||||
this.text_ = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the z-index for the style.
|
||||
* @return {number|undefined} ZIndex.
|
||||
* @api
|
||||
*/
|
||||
getZIndex() {
|
||||
return this.zIndex_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a geometry that is rendered instead of the feature's geometry.
|
||||
*
|
||||
* @param {string|module:ol/geom/Geometry|module:ol/style/Style~GeometryFunction} geometry
|
||||
* Feature property or geometry or function returning a geometry to render
|
||||
* for this style.
|
||||
* @api
|
||||
*/
|
||||
setGeometry(geometry) {
|
||||
if (typeof geometry === 'function') {
|
||||
this.geometryFunction_ = geometry;
|
||||
} else if (typeof geometry === 'string') {
|
||||
this.geometryFunction_ = function(feature) {
|
||||
return (
|
||||
/** @type {module:ol/geom/Geometry} */ (feature.get(geometry))
|
||||
);
|
||||
};
|
||||
} else if (!geometry) {
|
||||
this.geometryFunction_ = defaultGeometryFunction;
|
||||
} else if (geometry !== undefined) {
|
||||
this.geometryFunction_ = function() {
|
||||
return (
|
||||
/** @type {module:ol/geom/Geometry} */ (geometry)
|
||||
);
|
||||
};
|
||||
}
|
||||
this.geometry_ = geometry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the z-index.
|
||||
*
|
||||
* @param {number|undefined} zIndex ZIndex.
|
||||
* @api
|
||||
*/
|
||||
setZIndex(zIndex) {
|
||||
this.zIndex_ = zIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user