-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsel_point.php
320 lines (258 loc) · 11.5 KB
/
sel_point.php
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<!DOCTYPE html>
<html lang="en">
<head><?php
include('../libs/config.php');
$id_house = $_GET['id_house'];
?>
<meta charset="utf-8">
<title>Leaflet Users Map</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="" />
<meta name="keywords" content="" />
<!-- Le styles -->
<link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Norican">
<link type="text/css" rel="stylesheet" href="assets/bootstrap/css/bootstrap.css">
<link type="text/css" rel="stylesheet" href="assets/leaflet/leaflet.css" />
<!--[if lte IE 8]><link type="text/css" rel="stylesheet" href="assets/leaflet/leaflet.ie.css" /><![endif]-->
<link type="text/css" rel="stylesheet" href="assets/leaflet/plugins/leaflet.markercluster/MarkerCluster.css" />
<link type="text/css" rel="stylesheet" href="assets/leaflet/plugins/leaflet.markercluster/MarkerCluster.Default.css" />
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
position: absolute;
overflow:hidden;
}
#map {
margin-top:40px;
width:100%;
height:100%;
}
#loading {
position: absolute;
width: 220px;
height: 19px;
top: 50%;
left: 50%;
margin: -10px 0 0 -110px;
z-index: 20001;
}
#loading .loading-indicator {
height: auto;
margin: 0;
}
.navbar .brand {
font-size: 25px;
font-family: 'Norican', serif;
font-weight: bold;
color: white;
}
.navbar .nav > li > a {
padding: 13px 10px 11px;
}
.navbar .btn, .navbar .btn-group {
margin-top: 8px;
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
background: #f7f7f7;
}
.leaflet-control-geoloc {
background-image: url(img/location.png);
-webkit-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<div class="nav-collapse">
<form class="navbar-form pull-left">
<span style="padding-left: 20px;"><a class='btn btn-primary ' data-toggle="modal" href="#addmeModal"><i class="icon-plus-sign icon-white"></i> เพิ่มตำแหน่งบ้าน</a></span>
</form>
</div>
</div>
</div>
</div>
<div class="modal hide fade" id="addmeModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>เพิ่มตำแหน่งบ้านลงบนแผนที่!</h3>
</div>
<div class="modal-body">
<p>เลื่อนเมาส์ไปยังตำแหน่งหลังคาบ้าน</p>
<p>กรอกข้อมูลพื้นฐานครัวเรือนตามจริง</p>
</div>
<div class="modal-footer">
<a href="#" onclick="$('#addmeModal').modal('hide'); initRegistration(); return false;"class="btn btn-primary">เริ่ม!</a>
</div>
</div>
<div class="modal hide fade" id="insertSuccessModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Success!</h3>
</div>
<div class="modal-body">
<p>Thanks for joining the Leaflet Users Map!</p>
<p>You should receive an email shortly with instructions on how to edit your information.</p>
</div>
</div>
<div class="modal hide fade" id="removeSuccessModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>You have been removed</h3>
</div>
<div class="modal-body">
<p>You have been removed from the Leaflet User Map.</p>
<p>Thanks for your interest and feel free to add youself back at any time.</p>
</div>
</div>
<div id="map"></div>
<div id="loading-mask" class="modal-backdrop" style="display:none;"></div>
<div id="loading" style="display:none;">
<div class="loading-indicator">
<img src="img/ajax-loader.gif">
</div>
</div>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="assets/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/leaflet/leaflet.js"></script>
<script type="text/javascript" src="assets/leaflet/plugins/leaflet.markercluster/leaflet.markercluster.js"></script>
<script type="text/javascript" src="http://calvinmetcalf.github.io/leaflet-ajax/example/leaflet-src.js"></script>
<script type="text/javascript" src="http://calvinmetcalf.github.io/leaflet-ajax/dist/leaflet.ajax.js"></script>
<script type="text/javascript" src="http://calvinmetcalf.github.io/leaflet-ajax/example/spin.js"></script>
<script type="text/javascript" src="http://calvinmetcalf.github.io/leaflet-ajax/example/leaflet.spin.js"></script>
<script type="text/javascript">
<?php
if ($id_house != '') {
$result = pg_query( "select * from list_house2 where id_house = '$id_house';");
$arr = pg_fetch_array($result);
$lat = $arr[lat];
$longi = $arr[longi];
$zoom = 20;
}else{
$lat = 14.391688;
$longi = 101.137494;
$zoom = 6;
}
?>
var map, newUser, users, mapquest, firstLoad;
firstLoad = true;
users = new L.FeatureGroup();
newUser = new L.LayerGroup();
mapquest = new L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
});
map = new L.Map('map', {
center: new L.LatLng(<?php echo $lat; ?>, <?php echo $longi; ?>),
zoom: <?php echo $zoom; ?>,
layers: [mapquest, users, newUser]
});
<?php
if ($id_house != '') {
echo "L.marker([ $lat, $longi ]).addTo(map).bindPopup('$arr[name_house]');var popup = L.popup();" ;
}else{
}
?>
function onEachFeature(feature, layer) {
layer.bindPopup('จังหวัด : '+ feature.properties.prov_nam + '<br>' + 'อำเภอ : '+ feature.properties.amp_nam + '<br>' + 'ตำบล : '+ feature.properties.tam_nam + '<br>' + 'ชื่อหมู่บ้าน : '+ feature.properties.name_house + '<br>' + 'บ้านเลขที่ : '+ feature.properties.no_house +'<br>' + 'หมู่ที่ : '+ feature.properties.moo_house +'<br>' +'รหัสบ้าน : ' + feature.properties.id_house + '<br>' );
}
// GeoLocation Control
geolocControl.onAdd = function (map) {
var div = L.DomUtil.create('div', 'leaflet-control-zoom leaflet-control');
div.innerHTML = '<a class="leaflet-control-geoloc" href="#" onclick="geoLocate(); return false;" title="My location"></a>';
return div;
};
map.addControl(geolocControl);
map.addControl(new L.Control.Scale());
//map.locate({setView: true, maxZoom: 3});
$(document).ready(function() {
$.ajaxSetup({cache:false});
$('#map').css('height', ($(window).height() - 40));
getUsers();
});
$(window).resize(function () {
$('#map').css('height', ($(window).height() - 40));
}).resize();
function geoLocate() {
map.locate({setView: true, maxZoom: 17});
}
function initRegistration() {
map.addEventListener('click', onMapClick);
$('#map').css('cursor', 'crosshair');
return false;
}
function cancelRegistration() {
newUser.clearLayers();
$('#map').css('cursor', '');
map.removeEventListener('click', onMapClick);
}
function insertUser() {
$("#loading-mask").show();
$("#loading").show();
var prov_nam = $("#prov_nam").val();
var amp_nam = $("#amp_nam").val();
var tam_nam = $("#tam_nam").val();
var name_house = $("#name_house").val();
var no_house = $("#no_house").val();
var moo_house = $("#moo_house").val();
var id_house = $("#id_house").val();
var lat = $("#lat").val();
var longi = $("#longi").val();
var dataString = 'prov_nam='+ prov_nam + '&_nam=' + amp_nam + '&tam_nam=' + tam_nam + '&name_house=' + name_house + '&no_house=' + no_house + '&moo_house=' + moo_house + '&id_house=' + id_house + '&lat=' + lat + '&longi=' + longi;
$.ajax({
type: "POST",
url: "insert_user.php",
data: dataString,
success: function() {
cancelRegistration();
$("#loading-mask").hide();
$("#loading").hide();
$('#insertSuccessModal').modal('show');
geojson_layer.refresh();
},
error:function() {
('#removemeModal').modal('show');
}
});
return false;
}
function onMapClick(e) {
var markerLocation = new L.LatLng(e.latlng.lat, e.latlng.lng);
var marker = new L.Marker(markerLocation);
newUser.clearLayers();
newUser.addLayer(marker);
var form = '<form id="inputform" method="post" enctype="multipart/form-data" class="well">'+
'<label><strong>จังหวัด:</strong> </label>'+
'<input type="text" class="span3" placeholder="" id="prov_nam" name="prov_nam" value="<?php echo $prov; ?>" />'+
'<label><strong>อำเภอ:</strong> </label>'+
'<input type="text" class="span3" placeholder="" id="amp_nam" name="amp_nam" value="<?php echo $amp; ?>" />'+
'<label><strong>ตำบล:</strong></label>'+
'<input type="text" class="span3" placeholder="" id="tam_nam" name="tam_nam" value="<?php echo $tam; ?>" />'+
'<label><strong>ชื่อหมู่บ้าน:</strong></label>'+
'<input type="text" class="span3" placeholder="" id="name_house" name="name_house" />'+
'<label><strong>บ้านเลขที่:</strong></label>'+
'<input type="text" class="span3" placeholder="" id="no_house" name="no_house"/>'+
'<label><strong>หมู่ที่:</strong></label>'+
'<input type="number" class="span3" placeholder="" id="moo_house" name="moo_house" />'+
'<label><strong>รหัสบ้าน:</strong></label>'+
'<input type="number" class="span3" placeholder="" id="id_house" name="id_house" />'+
'<input style="display: none;" type="text" id="lat" name="lat" value="'+e.latlng.lat.toFixed(6)+'" />'+
'<input style="display: none;" type="text" id="longi" name="longi" value="'+e.latlng.lng.toFixed(6)+'" /><br><br>'+
'<div class="row-fluid">'+
'<div class="span6" style="text-align:center;"><button type="button" class="btn" onclick="cancelRegistration()">ยกเลิก</button></div>'+
'<div class="span6" style="text-align:center;"><button type="button" class="btn btn-primary" onclick="insertUser()">ยืนยัน</button></div>'+
'</div>'+
'</form>';
marker.bindPopup(form).openPopup();
}
</script>
</body>
</html>