-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_map.html
154 lines (126 loc) · 3.93 KB
/
main_map.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
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
<!DOCTYPE HTML>
<html>
<head>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='css/leaflet.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='css/Control.Geocoder.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='css/main_map.css') }}">
<script src="{{url_for('static', filename='js/leaflet.js')}}"></script>
<script src="{{url_for('static', filename='js/Control.Geocoder.js')}}"></script>
<style>
#map {
position: absolute;
display: inline-block;
height: 650px;
width: 1190px;
margin-top: 10px;
margin-left: 95px;
z-index: 0;
}
#input {
position: absolute;
display: inline-block;
height: 700px;
width: 180px;
margin-top: 0px;
margin-left: 10px;
background-image: linear-gradient(to left, red 30%,yellow 30%,white 0%);
z-index: 2;
}
</style>
</head>
<body>
<div id = "input">
<div class="markers-color-palette">
<img src="static/css/blue-marker.png" class="marker-colors blueIcon" />
Start
<br>
<img src="static/css/red-marker.png" class="marker-colors redIcon" />
End
<br><br><br>
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
{{ message }}
{% endfor %}
{% endif %}
{% endwith %}
</div>
<form action = "" method = "POST">
<p>Source <input id="Src" type="text" name="Src" /></p>
<p>Destination <input id="Dest" type="text" name="Dest" /></p>
<div class="input submit">
<input type="submit" name="btn" value="Submit" />
</div>
</form>
<br><br><br>
<form action="" method="post">
{{ form.csrf }}
<div class="input submit">
<input type="submit" name="btn" value="Randomise traffic" />
</div>
</form>
</div>
<div id="map">
<script type="text/javascript">
var CustomIcon = L.Icon.extend({
options: {
iconSize: [38, 38]
}
});
var redIcon = new CustomIcon({ iconUrl: 'static/css/red-marker.png' }),
blueIcon = new CustomIcon({ iconUrl: 'static/css/blue-marker.png' })
// var redIcon = new ({ iconUrl: "{{url_for('static', filename='css/red-marker.png')}}" }),
// blueIcon = new CustomIcon({ iconUrl: "{{url_for('static', filename='css/blue-marker.png')}}" });
var initialBounds = L.latLngBounds(L.latLng(22.5626,88.3539), L.latLng(22.5826, 88.3739));
var map = L.map('map').fitBounds(initialBounds);
// var map = L.map("map").fitBounds([
// [22, 90],
// [10, 100]
// ]);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var marker = L.marker([22.5736,88.3619], { icon:blueIcon,
draggable: true
}).addTo(map).on('dragend', onDragEnd);
var marker_f = L.marker([22.5726,88.3639], {icon:redIcon,
draggable: true
}).addTo(map).on('dragend', onDragEnd_f);
var geocoder = L.Control.geocoder().addTo(map),
Src = document.getElementById('Src'),
Dest = document.getElementById('Dest');
geocoder.markGeocode = function (result) {
var latlng = result.center;
var latlng_f = result.center;
L.marker(latlng, {
draggable: true
}).addTo(map).
L.marker(latlng_f, {
draggable: true
}).addTo(map).
on('dragend', onDragEnd).
on('dragend', onDragEnd_f).
// bindPopup(result.html).
openPopup();
displayLatLng(latlng);
displayLatLng_f(latlng_f);
};
var latlng,latlng_f;
function onDragEnd(event) {
latlng = event.target.getLatLng();
displayLatLng(latlng);
}
function onDragEnd_f(event) {
latlng_f = event.target.getLatLng();
displayLatLng_f(latlng_f);
}
function displayLatLng(latlng) {
Src.value = latlng.lng+','+latlng.lat;
}
function displayLatLng_f(latlng_f) {
Dest.value = latlng_f.lng+','+latlng_f.lat;
}
</script>
</div>
</body>
</html>