<commit_before>/**
 * @ngdoc object
 * @name anol.layer.Feature
 *
 * @param {Object} options AnOl Layer options
 * @param {Object} options.olLayer Options for ol.layer.Vector
 * @param {Object} options.olLayer.source Options for ol.source.Vector
 *
 * @description
 * Inherits from {@link anol.layer.Layer anol.layer.Layer}.
 */
 anol.layer.Feature = function(_options) {
    if(_options === false) {
        anol.layer.Layer.call(this, _options);
        return;
    }
    var self = this;
    var defaults = {};
    var options = $.extend({},
        anol.layer.Layer.prototype.DEFAULT_OPTIONS,
        defaults,
        _options
    );
    var hasStyleFunction = angular.isFunction(options.olLayer.style);

    this.sourceOptions = this._createSourceOptions(options.olLayer.source);
    options.olLayer.source = new ol.source.Vector(this.sourceOptions);

    options.olLayer = new ol.layer.Vector(options.olLayer);

    anol.layer.Layer.call(this, options);

    this.hasPropertyLabel = false;
    // if the layer has an own style function we don't create an style object
    if (!hasStyleFunction) {

        var defaultStyle = angular.isFunction(this.olLayer.getStyle()) ?
            this.olLayer.getStyle()()[0] : this.olLayer.getStyle();

        if(options.style !== undefined) {
            var createImageStyleFunction = options.style.externalGraphic !== undefined ?
                this.createIconStyle : this.createCircleStyle;

            this.hasPropertyLabel = options.style.propertyLabel !== undefined;

            this.defaultStyle = new ol.style.Style({
                image: createImageStyleFunction.call(this, options.style, defaultStyle.getImage()),
                fill: this.createFillStyle(options.style, defaultStyle.getFill()),
                stroke: this.createStrokeStyle(options.style, defaultStyle.getStroke()),
                text: this.createTextStyle(options.style, defaultStyle.getText())
            });
        } else {
            this.defaultStyle = defaultStyle;
        }

        this.olLayer.setStyle(function(feature) {
            return [self.createStyle(feature)];
        });
    }

    this.isVector = true;
    this.loaded = true;
    this.saveable = options.saveable || false;
    this.editable = options.editable || false;
};
anol.layer.Feature.prototype = new anol.layer.Layer(false);
$.extend(anol.layer.Feature.prototype, {
    CLASS_NAME: 'anol.layer.Feature',
    DEFAULT_FONT_FACE: 'Helvetica',
    DEFAULT_FONT_SIZE: '10px',
    DEFAULT_FONT_WEIGHT: 'normal',
    extent: function() {
        var extent = this.olLayer.getSource().getExtent();
        if(ol.extent.isEmpty(extent)) {
            return false;
        }
        return extent;
    },
    createStyle: function(feature, resolution) {
        var defaultStyle = angular.isFunction(this.defaultStyle) ?
            this.defaultStyle(feature, resolution)[0] : this.defaultStyle;
        if(feature === undefined) {
            return defaultStyle;
        }
        var geometryType = feature.getGeometry().getType();
        var featureStyle = feature.get('style') || {};
        if(angular.equals(featureStyle, {}) && !this.hasPropertyLabel) {
            return defaultStyle;
        }
        var styleOptions = {};
        if(geometryType === 'Point') {
            styleOptions.image = this.createImageStyle(featureStyle, defaultStyle.getImage());
        } else {
            // line features ignores fill style
            styleOptions.fill = this.createFillStyle(featureStyle, defaultStyle.getFill());
            styleOptions.stroke = this.createStrokeStyle(featureStyle, defaultStyle.getStroke());
        }
        styleOptions.text = this.createTextStyle(featureStyle, defaultStyle.getText(), feature);
        return new ol.style.Style(styleOptions);
    },
    createImageStyle: function(style, defaultImageStyle) {
        var radius = style.radius;
        var externalGraphic = style.externalGraphic;

        var isCircle = radius !== undefined;
        var isIcon = externalGraphic !== undefined;
        var isDefaultCircle = defaultImageStyle instanceof ol.style.Circle;
        var isDefaultIcon = defaultImageStyle instanceof ol.style.Icon;

        if (isIcon || (!isCircle && isDefaultIcon)) {
            return this.createIconStyle(style, defaultImageStyle);
        } else if(isCircle || (!isIcon && isDefaultCircle)) {
            return this.createCircleStyle(style, defaultImageStyle);
        }
        return defaultImageStyle;
    },
    createCircleStyle: function(style, defaultCircleStyle) {
        var defaultStrokeStyle = new ol.style.Stroke();
        var defaultFillStyle = new ol.style.Fill();
        var radius;
        if(defaultCircleStyle instanceof ol.style.Circle) {
            defaultStrokeStyle = defaultCircleStyle.getStroke();
            defaultFillStyle = defaultCircleStyle.getFill();
            radius = defaultCircleStyle.getRadius();
        }

        var _radius = style.radius;
        if(_radius !== undefined) {
            radius = parseFloat(_radius);
        }
        return new ol.style.Circle({
            radius: radius,
            stroke: this.createStrokeStyle(style, defaultStrokeStyle),
            fill: this.createFillStyle(style, defaultFillStyle)
        });
    },
    createIconStyle: function(style, defaultIconStyle) {
        var styleOptions = {};

        if(defaultIconStyle instanceof ol.style.Icon) {
            styleOptions.src = defaultIconStyle.getSrc();
            styleOptions.rotation = defaultIconStyle.getRotation();
            styleOptions.scale = defaultIconStyle.getScale();
            styleOptions.size = defaultIconStyle.getSize();
        }

        if(style.externalGraphic !== undefined) {
            styleOptions.src = style.externalGraphic;
        }

        if(style.rotation !== undefined) {
            styleOptions.rotation = parseFloat(style.rotation);
        }

        if(style.graphicWidth !== undefined && style.graphicHeight !== undefined) {
            styleOptions.size = [
                parseInt(style.graphicWidth),
                parseInt(style.graphicHeight)
            ];
        }

        if(style.graphicColor !== undefined) {
            styleOptions.color = style.graphicColor;
        }

        var anchor = [0.5, 0.5];
        if(style.graphicXAnchor !== undefined) {
            anchor[0] = parseInt(style.graphicXAnchor);
            styleOptions.anchorXUnits = 'pixel';
        }
        if(style.graphicYAnchor !== undefined) {
            anchor[1] = parseInt(style.graphicYAnchor);
            styleOptions.anchorYUnits = 'pixel';
        }
        styleOptions.anchor = anchor;

        if(style.scale !== undefined) {
            styleOptions.scale = parseFloat(style.scale);
        }

        return new ol.style.Icon(styleOptions);
    },
    createFillStyle: function(style, defaultFillStyle) {
        var color = ol.color.asArray(defaultFillStyle.getColor()).slice();
        var fillColor = style.fillColor;
        if (fillColor !== undefined) {
            fillColor = ol.color.asArray(fillColor);
            color[0] = fillColor[0];<commit_msg>Changed graphic style property names<commit_after>/**
 * @ngdoc object
 * @name anol.layer.Feature
 *
 * @param {Object} options AnOl Layer options
 * @param {Object} options.olLayer Options for ol.layer.Vector
 * @param {Object} options.olLayer.source Options for ol.source.Vector
 *
 * @description
 * Inherits from {@link anol.layer.Layer anol.layer.Layer}.
 */
 anol.layer.Feature = function(_options) {
    if(_options === false) {
        anol.layer.Layer.call(this, _options);
        return;
    }
    var self = this;
    var defaults = {};
    var options = $.extend({},
        anol.layer.Layer.prototype.DEFAULT_OPTIONS,
        defaults,
        _options
    );
    var hasStyleFunction = angular.isFunction(options.olLayer.style);

    this.sourceOptions = this._createSourceOptions(options.olLayer.source);
    options.olLayer.source = new ol.source.Vector(this.sourceOptions);

    options.olLayer = new ol.layer.Vector(options.olLayer);

    anol.layer.Layer.call(this, options);

    this.hasPropertyLabel = false;
    // if the layer has an own style function we don't create an style object
    if (!hasStyleFunction) {

        var defaultStyle = angular.isFunction(this.olLayer.getStyle()) ?
            this.olLayer.getStyle()()[0] : this.olLayer.getStyle();

        if(options.style !== undefined) {
            var createImageStyleFunction = options.style.externalGraphic !== undefined ?
                this.createIconStyle : this.createCircleStyle;

            this.hasPropertyLabel = options.style.propertyLabel !== undefined;

            this.defaultStyle = new ol.style.Style({
                image: createImageStyleFunction.call(this, options.style, defaultStyle.getImage()),
                fill: this.createFillStyle(options.style, defaultStyle.getFill()),
                stroke: this.createStrokeStyle(options.style, defaultStyle.getStroke()),
                text: this.createTextStyle(options.style, defaultStyle.getText())
            });
        } else {
            this.defaultStyle = defaultStyle;
        }

        this.olLayer.setStyle(function(feature) {
            return [self.createStyle(feature)];
        });
    }

    this.isVector = true;
    this.loaded = true;
    this.saveable = options.saveable || false;
    this.editable = options.editable || false;
};
anol.layer.Feature.prototype = new anol.layer.Layer(false);
$.extend(anol.layer.Feature.prototype, {
    CLASS_NAME: 'anol.layer.Feature',
    DEFAULT_FONT_FACE: 'Helvetica',
    DEFAULT_FONT_SIZE: '10px',
    DEFAULT_FONT_WEIGHT: 'normal',
    extent: function() {
        var extent = this.olLayer.getSource().getExtent();
        if(ol.extent.isEmpty(extent)) {
            return false;
        }
        return extent;
    },
    createStyle: function(feature, resolution) {
        var defaultStyle = angular.isFunction(this.defaultStyle) ?
            this.defaultStyle(feature, resolution)[0] : this.defaultStyle;
        if(feature === undefined) {
            return defaultStyle;
        }
        var geometryType = feature.getGeometry().getType();
        var featureStyle = feature.get('style') || {};
        if(angular.equals(featureStyle, {}) && !this.hasPropertyLabel) {
            return defaultStyle;
        }
        var styleOptions = {};
        if(geometryType === 'Point') {
            styleOptions.image = this.createImageStyle(featureStyle, defaultStyle.getImage());
        } else {
            // line features ignores fill style
            styleOptions.fill = this.createFillStyle(featureStyle, defaultStyle.getFill());
            styleOptions.stroke = this.createStrokeStyle(featureStyle, defaultStyle.getStroke());
        }
        styleOptions.text = this.createTextStyle(featureStyle, defaultStyle.getText(), feature);
        return new ol.style.Style(styleOptions);
    },
    createImageStyle: function(style, defaultImageStyle) {
        var radius = style.radius;
        var externalGraphic = style.externalGraphic;

        var isCircle = radius !== undefined;
        var isIcon = externalGraphic !== undefined;
        var isDefaultCircle = defaultImageStyle instanceof ol.style.Circle;
        var isDefaultIcon = defaultImageStyle instanceof ol.style.Icon;

        if (isIcon || (!isCircle && isDefaultIcon)) {
            return this.createIconStyle(style, defaultImageStyle);
        } else if(isCircle || (!isIcon && isDefaultCircle)) {
            return this.createCircleStyle(style, defaultImageStyle);
        }
        return defaultImageStyle;
    },
    createCircleStyle: function(style, defaultCircleStyle) {
        var defaultStrokeStyle = new ol.style.Stroke();
        var defaultFillStyle = new ol.style.Fill();
        var radius;
        if(defaultCircleStyle instanceof ol.style.Circle) {
            defaultStrokeStyle = defaultCircleStyle.getStroke();
            defaultFillStyle = defaultCircleStyle.getFill();
            radius = defaultCircleStyle.getRadius();
        }

        var _radius = style.radius;
        if(_radius !== undefined) {
            radius = parseFloat(_radius);
        }
        return new ol.style.Circle({
            radius: radius,
            stroke: this.createStrokeStyle(style, defaultStrokeStyle),
            fill: this.createFillStyle(style, defaultFillStyle)
        });
    },
    createIconStyle: function(style, defaultIconStyle) {
        var styleOptions = {};

        if(defaultIconStyle instanceof ol.style.Icon) {
            styleOptions.src = defaultIconStyle.getSrc();
            styleOptions.rotation = defaultIconStyle.getRotation();
            styleOptions.scale = defaultIconStyle.getScale();
            styleOptions.size = defaultIconStyle.getSize();
        }

        if(style.externalGraphic !== undefined) {
            styleOptions.src = style.externalGraphic;
        }

        if(style.graphicRotation !== undefined) {
            styleOptions.rotation = parseFloat(style.graphicRotation);
        }

        if(style.graphicWidth !== undefined && style.graphicHeight !== undefined) {
            styleOptions.size = [
                parseInt(style.graphicWidth),
                parseInt(style.graphicHeight)
            ];
        }

        if(style.graphicColor !== undefined) {
            styleOptions.color = style.graphicColor;
        }

        var anchor = [0.5, 0.5];
        if(style.graphicXAnchor !== undefined) {
            anchor[0] = parseInt(style.graphicXAnchor);
            styleOptions.anchorXUnits = 'pixel';
        }
        if(style.graphicYAnchor !== undefined) {
            anchor[1] = parseInt(style.graphicYAnchor);
            styleOptions.anchorYUnits = 'pixel';
        }
        styleOptions.anchor = anchor;

        if(style.graphicScale !== undefined) {
            styleOptions.scale = parseFloat(style.graphicScale);
        }

        return new ol.style.Icon(styleOptions);
    },
    createFillStyle: function(style, defaultFillStyle) {
        var color = ol.color.asArray(defaultFillStyle.getColor()).slice();
        var fillColor = style.fillColor;
        if (fillColor !== undefined) {
            fillColor = ol.color.asArray(fillColor);
            color[0] = fillColor[0];
{'fraction_non_alphanumeric': 0.11375532137623003, 'fraction_numerical': 0.0016749249773187244, 'mean_word_length': 2.484074884512521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '88250', 'n_tokens_mistral': 3877, 'n_tokens_neox': 3804, 'n_words': 715}