Project

General

Profile

1
$(function() {
2
    altair_search_page.init_map();
3
});
4

    
5
altair_search_page = {
6
    init_map: function() {
7

    
8
        // set min height for map
9
        function updateheight() {
10
            $('#map_search').css({
11
                minHeight: $window.height() - $('#header_main').height() - 59
12
            });
13
        }
14
        updateheight();
15

    
16
    // create map and markers
17

    
18
        var $map_search = $('#map_search'),
19
            $map_search_list = $('#map_search_list').children('li'),
20
            marker_url = isHighDensity() ? 'assets/img/md-images/ic_place_red_48dp.png' : 'assets/img/md-images/ic_place_red_24dp.png',
21
            marker_size = isHighDensity() ? new google.maps.Size(48, 48) : new google.maps.Size(24, 24),
22
            marker_scaled_size = new google.maps.Size(24, 24),
23
            marker_zoom = 12,
24
            locations_data = [];
25

    
26
        // get locations from data atributes
27
        $map_search_list.each(function () {
28
            var $this = $(this),
29
                locations = {
30
                    lat: $this.attr('data-gmap-lat'),
31
                    lon: $this.attr('data-gmap-lon'),
32
                    title: $this.attr('data-gmap-company'),
33
                    html: '<div class="gmap-info-window" style="max-width: 180px;">'
34
                    + '<h3>' + $this.attr('data-gmap-company') + '</h3>'
35
                    + '<p>' + $this.attr('data-gmap-company-address') + '</p>'
36
                    + '<p class="uk-margin-small-top"><a target="_blank" href="https://www.google.com/maps/dir/Current+Location/'+$this.attr('data-gmap-lat') +','+$this.attr('data-gmap-lon')+'">Get Directions</a></p>'
37
                    + '</div>',
38
                    zoom: marker_zoom,
39
                    icon: {
40
                        url: marker_url,
41
                        size: marker_size,
42
                        scaledSize: marker_scaled_size
43
                    }
44
                };
45
            locations_data.push(locations);
46
        });
47

    
48
        // init map
49
        var mapSearch = new Maplace({
50
            map_div: '#map_search',
51
            locations: locations_data,
52
            controls_on_map: false,
53
            map_options: {
54
                set_center: [40.85167, -93.259932],
55
                zoom: 12,
56
                streetViewControl: false
57
            },
58
            styles: {
59
                'Blue water': [{
60
                    "featureType": "water",
61
                    "stylers": [{"color": "#46bcec"}, {"visibility": "on"}]
62
                }, {"featureType": "landscape", "stylers": [{"color": "#f2f2f2"}]}, {
63
                    "featureType": "road",
64
                    "stylers": [{"saturation": -100}, {"lightness": 45}]
65
                }, {
66
                    "featureType": "road.highway",
67
                    "stylers": [{"visibility": "simplified"}]
68
                }, {
69
                    "featureType": "road.arterial",
70
                    "elementType": "labels.icon",
71
                    "stylers": [{"visibility": "off"}]
72
                }, {
73
                    "featureType": "administrative",
74
                    "elementType": "labels.text.fill",
75
                    "stylers": [{"color": "#444444"}]
76
                }, {"featureType": "transit", "stylers": [{"visibility": "off"}]}, {
77
                    "featureType": "poi",
78
                    "stylers": [{"visibility": "off"}]
79
                }]
80
            }
81
        }).Load();
82

    
83
        // jump to marker
84
        var enterTimeout;
85
        $map_search_list
86
            .on('click', function (e) {
87
                e.preventDefault();
88
                var $this = $(this),
89
                    $this_index = $this.index();
90
                $this
91
                    .addClass('md-list-item-active')
92
                    .siblings()
93
                    .removeClass('md-list-item-active');
94

    
95
                mapSearch.ViewOnMap($this_index+1);
96
            });
97
            // uncoment this code to show marker on mouseenter
98
            /*.on('mouseenter', function (e) {
99
                e.preventDefault();
100
                clearTimeout(enterTimeout);
101
                var $this = $(this),
102
                    $this_index = $this.index();
103

    
104
                enterTimeout = setTimeout(function() {
105
                    $map_search_list.removeClass('md-list-item-active');
106
                    //mapSearch.ViewOnMap($this_index+1);
107
                    google.maps.event.trigger(mapSearch.markers[$this_index], 'click');
108
                },300)
109

    
110
            });*/
111

    
112
        function updateMap() {
113
            var gmap_search = mapSearch.oMap;
114
            google.maps.event.trigger(gmap_search, 'resize');
115
            gmap_search.fitBounds(mapSearch.oBounds);
116
        }
117

    
118
        // update/init map when it become visible
119
        $(".map_search_wrapper").on('display.uk.check', function(){
120
            updateMap();
121
        });
122

    
123
        // resize map on window resize event
124
        $(window).on('debouncedresize', function () {
125
            updateheight();
126
            updateMap();
127
        });
128

    
129
        // show/hide map search list
130
        $('#map_search_list_toggle').on('click', function(e) {
131
            e.preventDefault();
132
            $('.map_search_wrapper').toggleClass('map_search_list_active');
133
            setTimeout(function() {
134
                updateMap();
135
            },290)
136
        })
137

    
138
    }
139
};
(61-61/114)