<commit_before>spacialistApp.service('mapService', ['httpGetFactory', 'httpPostFactory', 'httpGetPromise', 'leafletData', 'userService', function(httpGetFactory, httpPostFactory, httpGetPromise, leafletData, userService) {
    var contextGeodata;
    var localContexts;
    var defaultColor = '#00FF00';
    var map = {};
    map.geodataList = [];
    map.currentGeodata = {};

    initMapVariables();
    initMap();

    function cleanName(name) {
        return getKeyForName(name.replace(/[^\x00-\x7F]/g, ''));
    }

    function getKeyForName(name) {
        return name.replace(/-/, '');
    }

    map.addLegend = function(legend) {
        map.map.legend = {};
        map.map.legend.position = 'bottomleft';
        map.map.legend.colors = [];
        map.map.legend.labels = [];
        for(var k in legend) {
            if(legend.hasOwnProperty(k)) {
                var value = legend[k];
                map.map.legend.colors.push(value.color.color);
                map.map.legend.labels.push(value.name);
            }
        }
    };

    map.addGeodata = function(type, coords) {
        var formData = new FormData();
        formData.append('type', type);
        formData.append('coords', angular.toJson(coords));
        httpPostFactory('api/context/add/geodata', formData, function(response) {
            console.log(response);
            map.addListToMarkers([
                response.geodata
            ]);
        });
    };

    map.getGeodata = function(contexts) {
        localContexts = contexts;
        httpGetFactory('api/context/get/geodata', function(response) {
            if(response.error) {
                //TODO show modal
                console.log("ERROR OCCURED");
            } else {
                var geodatas = response.geodata;
                for(var i=0; i<geodatas.length; i++) {
                    var current = geodatas[i];
                    map.geodataList.push(current);
                }
                map.addListToMarkers(map.geodataList);
            }
        });
    };

    map.addListToMarkers = function(geodataList) {
        if(!userService.can('view_geodata')) {
            return;
        }
        var defaultIcon = map.markerIcons[0].icon;
        for(var i=0; i<geodataList.length; i++) {
            var geodata = geodataList[i];
            var color, icon;
            // if(localContexts[cIndex]) {
            //     color = localContexts[cIndex].color;
            //     icon = localContexts[cIndex].icon;
            // } else {
                color = defaultColor;
                icon = defaultIcon;
            // }
            var feature = {
                type: 'Feature',
                id: geodata.id,
                geometry: geodata.geodata,
                properties: {
                    name: 'Geodata #' + geodata.id,
                    color: color,
                    icon: icon,
                    popupContent: "<div ng-include src=\"'layouts/marker.html'\"></div>"
                }
            };
            map.geoJson.addData(feature);
        }
        map.mapObject.fitBounds(map.geoJson.getBounds());
    };

    map.closePopup = function() {
        map.mapObject.closePopup();
    };

    map.openPopup = function(geodataId) {
        var alreadyFound = false;
        var layers = map.geoJson.getLayers();
        angular.forEach(layers, function(layer, key) {
            if(!alreadyFound) {
                if(layer.feature.id == geodataId) {
                    alreadyFound = true;
                    layer.openPopup();
                }
            }
        });<commit_msg>move non-point features to the back<commit_after>spacialistApp.service('mapService', ['httpGetFactory', 'httpPostFactory', 'httpGetPromise', 'leafletData', 'userService', function(httpGetFactory, httpPostFactory, httpGetPromise, leafletData, userService) {
    var contextGeodata;
    var localContexts;
    var defaultColor = '#00FF00';
    var map = {};
    map.geodataList = [];
    map.currentGeodata = {};

    initMapVariables();
    initMap();

    function cleanName(name) {
        return getKeyForName(name.replace(/[^\x00-\x7F]/g, ''));
    }

    function getKeyForName(name) {
        return name.replace(/-/, '');
    }

    map.addLegend = function(legend) {
        map.map.legend = {};
        map.map.legend.position = 'bottomleft';
        map.map.legend.colors = [];
        map.map.legend.labels = [];
        for(var k in legend) {
            if(legend.hasOwnProperty(k)) {
                var value = legend[k];
                map.map.legend.colors.push(value.color.color);
                map.map.legend.labels.push(value.name);
            }
        }
    };

    map.addGeodata = function(type, coords) {
        var formData = new FormData();
        formData.append('type', type);
        formData.append('coords', angular.toJson(coords));
        httpPostFactory('api/context/add/geodata', formData, function(response) {
            console.log(response);
            map.addListToMarkers([
                response.geodata
            ]);
        });
    };

    map.getGeodata = function(contexts) {
        localContexts = contexts;
        httpGetFactory('api/context/get/geodata', function(response) {
            if(response.error) {
                //TODO show modal
                console.log("ERROR OCCURED");
            } else {
                var geodatas = response.geodata;
                for(var i=0; i<geodatas.length; i++) {
                    var current = geodatas[i];
                    map.geodataList.push(current);
                }
                map.addListToMarkers(map.geodataList);
            }
        });
    };

    map.addListToMarkers = function(geodataList) {
        if(!userService.can('view_geodata')) {
            return;
        }
        var defaultIcon = map.markerIcons[0].icon;
        for(var i=0; i<geodataList.length; i++) {
            var geodata = geodataList[i];
            var color, icon;
            // if(localContexts[cIndex]) {
            //     color = localContexts[cIndex].color;
            //     icon = localContexts[cIndex].icon;
            // } else {
                color = defaultColor;
                icon = defaultIcon;
            // }
            var feature = {
                type: 'Feature',
                id: geodata.id,
                geometry: geodata.geodata,
                properties: {
                    name: 'Geodata #' + geodata.id,
                    color: color,
                    icon: icon,
                    popupContent: "<div ng-include src=\"'layouts/marker.html'\"></div>"
                }
            };
            map.geoJson.addData(feature);
            // workaround, because calling `bringToBack()` in the `onEachFeature` throws an error (this._map is undefined)
            var currentLayers = map.geoJson.getLayers();
            var currentLayer = currentLayers[currentLayers.length - 1];
            if(feature.geometry.type != 'Point') {
                currentLayer.bringToBack();
            }
        }
        map.mapObject.fitBounds(map.geoJson.getBounds());
    };

    map.closePopup = function() {
        map.mapObject.closePopup();
    };

    map.openPopup = function(geodataId) {
        var alreadyFound = false;
        var layers = map.geoJson.getLayers();
        angular.forEach(layers, function(layer, key) {
            if(!alreadyFound) {
                if(layer.feature.id == geodataId) {
                    alreadyFound = true;
                    layer.openPopup();
                }
            }
        });
{'fraction_non_alphanumeric': 0.12734919174661585, 'fraction_numerical': 0.0027598896044158236, 'mean_word_length': 1.6088447034624613, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '302150', 'n_tokens_mistral': 2257, 'n_tokens_neox': 2146, 'n_words': 348}