-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
56 lines (56 loc) · 2.09 KB
/
script.js
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
$(document).ready(function() {
let ip = "";
var redIcon = new L.Icon({
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
var blueIcon = new L.Icon({
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-blue.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
$.getJSON("https://api.ipify.org?format=json", function(data) {
ip = data.ip;
});
$.ajax({
url: "https://ipapi.co/" + ip + "/json/",
async: false,
dataType: "json",
success: function(data) {
var southWest = L.latLng(-89.98155760646617, -180),
northEast = L.latLng(89.99346179538875, 180);
var bounds = L.latLngBounds(southWest, northEast);
var map = L.map('map', {
center: bounds.getCenter(),
maxBounds: bounds,
maxBoundsViscosity: 1.0,
minZoom: 1
}).setView([data.latitude, data.longitude], 10);
var lat = data.latitude;
var long = data.longitude;
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
$.ajax({
url: "https://geostore.supremestdoggo.repl.co/?lat=" + data.latitude.toString() + "&long=" + data.longitude.toString(),
method: "POST"
})
$.getJSON("https://geostore.supremestdoggo.repl.co/", function(data) {
for (let i = 0; i < data.length; i++) {
let isHere = data[i].latitude == lat && data[i].longitude == long;
L.marker([data[i].latitude, data[i].longitude], {
icon: isHere ? redIcon : blueIcon
}).addTo(map);
}
});
}
})
})