-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
235 lines (201 loc) · 7.76 KB
/
index.html
File metadata and controls
235 lines (201 loc) · 7.76 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<html lang="en" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Map Test</title>
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/uikit-rtl.min.css" />
<link rel="preconnect" href="//fdn.fontcdn.ir"><link rel="preconnect" href="//v1.fontapi.ir"><link href="https://v1.fontapi.ir/css/Samim" rel="stylesheet">
<!-- UIkit JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit-icons.min.js"></script>
<!-- <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" /> -->
<!-- <script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script> -->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<link href="https://static.neshan.org/sdk/leaflet/1.4.0/leaflet.css" rel="stylesheet" type="text/css">
<script src="https://static.neshan.org/sdk/leaflet/1.4.0/leaflet.js" type="text/javascript"></script>
<style>
* {
font-family: Samim, sans-serif;
}
body {
background: #121212;
min-height: 100vh;
}
.uk-grid {
margin-right: -15px !important;
}
.uk-card-default {
background: #262626;
}
#map {
height: 500px;
}
.uk-input-dark {
background-color: #383838;
border: none;
border-radius: 100px;
color: #c4c4c4;
}
.uk-input-dark:focus {
background-color: #383838;
border: none;
border-radius: 100px;
color: #c4c4c4;
}
.uk-button-dark {
background-color: #520085;
border: none;
border-radius: 100px;
color: #c4c4c4;
font-weight: 900;
}
#results {
max-height: 300px;
overflow-x: auto;
}
</style>
</head>
<body>
<div id="root" class="uk-section uk-padding-small">
<div class="uk-width-1-1" uk-grid>
<div class="uk-width-1-3@m">
<div class="uk-card uk-card-body uk-card-default uk-border-rounded">
<div class="" uk-grid>
<div class="uk-width-2-3@m">
<input class="uk-input uk-input-dark" type="text" id="query" placeholder="جستجوی مکان">
</div>
<div class="uk-width-expand">
<button class="uk-button uk-button-dark uk-width-1-1" onClick="searchApi()">جستجو</button>
</div>
</div>
<div class="uk-margin-medium-top" id="results"></div>
</div>
</div>
<div class="uk-width-expand">
<div class="uk-card uk-card-body uk-card-default uk-border-rounded">
<div class="uk-border-rounded" id="map"></div>
</div>
</div>
</div>
</div>
<!-- pure leaflet sript -->
<script>
// var baseCordinates = [35.699687, 51.338146];
// var map = L.map('map').setView(baseCordinates, 15);
// var markersBag = [];
// L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
// maxZoom: 19,
// attribution: 'PrimeMap | © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
// }).addTo(map);
// function handleMapClick(e) {
// // remove previous markers
// markersBag.forEach(m => {
// m.remove();
// })
// // init new marker & add to markersBag array
// var marker = L.marker(e.latlng).addTo(map);
// markersBag.push(marker);
// console.log(e.latlng);
// }
// map.on('click', handleMapClick);
</script>
<!-- neshan map script -->
<script>
var submissions = [
{
'title': 'روزنامه صمت',
'cordinates': [35.72543699999999,51.41672369999999],
},
{
'title': 'بیمارستان تهران کلینیک',
'cordinates': [35.72579050504679,51.41847019306144],
},
{
'title': 'رستوران منصور',
'cordinates': [35.724849, 51.414836],
}
];
var baseCordinates = [35.699739, 51.338097];
var baseZoom = 14;
var markersBag = [];
var map = new L.Map('map', {
key: 'web.4bb42e651eb7471299a5429a336ef866',
maptype: 'standard-day',
poi: true,
traffic: false,
center: baseCordinates,
zoom: 14
});
map.on('click', handleMapClick);
function addMarker(e) {
// remove previous markers
markersBag.forEach(m => {
m.remove();
})
// init new marker & add to markersBag array
var marker = new L.marker(e.latlng).addTo(map);
markersBag.push(marker);
console.log('maker injected on cordinates ' + e.latlng);
}
function handleMapClick(e) {
addMarker(e);
}
function mapResetView() {
map.setView(baseCordinates, baseZoom);
}
function changeView(cordinates = baseCordinates, zoom = baseZoom, ShouldAddMarker = true) {
map.setView(cordinates, zoom);
if (ShouldAddMarker) {
addMarker({latlng: cordinates});
}
}
function searchApi() {
let query = document.querySelector('#query').value;
if (query.length === 0 || query.length < 5) {
return;
}
let lat = baseCordinates[0];
let lng = baseCordinates[1];
// const axios = require('axios');
let config = {
method: 'get',
maxBodyLength: Infinity,
url: 'https://api.neshan.org/v1/search?term='+query+'&lat='+lat+'&lng='+lng,
headers: {
'Api-Key': 'service.4cc968a40bb94cedab2d812152dc8fd0'
}
};
axios.request(config)
.then((response) => {
document.querySelector('#results').innerHTML = '';
let res = response.data.items;
res.forEach(item => {
let title = item.title;
let address = item.address;
let yx = "[" + item.location.y +","+ item.location.x +"]";
document.querySelector('#results').innerHTML += `
<div class="uk-margin-small-bottom">
<a class="uk-link-reset" style="color: #d9d9d9 !important; font-weight: 900" onClick="changeView(${yx}, 19)">
${title}
<br />
<span class="uk-text-meta">${address}</span>
</a>
</div>`;
});
})
.catch((error) => {
console.log(error);
});
}
// submissions.forEach(s => {
// var pop = L.popup()
// .setLatLng(s.cordinates)
// .setContent(s.title)
// .addTo(map);
// });
changeView(baseCordinates);
</script>
</body>
</html>