aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131/hw3/contacts.js
blob: 68d573191df1ba5e77e4d4f237de09ef484a718b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
document.getElementById("bigboi").classList.add("isntRotating");

function change(small, row) {
    document.getElementsByClassName("smol")[row].src = small;
}
function lucky() {
    var image = ["carlson.jpg", "johnston.jpg", "morrill.jpg", "shepherd.jpg", "snyder.jpg", "walter.jpg"];
    document.getElementById("bigboi").src = image[Math.floor(6 * Math.random())];
}
let isRotating=0;
function dizzy() {
    if (!isRotating) {
        document.getElementById("bigboi").classList.remove("isntRotating");
    } else {
    	document.getElementById("bigboi").classList.add("isntRotating");
    }
    isRotating^=1;   
}
function check(value) {
    if(value==="Other")
        document.getElementById('others').style.display = 'block';
    else
        document.getElementById('others').style.display = 'none';
}
let map;
var center = { lat: 44.9727, lng: -93.23540000000003 };
function initMap() {
    map = new google.maps.Map(document.getElementById("map"), {
        center: center,
        zoom: 14,
    });

    var service = new google.maps.places.PlacesService(map);
    entries = document.getElementsByClassName("entry");
    locations = [];
    for (e=0; e<entries.length; e+=1) {
        var kludge = 0;
        var request = {
            query: entries[e].getElementsByClassName("address")[0].textContent,
            fields: ['name', 'geometry'],
        };
        service.findPlaceFromQuery(request, function (results, status) {
            if (status === google.maps.places.PlacesServiceStatus.OK) {
                locations[kludge++] = results[0];
            }
            if (kludge == entries.length) {
                addPointsContacts(locations);
            }
        });
    }
}
function addPointsContacts(locations) {
    for (x in locations) {
        var newEntry = document.getElementsByClassName("entry")[x];
        var marker = new google.maps.Marker({
            map,
            position: locations[x].geometry.location,
            title: newEntry.getElementsByClassName("name")[0].textContent,
            icon: "./Untitled.png",
            data: {
                content:    "<div class='id'>" + 
                            "<b>" + newEntry.getElementsByClassName("name")[0].textContent + "</b>" + "<br>" +
                            newEntry.getElementsByClassName("category")[0].textContent + "<br>" +
                            newEntry.getElementsByClassName("room")[0].textContent + " " + newEntry.getElementsByClassName("street")[0].textContent + "<br>" +
                            newEntry.getElementsByClassName("city")[0].textContent + 
                            "</div>",
            },
        });
        marker.addListener('click', function () {
            if (!this.infoWindow) {
                this.infoWindow = new google.maps.InfoWindow({
                    content: this.data.content,
                });
                this.infoWindow.open(map, this);
            }
        })
    }
}
var service;
var otherRadius;
var searchMarker = [];
function searchPlaces() {
    var request;
    if (document.getElementById("places").value!="Other") {
        request = {
            location: center,
            radius: document.getElementById("distance").value,
            type: document.getElementById("places").value,
        };
        service = new google.maps.places.PlacesService(map);
        service.nearbySearch(request, (results, status) => {
            if (status === google.maps.places.PlacesServiceStatus.OK && results) {
                addPointsSearch(results, false);
            }
        });
    } else {
        request = {
            location: center,
            radius: document.getElementById("distance").value,
            query: document.getElementById("others").value,
        };
        otherRadius = request.radius;
        service = new google.maps.places.PlacesService(map);
        service.textSearch(request, (results, status) => {
            if (status === google.maps.places.PlacesServiceStatus.OK && results) {
                addPointsSearch(results, true);
            }
        });
    }
}

function addPointsSearch(locations, isOther) {
    deleteMarkers();
    for (x in locations) {
        var marker;
        if (isOther) {
            if (google.maps.geometry.spherical.computeDistanceBetween(locations[x].geometry.location, map.getCenter()) < parseInt(otherRadius)) {
                marker = new google.maps.Marker({
                    map,
                    title: locations[x].name,
                    position: locations[x].geometry.location,
                    data: {
                        content: "<b>" + locations[x].name + "</b>"
                            + "<br>" + locations[x].formatted_address
                    },
                });
            }
        } else {
            marker = new google.maps.Marker({
                map,
                title: locations[x].name,
                position: locations[x].geometry.location,
                data: {
                    content: "<b>" + locations[x].name + "</b>"
                        + "<br>" + locations[x].vicinity
                },
            });
        }
        if (marker) {
            marker.addListener('click', function () {
                if (!this.infoWindow) {
                    this.infoWindow = new google.maps.InfoWindow({
                        content: this.data.content,
                    });
                    this.infoWindow.open(map, this);
                }
            })
            searchMarker.push(marker);
        }
        
    }
}
function deleteMarkers() {
    for (let i = 0; i < searchMarker.length; i++) {
        searchMarker[i].setMap(null);
    }
    searchMarker = [];
}

function directions () {
    
}