-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
128 lines (100 loc) · 3.1 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=geometry,places"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/geocomplete/1.6.5/jquery.geocomplete.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map_div {
height: 100%;
}
</style>
</head>
<body>
<div id="location_container"class="jumbotron">
<div class="container">
<p>w11 2ed - soon</p>
<p>w10 5nr - live</p>
<p>sw19 5aw - not live and not coming soon</p>
<input id="location" placeholder="" type="text" class="form-control" autocomplete="off">
<div id="result"></div>
</div>
</div>
<div id="map_div"></div>
<script>
var marker;
function initialize() {
var map = new google.maps.Map(document.getElementById('map_div'), {
center: new google.maps.LatLng(51.5072, -0.1275),
zoom: 12,
mapTypeId: google.maps.MapTypeId.TERRAIN
});
initGeocompleteControl(map, function(result) {
if (!marker || !marker.setPosition) {
marker = new google.maps.Marker({
position: result.geometry.location,
map: map
});
} else {
marker.setPosition(result.geometry.location);
}
var inPolygon = false;
map.data.forEach(function(f) {
if (f.getProperty("key") == "live") {
var bounds = new google.maps.LatLngBounds();
calcBounds(f.getGeometry(), bounds);
if (bounds.contains(result.geometry.location)) {
$("#result").empty();
$("#result").html('Location is found and is live');
console.log('Location is found and is live');
inPolygon = true;
}
} else if (f.getProperty("key") == "soon") {
var bounds = new google.maps.LatLngBounds();
calcBounds(f.getGeometry(), bounds);
if (bounds.contains(result.geometry.location)) {
$("#result").empty();
$("#result").html('Location is found and is coming soon');
console.log('Location is found and is coming soon');
inPolygon = true;
}
}
});
if (!inPolygon) {
$("#result").empty();
$("#result").html('Location is not found');
console.log('Location is not found')
}
});
map.data.loadGeoJson('polygon-data.json');
}
function initGeocompleteControl(map, complete) {
var option = {
//types: ['(cities)']
country: 'GB'
};
$("#location").geocomplete(option).bind("geocode:result", function(event, result) {
complete(result);
});
}
function calcBounds(geometry, bounds) {
if (geometry instanceof google.maps.LatLng) {
bounds.extend(geometry);
} else if (geometry instanceof google.maps.Data.Point) {
bounds.extend(geometry.get());
} else {
geometry.getArray().forEach(function(g) {
calcBounds(g, bounds);
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>
</html>