let ol = require('openlayers');
/**
* Класс, предназначенный для извлечение параметров стиля
* @class ExtractStyle
*/
class ExtractStyle {
constructor(styleFunction) {
this.styleFunction = styleFunction;
}
/**
* Получение корректного имени класса стиля
* @return {undefined}
*/
getStyleTypeName() {
let dict = {
AtlasManager: ol.style.AtlasManager,
Circle: ol.style.Circle,
Fill: ol.style.Fill,
Icon: ol.style.Icon,
Image: ol.style.Image,
RegularShape: ol.style.RegularShape,
Stroke: ol.style.Stroke,
Style: ol.style.Style,
Text: ol.style.Text
};
let typeName = undefined;
let styleFunction = this.styleFunction;
for (let key in dict) {
if (styleFunction instanceof dict[key]) typeName = key;
}
return typeName;
}
/**
* Метод возвращает дефолтовое значение стиля от функции стиля
* @return {*}
*/
getDefaultValue() {
let defaultValues = this.styleFunction();
if (defaultValues.length > 0) return defaultValues[0];
return undefined;
}
/**
* Метод возвращает свойства заливки стиля
* @param value
* @return {*}
*/
getFill(value) {
let fillParams = value.getFill();
if (!fillParams) return {};
let result = {
color: fillParams.getColor()
};
return result;
}
/**
* Метод возвращает свойства линии стиля
* @param value
* @return {*}
*/
getStroke(value) {
let strokeParams = value.getStroke();
if (!strokeParams) return {};
let result = {
color: strokeParams.getColor(),
lineCap: strokeParams.getLineCap(),
lineJoin: strokeParams.getLineJoin(),
lineDash: strokeParams.getLineDash(),
lineDashOffset: strokeParams.getLineDashOffset(),
miterLimit: strokeParams.getMiterLimit(),
width: strokeParams.getWidth()
};
return result;
}
/**
* Метод возвращает свойства изображения стиля
* @param value
* @return {*}
*/
getImage(value) {
let self = this;
let imageParams = value.getImage();
if (!imageParams) return {};
let result = {
anchor: imageParams.getAnchor(),
img: imageParams.getImage(),
opacity: imageParams.getOpacity(),
scale: imageParams.getScale(),
size: imageParams.getSize(),
rotation: imageParams.getRotation(),
rotateWithView: imageParams.getRotateWithView(),
fill: self.getFill(imageParams.getFill()),
stroke: self.getStroke(imageParams.getStroke()),
radius: imageParams.getRadius(),
radius2: imageParams.getRadius2()
};
return result;
}
/**
* Метод возвращает описание стиля для дефолтового значения стиля
* @return {{}}
*/
getStyleConfiguration() {
let self = this;
let styleName = self.getStyleTypeName();
let value = self.getDefaultValue();
let config = {};
switch (styleName) {
case "AtlasManager":
break;
case "Circle":
break;
case "Fill":
config = this.getFill(value);
break;
case "Icon":
config = self.getImage(value);
break;
case "Image":
config = self.getImage(value);
break;
case "RegularShape":
config = self.getImage(value);
break;
case "Stroke":
config = self.getStroke(value);
break;
case "Style":
break;
case "Text":
break;
default:
break;
};
return config;
}
}
module.exports = ExtractStyle;