<commit_before>define "app/map", ['leaflet', 'proj4leaflet', 'backbone', 'backbone.marionette', 'leaflet.markercluster', 'i18next', 'app/widgets', 'app/models', 'app/p13n', 'app/jade'], (leaflet, p4j, Backbone, Marionette, markercluster, i18n, widgets, models, p13n, jade) ->
    ICON_SIZE = 40
    if get_ie_version() and get_ie_version() < 9
        ICON_SIZE *= .8
    MARKER_POINT_VARIANT = false

    class MapView extends Backbone.Marionette.View
        tagName: 'div'
        initialize: (opts) ->
            @navigation_layout = opts.navigation_layout
            @units = opts.units
            @user_click_coordinate_position = opts.user_click_coordinate_position
            @selected_services = opts.services
            @search_results = opts.search_results
            @selected_units = opts.selected_units
            #@listenTo @units, 'add', @draw_units
            @listenTo @units, 'finished', =>
            # Triggered when all of the
            # pages of units have been fetched.
                unless @selected_services.isEmpty()
                    @draw_units @units
                    @refit_bounds()
            @listenTo @user_click_coordinate_position, 'change:value', (model, current) =>
                previous = model.previous 'value'
                if previous?
                    @stopListening previous
                @listenTo current, 'request', =>
                    @map.once 'click', (e) =>
                        current.set 'position',
                            coords:
                                latitude: e.latlng.lat
                                longitude: e.latlng.lng

            @listenTo @units, 'unit:highlight', @highlight_unselected_unit
            @listenTo @units, 'batch-remove', @remove_units
            @listenTo @units, 'remove', @remove_unit
            @listenTo @units, 'reset', =>
                @all_markers.clearLayers()
                @units.each (unit) => @draw_unit(unit)
                unless @units.isEmpty()
                    @refit_bounds()
            @listenTo @selected_units, 'reset', (units, options) ->
                @clear_popups(true)
                if units.isEmpty()
                    return
                unit = units.first()
                if not unit.marker?
                    @draw_unit unit
                    @refit_bounds true
                @highlight_selected_unit unit

            @listenTo p13n, 'position', @handle_user_position

        get_max_auto_zoom: ->
            if p13n.get('map_background_layer') == 'guidemap'
                7
            else
                12

        handle_user_position: (position_object) ->
            pos = position_object.get 'position'
            lat_lng = L.latLng [pos.coords.latitude, pos.coords.longitude]
            accuracy = pos.coords.accuracy
            radius = 4
            if not @user_position_markers?
                opts =
                    weight: 0
                accuracy_marker = L.circle lat_lng, accuracy, opts
                @map.addLayer accuracy_marker
                opts =
                    color: '#ff0000'
                    radius: radius
                marker = L.circleMarker lat_lng, opts
                @map.addLayer marker
                @user_position_markers =
                    accuracy: accuracy_marker
                    position: marker
            else
                pm = @user_position_markers
                pm.accuracy.setLatLng lat_lng
                pm.accuracy.setRadius radius
                pm.position.setLatLng lat_lng

        render: ->
            @$el.attr 'id', 'map'
        width: ->
            @$el.width()
        height: ->
            @$el.height()
        to_coordinates: (windowCoordinates) ->
            @map.layerPointToLatLng(@map.containerPointToLayerPoint(windowCoordinates))

        clear_popups: (clear_selected) ->
            @popups.eachLayer (layer) =>
                if clear_selected
                    layer.selected = false
                    @popups.removeLayer layer
                else unless layer.selected
                    @popups.removeLayer layer

        remove_units: (options) ->
            @all_markers.clearLayers()
            @draw_units @units
            unless @selected_units.isEmpty()
                @highlight_selected_unit @selected_units.first()

        remove_unit: (unit, units, options) ->
            if unit.marker?
                @all_markers.removeLayer unit.marker
                delete unit.marker

        create_icon: (unit, services) ->
            color = app.color_matcher.unit_color(unit) or 'rgb(255, 255, 255)'
            if MARKER_POINT_VARIANT
                ctor = widgets.PointCanvasIcon
            else
                ctor = widgets.PlantCanvasIcon
            new ctor ICON_SIZE, color, unit.id

        create_cluster_icon: (cluster) ->
            count = cluster.getChildCount()
            service_collection = new models.ServiceList()
            if not @selected_services.isEmpty()
                service_collection.add @selected_services.last()
            markers = cluster.getAllChildMarkers()
            _.each markers, (marker) =>
                unless marker.unit?
                    return
                unless @selected_services.isEmpty()
                    service = @selected_services.find (s) =>
                        s.get('root') in marker.unit.get('root_services')
                else
                    service = new models.Service
                        id: marker.unit.get('root_services')[0]
                        root: marker.unit.get('root_services')[0]
                service_collection.add service

            colors = service_collection.map (service) =>
                app.color_matcher.service_color(service)<commit_msg>Bugfix: don't always add the last service to cluster color array.<commit_after>define "app/map", ['leaflet', 'proj4leaflet', 'backbone', 'backbone.marionette', 'leaflet.markercluster', 'i18next', 'app/widgets', 'app/models', 'app/p13n', 'app/jade'], (leaflet, p4j, Backbone, Marionette, markercluster, i18n, widgets, models, p13n, jade) ->
    ICON_SIZE = 40
    if get_ie_version() and get_ie_version() < 9
        ICON_SIZE *= .8
    MARKER_POINT_VARIANT = false

    class MapView extends Backbone.Marionette.View
        tagName: 'div'
        initialize: (opts) ->
            @navigation_layout = opts.navigation_layout
            @units = opts.units
            @user_click_coordinate_position = opts.user_click_coordinate_position
            @selected_services = opts.services
            @search_results = opts.search_results
            @selected_units = opts.selected_units
            #@listenTo @units, 'add', @draw_units
            @listenTo @units, 'finished', =>
            # Triggered when all of the
            # pages of units have been fetched.
                unless @selected_services.isEmpty()
                    @draw_units @units
                    @refit_bounds()
            @listenTo @user_click_coordinate_position, 'change:value', (model, current) =>
                previous = model.previous 'value'
                if previous?
                    @stopListening previous
                @listenTo current, 'request', =>
                    @map.once 'click', (e) =>
                        current.set 'position',
                            coords:
                                latitude: e.latlng.lat
                                longitude: e.latlng.lng

            @listenTo @units, 'unit:highlight', @highlight_unselected_unit
            @listenTo @units, 'batch-remove', @remove_units
            @listenTo @units, 'remove', @remove_unit
            @listenTo @units, 'reset', =>
                @all_markers.clearLayers()
                @units.each (unit) => @draw_unit(unit)
                unless @units.isEmpty()
                    @refit_bounds()
            @listenTo @selected_units, 'reset', (units, options) ->
                @clear_popups(true)
                if units.isEmpty()
                    return
                unit = units.first()
                if not unit.marker?
                    @draw_unit unit
                    @refit_bounds true
                @highlight_selected_unit unit

            @listenTo p13n, 'position', @handle_user_position

        get_max_auto_zoom: ->
            if p13n.get('map_background_layer') == 'guidemap'
                7
            else
                12

        handle_user_position: (position_object) ->
            pos = position_object.get 'position'
            lat_lng = L.latLng [pos.coords.latitude, pos.coords.longitude]
            accuracy = pos.coords.accuracy
            radius = 4
            if not @user_position_markers?
                opts =
                    weight: 0
                accuracy_marker = L.circle lat_lng, accuracy, opts
                @map.addLayer accuracy_marker
                opts =
                    color: '#ff0000'
                    radius: radius
                marker = L.circleMarker lat_lng, opts
                @map.addLayer marker
                @user_position_markers =
                    accuracy: accuracy_marker
                    position: marker
            else
                pm = @user_position_markers
                pm.accuracy.setLatLng lat_lng
                pm.accuracy.setRadius radius
                pm.position.setLatLng lat_lng

        render: ->
            @$el.attr 'id', 'map'
        width: ->
            @$el.width()
        height: ->
            @$el.height()
        to_coordinates: (windowCoordinates) ->
            @map.layerPointToLatLng(@map.containerPointToLayerPoint(windowCoordinates))

        clear_popups: (clear_selected) ->
            @popups.eachLayer (layer) =>
                if clear_selected
                    layer.selected = false
                    @popups.removeLayer layer
                else unless layer.selected
                    @popups.removeLayer layer

        remove_units: (options) ->
            @all_markers.clearLayers()
            @draw_units @units
            unless @selected_units.isEmpty()
                @highlight_selected_unit @selected_units.first()

        remove_unit: (unit, units, options) ->
            if unit.marker?
                @all_markers.removeLayer unit.marker
                delete unit.marker

        create_icon: (unit, services) ->
            color = app.color_matcher.unit_color(unit) or 'rgb(255, 255, 255)'
            if MARKER_POINT_VARIANT
                ctor = widgets.PointCanvasIcon
            else
                ctor = widgets.PlantCanvasIcon
            new ctor ICON_SIZE, color, unit.id

        create_cluster_icon: (cluster) ->
            count = cluster.getChildCount()
            service_collection = new models.ServiceList()
            markers = cluster.getAllChildMarkers()
            _.each markers, (marker) =>
                unless marker.unit?
                    return
                if @selected_services.isEmpty()
                    service = new models.Service
                        id: marker.unit.get('root_services')[0]
                        root: marker.unit.get('root_services')[0]
                else
                    service = @selected_services.find (s) =>
                        s.get('root') in marker.unit.get('root_services')
                service_collection.add service

            colors = service_collection.map (service) =>
                app.color_matcher.service_color(service)

{'fraction_non_alphanumeric': 0.08963488492818827, 'fraction_numerical': 0.006575532098979062, 'mean_word_length': 1.4992432432432432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '3046116', 'n_tokens_mistral': 3151, 'n_tokens_neox': 2928, 'n_words': 630}