-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
78 lines (63 loc) · 2.16 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
<html>
<head>
<title>SimplyRETS Map Search</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.2.3/leaflet.draw.css" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.2.3/leaflet.draw.js"></script>
<script language="javascript">
$(document).ready(function() {
var map = new L.Map('map');
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
var houston = new L.LatLng(29.97, -95.35);
map.setView(houston,10);
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
draw: {
circle: false,
marker: false,
polyline: false
},
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
var markers = [];
var polygon = null;
map.on('draw:created', function (e) {
// remove markers and polygon from the last run
$.each (markers, function (i) { map.removeLayer(markers[i]) });
if (polygon != null) map.removeLayer (polygon);
var latLngs = $.map(e.layer.getLatLngs(), function(o) {
return { name: "points", value: o.lat + "," + o.lng };
});
$.ajax({
url: 'https://api.simplyrets.com/properties',
data: latLngs,
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("simplyrets:simplyrets"))
},
success: function(data) {
$.each (data, function (idx) {
var markerLocation = new L.LatLng(data[idx].geo.lat, data[idx].geo.lng);
var marker = new L.Marker(markerLocation);
map.addLayer(marker);
markers.push(marker);
});
}
});
polygon = e.layer;
map.addLayer(e.layer);
});
});
</script>
</head>
<body>
<div id="map" style="height: 100%"></div>
</body>
</html>