<commit_before>var Backbone = require('backbone'),
    template = require("../templates/map.hbs"),
    service = require('../models/service'),
    servicetype = require('../models/servicetype'),
    hashtrack = require('hashtrack'),
    i18n = require('i18next-client'),
    search = require('../search')
;


module.exports = Backbone.View.extend({
    feedback: false,

    initialize: function(params){
        var self = this;
        this.feedback = params.hasOwnProperty('feedback');
        this.query = "";
        this.services = new service.PublicServices();
        this.servicetypes = new servicetype.ServiceTypes();
        //this.render();
        this.markers = [];
    },

    render: function() {
        var $el = this.$el;

        var self=this;
        this.$el.html(template({
            services: this.services,
            query: hashtrack.getVar('q'),
            feedback: this.feedback
        }));
        $('.no-search-results').hide();

        var $scv = this.$el.find('#search_controls');
        var SearchControlView = new search.SearchControls({
            $el: $scv,
            feedback: this.feedback
        });
        SearchControlView.render();

        function initialize() {
            var mapOptions = {
                center: { lat: 33.8869, lng: 35.5131},
                zoom: 8
            };
            self.map = new google.maps.Map(document.getElementById('map_canvas'),
                mapOptions);
            search.refetchServices(self.query).then(function(){
                self.updateResults();
            });
        }

        initialize();
    },

    updateResults: function() {
        var self = this;
        $.each(self.markers, function() {
            this.setMap(null);
        });
        self.markers = [];
        var bounds = new google.maps.LatLngBounds();
        var services = search.services.data();
        if (services.length === 0) {
            $('.no-search-results').show();
            $('#map_container').hide();
            return;
        }
        $('.no-search-results').hide();
        $('#map_container').show();
        $.each(services, function() {
            var service = this;

            // this.location, from PostGIS, is in the form POINT(LONG LAT)
            // Google Maps API's LatLng() constructor expects LAT, LONG parameters
            var long_lat_str = /(-?\d+\.\d+) (-?\d+\.\d+)/.exec(this.location);
            if (long_lat_str) {
                var myLatlng = new google.maps.LatLng(long_lat_str[2], long_lat_str[1]);
                bounds.extend(myLatlng);
                var marker = new google.maps.Marker({
                    position: myLatlng,
                    title: this.name,
                    icon: new google.maps.MarkerImage(
                        this.servicetype.icon_url,
                        null,
                        null,
                        new google.maps.Point(12, 12),
                        new google.maps.Size(24, 24)
                    ),
                });
                window.marker = marker;
                marker.setMap(self.map);
                self.markers.push(marker);
                google.maps.event.addListener(marker, 'click', function() {
                    location.hash = '#/service/' + service.id;
                })
            }
        });
        self.map.fitBounds(bounds);
        var zoom = self.map.getZoom();
        if (zoom > 10) {
            self.map.setZoom(10);
        }
    },

    events: {
        "search": function(_, query) {
            $('.spinner').show();
            var self = this;
            search.refetchServices().then(function(){
                self.updateResults();
                $('.spinner').hide();
            })
        },
        "input input.query": function(e) {
            var query = $(e.target).val();
            hashtrack.setVar('q', query);
        },
        "change .query-service-type": function(e) {<commit_msg>455 Limit view in initial map display<commit_after>var Backbone = require('backbone'),
    template = require("../templates/map.hbs"),
    service = require('../models/service'),
    servicetype = require('../models/servicetype'),
    hashtrack = require('hashtrack'),
    i18n = require('i18next-client'),
    search = require('../search')
;


module.exports = Backbone.View.extend({
    feedback: false,

    initialize: function(params){
        var self = this;
        this.feedback = params.hasOwnProperty('feedback');
        this.query = "";
        this.services = new service.PublicServices();
        this.servicetypes = new servicetype.ServiceTypes();
        //this.render();
        this.markers = [];
    },

    render: function() {
        var $el = this.$el;

        var self=this;
        this.$el.html(template({
            services: this.services,
            query: hashtrack.getVar('q'),
            feedback: this.feedback
        }));
        $('.no-search-results').hide();

        var $scv = this.$el.find('#search_controls');
        var SearchControlView = new search.SearchControls({
            $el: $scv,
            feedback: this.feedback
        });
        SearchControlView.render();

        function initialize() {
            var mapOptions = {
                center: { lat: 33.8869, lng: 35.5131},
                zoom: 10
            };
            self.map = new google.maps.Map(document.getElementById('map_canvas'),
                mapOptions);
            search.refetchServices(self.query).then(function(){
                self.updateResults();
            });
        }

        initialize();
    },

    updateResults: function() {
        var self = this;
        $.each(self.markers, function() {
            this.setMap(null);
        });
        self.markers = [];
        var services = search.services.data();
        if (services.length === 0) {
            $('.no-search-results').show();
            $('#map_container').hide();
            return;
        }
        $('.no-search-results').hide();
        $('#map_container').show();
        $.each(services, function() {
            var service = this;

            // this.location, from PostGIS, is in the form POINT(LONG LAT)
            // Google Maps API's LatLng() constructor expects LAT, LONG parameters
            var long_lat_str = /(-?\d+\.\d+) (-?\d+\.\d+)/.exec(this.location);
            if (long_lat_str) {
                var myLatlng = new google.maps.LatLng(long_lat_str[2], long_lat_str[1]);
                var marker = new google.maps.Marker({
                    position: myLatlng,
                    title: this.name,
                    icon: new google.maps.MarkerImage(
                        this.servicetype.icon_url,
                        null,
                        null,
                        new google.maps.Point(12, 12),
                        new google.maps.Size(24, 24)
                    ),
                });
                window.marker = marker;
                marker.setMap(self.map);
                self.markers.push(marker);
                google.maps.event.addListener(marker, 'click', function() {
                    location.hash = '#/service/' + service.id;
                })
            }
        });
    },

    events: {
        "search": function(_, query) {
            $('.spinner').show();
            var self = this;
            search.refetchServices().then(function(){
                self.updateResults();
                $('.spinner').hide();
            })
        },
        "input input.query": function(e) {
            var query = $(e.target).val();
            hashtrack.setVar('q', query);
        },
        "change .query-service-type": function(e) {
{'fraction_non_alphanumeric': 0.14548516647234097, 'fraction_numerical': 0.00829122943386449, 'mean_word_length': 1.5048669695003245, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 4, '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': '880690', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2034, 'n_words': 391}