<commit_before>import { mainLizmap } from './Globals.js';

import { Vector as VectorSource } from 'ol/source';
import { Vector as VectorLayer } from 'ol/layer';

import WKT from 'ol/format/WKT';

export default class Layers {

    constructor() {}

    /**
     * Add a vector layer from a WKT.
     * @param {string} wkt WKT in EPSG:4326 projection
     * @memberof Layers
     */
    addLayerFromWKT(wkt){
        if(!wkt){return;}

        const format = new WKT();
        const feature = format.readFeature(wkt, {
            dataProjection: 'EPSG:4326',
            featureProjection: mainLizmap.projection,
        });

        const vector = new VectorLayer({
            source: new VectorSource({
                features: [feature],
            }),
        });

        mainLizmap.map._olMap.addLayer(vector);

        return vector;
    }

    /**
     * Removes the given layer from the map.
     * @param {import("ol/layer/Base").default} layer OL layer to remove
     * @memberof Layers
     */
    removeLayer(layer){
        if (!layer){return;}

        for (const _layer of mainLizmap.map._olMap.getLayers().getArray()) {
            if (_layer === layer) {
                mainLizmap.map._olMap.removeLayer(layer);
            }
        }
    }
}
<commit_msg>Add addLayerFromGeoJSON() based on OL6<commit_after>import { mainLizmap } from './Globals.js';

import { Vector as VectorSource } from 'ol/source';
import { Vector as VectorLayer } from 'ol/layer';

import WKT from 'ol/format/WKT';
import GeoJSON from 'ol/format/GeoJSON';

export default class Layers {

    constructor() {}

    /**
     * Add a vector layer from a WKT.
     * @param {string} wkt WKT in EPSG:4326 projection
     * @memberof Layers
     */
    addLayerFromWKT(wkt){
        const format = new WKT();
        const feature = format.readFeature(wkt, {
            dataProjection: 'EPSG:4326',
            featureProjection: mainLizmap.projection,
        });

        const vector = new VectorLayer({
            source: new VectorSource({
                features: [feature],
            }),
        });

        mainLizmap.map._olMap.addLayer(vector);

        return vector;
    }

    /**
     * Add a vector layer from a GeoJSON.
     * @param {ArrayBuffer|Document|Element|Object|string} geojson geojson in EPSG:4326 projection
     * @memberof Layers
     */
    addLayerFromGeoJSON(geojson) {
        const vector = new VectorLayer({
            source: new VectorSource({
                features: new GeoJSON().readFeatures(geojson, {
                    dataProjection: 'EPSG:4326',
                    featureProjection: mainLizmap.projection
                }),
            }),
        });

        mainLizmap.map._olMap.addLayer(vector);

        return vector;
    }

    /**
     * Removes the given layer from the map.
     * @param {import("ol/layer/Base").default} layer OL layer to remove
     * @memberof Layers
     */
    removeLayer(layer){
        for (const _layer of mainLizmap.map._olMap.getLayers().getArray()) {
            if (_layer === layer) {
                mainLizmap.map._olMap.removeLayer(layer);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.11532385466034756, 'fraction_numerical': 0.007898894154818325, 'mean_word_length': 1.9896128423040604, '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': '5258482', 'n_tokens_mistral': 989, 'n_tokens_neox': 926, 'n_words': 227}