<commit_before>import BaseLayer from 'ol/layer/Base';
import Static from 'ol/source/ImageStatic';
import VectorLayer from 'ol/layer/Vector';
import {Circle, Icon} from 'ol/style';
import {Fill, Image as ImageStyle, Stroke, Style} from 'ol/style';
import {HsLegendDescriptor} from './legend-descriptor.interface';
import {HsUtilsService} from '../utils/utils.service';
import {Image as ImageLayer, Layer} from 'ol/layer';
import {ImageWMS, Source} from 'ol/source';
import {Injectable} from '@angular/core';
import {TileWMS, XYZ} from 'ol/source';

@Injectable({
  providedIn: 'root',
})
export class HsLegendService {
  /**
   * @param HsUtilsService
   */
  constructor(private HsUtilsService: HsUtilsService) {}

  /**
   * Test if layer is visible and has supported type (conditions for displaying legend)
   *
   * @memberof HsLegendService
   * @function isLegendable
   * @param {object} layer Layer to test
   * @returns {boolean} Return if legend might exist for layer and layer is visible
   */
  legendValid(layer: HsLegendDescriptor): boolean {
    if (layer === undefined || layer.type == undefined) {
      return false;
    }
    if (
      ['vector', 'wms', 'static'].indexOf(layer.type) > -1 &&
      layer.lyr.getVisible()
    ) {
      return true;
    }
    return false;
  }

  /**
   * Get vector layer feature geometries
   *
   * @memberof HsLegendService
   * @function getVectorFeatureGeometry
   * @param {Layer} currentLayer Layer of interest
   * @returns {Array<string>} Array of simplified lowercase names of geometry types encountered in layer
   */
  getVectorFeatureGeometry(currentLayer: Layer): string[] {
    if (currentLayer === undefined) {
      return;
    }
    let foundPoint = false;
    let foundLine = false;
    let foundPolygon = false;
    for (const feature of currentLayer.getSource().getFeatures()) {
      if (feature.getGeometry()) {
        const type = feature.getGeometry().getType();
        switch (type) {
          case 'LineString' || 'MultiLineString':
            foundLine = true;
            break;
          case 'Polygon' || 'MultiPolygon':
            foundPolygon = true;
            break;
          case 'Point' || 'MultiPoint':
            foundPoint = true;
            break;
          default:
        }
      }
    }
    const tmp = [];
    if (foundLine) {
      tmp.push('line');
    }
    if (foundPolygon) {
      tmp.push('polygon');
    }
    if (foundPoint) {
      tmp.push('point');
    }
    return tmp;
  }

  /**
   * Get vector layer styles for first 100 features
   *
   * @memberof HsLegendService
   * @function getStyleVectorLayer
   * @param {Layer} currentLayer Layer of interest
   * @returns {Array} Array of serialized unique style descriptions encountered when looping through first 100 features
   */
  getStyleVectorLayer(currentLayer: Layer): Array<any> {
    if (currentLayer === undefined) {
      return;
    }
    let styleArray = [];
    const layerStyle = currentLayer.getStyle();
    if (!this.HsUtilsService.isFunction(layerStyle)) {
      styleArray.push(layerStyle);
    } else {
      if (currentLayer.getSource().getFeatures().length > 0) {
        let featureStyle = currentLayer
          .getSource()
          .getFeatures()
          .map((feature) => currentLayer.getStyle()(feature));
        if (featureStyle.length > 1000) {
          featureStyle = featureStyle.slice(0, 100);
        }
        if (featureStyle[0].length) {
          featureStyle = [].concat.apply([], featureStyle);
        }
        styleArray = styleArray.concat(featureStyle);<commit_msg>Fix first drawn feature disappearing fixes #844<commit_after>import BaseLayer from 'ol/layer/Base';
import Static from 'ol/source/ImageStatic';
import VectorLayer from 'ol/layer/Vector';
import {Circle, Icon} from 'ol/style';
import {Fill, Image as ImageStyle, Stroke, Style} from 'ol/style';
import {HsLegendDescriptor} from './legend-descriptor.interface';
import {HsUtilsService} from '../utils/utils.service';
import {Image as ImageLayer, Layer} from 'ol/layer';
import {ImageWMS, Source} from 'ol/source';
import {Injectable} from '@angular/core';
import {TileWMS, XYZ} from 'ol/source';

@Injectable({
  providedIn: 'root',
})
export class HsLegendService {
  /**
   * @param HsUtilsService
   */
  constructor(private HsUtilsService: HsUtilsService) {}

  /**
   * Test if layer is visible and has supported type (conditions for displaying legend)
   *
   * @memberof HsLegendService
   * @function isLegendable
   * @param {object} layer Layer to test
   * @returns {boolean} Return if legend might exist for layer and layer is visible
   */
  legendValid(layer: HsLegendDescriptor): boolean {
    if (layer === undefined || layer.type == undefined) {
      return false;
    }
    if (
      ['vector', 'wms', 'static'].indexOf(layer.type) > -1 &&
      layer.lyr.getVisible()
    ) {
      return true;
    }
    return false;
  }

  /**
   * Get vector layer feature geometries
   *
   * @memberof HsLegendService
   * @function getVectorFeatureGeometry
   * @param {Layer} currentLayer Layer of interest
   * @returns {Array<string>} Array of simplified lowercase names of geometry types encountered in layer
   */
  getVectorFeatureGeometry(currentLayer: Layer): string[] {
    if (currentLayer === undefined) {
      return;
    }
    let foundPoint = false;
    let foundLine = false;
    let foundPolygon = false;
    for (const feature of currentLayer.getSource().getFeatures()) {
      if (feature.getGeometry()) {
        const type = feature.getGeometry().getType();
        switch (type) {
          case 'LineString' || 'MultiLineString':
            foundLine = true;
            break;
          case 'Polygon' || 'MultiPolygon':
            foundPolygon = true;
            break;
          case 'Point' || 'MultiPoint':
            foundPoint = true;
            break;
          default:
        }
      }
    }
    const tmp = [];
    if (foundLine) {
      tmp.push('line');
    }
    if (foundPolygon) {
      tmp.push('polygon');
    }
    if (foundPoint) {
      tmp.push('point');
    }
    return tmp;
  }

  /**
   * Get vector layer styles for first 100 features
   *
   * @memberof HsLegendService
   * @function getStyleVectorLayer
   * @param {Layer} currentLayer Layer of interest
   * @returns {Array} Array of serialized unique style descriptions encountered when looping through first 100 features
   */
  getStyleVectorLayer(currentLayer: Layer): Array<any> {
    if (currentLayer === undefined) {
      return;
    }
    let styleArray = [];
    const layerStyle = currentLayer.getStyle();
    if (!this.HsUtilsService.isFunction(layerStyle)) {
      styleArray.push(layerStyle);
    } else {
      if (currentLayer.getSource().getFeatures().length > 0) {
        let featureStyle = currentLayer
          .getSource()
          .getFeatures()
          .map((feature) => layerStyle(feature));
        if (featureStyle.length > 1000) {
          featureStyle = featureStyle.slice(0, 100);
        }
        if (featureStyle[0].length) {
          featureStyle = [].concat.apply([], featureStyle);
        }
        styleArray = styleArray.concat(featureStyle);
{'fraction_non_alphanumeric': 0.11990541104465155, 'fraction_numerical': 0.00514675198219502, 'mean_word_length': 2.7722980062959075, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '4873549', 'n_tokens_mistral': 2106, 'n_tokens_neox': 2042, 'n_words': 569}