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

export default class Snapping {

    constructor() {

        this._active = false;
        this._maxFeatures = 1000;
        this._restrictToMapExtent = true;
        this._config = undefined;

        // Create layer to store snap features
        const snapLayer = new OpenLayers.Layer.Vector('snaplayer', {
            visibility: false,
            styleMap: new OpenLayers.StyleMap({
                pointRadius: 2,
                fill: false,
                stroke: true,
                strokeWidth: 3,
                strokeColor: 'red',
                strokeOpacity: 0.8
            })
        });

        mainLizmap.lizmap3.map.addLayer(snapLayer);

        const snapControl = new OpenLayers.Control.Snapping({
            layer: mainLizmap.edition.editLayer,
            targets: [{
                layer: snapLayer
            }]
        });
        mainLizmap.lizmap3.map.addControls([snapControl]);
        mainLizmap.lizmap3.controls['snapControl'] = snapControl;

        // Activate snap when a layer is edited
        mainEventDispatcher.addListener(
            () => {
                // Get snapping configuration for edited layer
                for (const editionLayer in mainLizmap.config.editionLayers) {
                    if (mainLizmap.config.editionLayers.hasOwnProperty(editionLayer)) {
                        if (mainLizmap.config.editionLayers[editionLayer].layerId === mainLizmap.edition.layerId){
                            const editionLayerConfig = mainLizmap.config.editionLayers[editionLayer];
                            if (editionLayerConfig.hasOwnProperty('snap_layers')){
                                this.config = {
                                    'snap_layers': editionLayerConfig.snap_layers.split(','),
                                    'snap_vertices': editionLayerConfig.snap_vertices === 'True' ? true : false,
                                    'snap_segments': editionLayerConfig.snap_segments === 'True' ? true : false,
                                    'snap_intersections': editionLayerConfig.snap_intersections === 'True' ? true : false,
                                    'snap_vertices_tolerance': editionLayerConfig.snap_vertices_tolerance,
                                    'snap_segments_tolerance': editionLayerConfig.snap_segments_tolerance,
                                    'snap_intersections_tolerance': editionLayerConfig.snap_intersections_tolerance
                                };
                            }
                        }
                    }
                }

                if (this._config !== undefined){
                    // Empty snapping layer first
                    mainLizmap.lizmap3.map.getLayersByName('snaplayer')[0].destroyFeatures();

                    for (const snapLayer of this._config.snap_layers) {
<commit_msg>[Snapping] add tests on config params<commit_after>import { mainLizmap, mainEventDispatcher } from '../modules/Globals.js';

export default class Snapping {

    constructor() {

        this._active = false;
        this._maxFeatures = 1000;
        this._restrictToMapExtent = true;
        this._config = undefined;

        // Create layer to store snap features
        const snapLayer = new OpenLayers.Layer.Vector('snaplayer', {
            visibility: false,
            styleMap: new OpenLayers.StyleMap({
                pointRadius: 2,
                fill: false,
                stroke: true,
                strokeWidth: 3,
                strokeColor: 'red',
                strokeOpacity: 0.8
            })
        });

        mainLizmap.lizmap3.map.addLayer(snapLayer);

        const snapControl = new OpenLayers.Control.Snapping({
            layer: mainLizmap.edition.editLayer,
            targets: [{
                layer: snapLayer
            }]
        });
        mainLizmap.lizmap3.map.addControls([snapControl]);
        mainLizmap.lizmap3.controls['snapControl'] = snapControl;

        // Activate snap when a layer is edited
        mainEventDispatcher.addListener(
            () => {
                // Get snapping configuration for edited layer
                for (const editionLayer in mainLizmap.config.editionLayers) {
                    if (mainLizmap.config.editionLayers.hasOwnProperty(editionLayer)) {
                        if (mainLizmap.config.editionLayers[editionLayer].layerId === mainLizmap.edition.layerId){
                            const editionLayerConfig = mainLizmap.config.editionLayers[editionLayer];
                            if (editionLayerConfig.hasOwnProperty('snap_layers')){
                                this.config = {
                                    'snap_layers': editionLayerConfig.snap_layers.split(','),
                                    'snap_vertices': (editionLayerConfig.hasOwnProperty('snap_vertices') && editionLayerConfig.snap_vertices === 'True') ? true : false,
                                    'snap_segments': (editionLayerConfig.hasOwnProperty('snap_segments') && editionLayerConfig.snap_segments === 'True') ? true : false,
                                    'snap_intersections': (editionLayerConfig.hasOwnProperty('snap_intersections') && editionLayerConfig.snap_intersections === 'True') ? true : false,
                                    'snap_vertices_tolerance': editionLayerConfig.hasOwnProperty('snap_vertices_tolerance') ? editionLayerConfig.snap_vertices_tolerance : 10,
                                    'snap_segments_tolerance': editionLayerConfig.hasOwnProperty('snap_segments_tolerance') ? editionLayerConfig.snap_segments_tolerance : 10,
                                    'snap_intersections_tolerance': editionLayerConfig.hasOwnProperty('snap_intersections_tolerance') ? editionLayerConfig.snap_intersections_tolerance : 10
                                };
                            }
                        }
                    }
                }

                if (this._config !== undefined){
                    // Empty snapping layer first
                    mainLizmap.lizmap3.map.getLayersByName('snaplayer')[0].destroyFeatures();

                    for (const snapLayer of this._config.snap_layers) {

{'fraction_non_alphanumeric': 0.08833809977756593, 'fraction_numerical': 0.005084207181442644, 'mean_word_length': 1.6651143099068586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '641974', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1520, 'n_words': 262}