Permalink
Browse files

updated

  • Loading branch information...
1 parent 156c852 commit 32e8b6a28b112ae737d2e4f1a23d737426258497 @tegansnyder committed Jun 8, 2012
Showing with 74 additions and 8 deletions.
  1. +34 −2 ajax.php
  2. +40 −6 index.html
View
@@ -11,13 +11,45 @@
$points[0]['lng'] = -96.70189;
$points[1]['lat'] = 40.8132;
$points[1]['lng'] = -96.7260;
+ $points[2]['lat'] = 40.7704;
+ $points[2]['lng'] = -96.8268;
+ $points[3]['lat'] = 40.7603;
+ $points[3]['lng'] = -96.8026;
+ $points[4]['lat'] = 40.7860;
+ $points[4]['lng'] = -96.8306;
+ $points[5]['lat'] = 40.7512;
+ $points[5]['lng'] = -96.7813;
+ $points[6]['lat'] = 40.7401;
+ $points[6]['lng'] = -96.7355;
+ $points[7]['lat'] = 40.7600;
+ $points[7]['lng'] = -96.7267;
+ $points[8]['lat'] = 40.7692;
+ $points[8]['lng'] = -96.6790;
+ $points[9]['lat'] = 40.7917;
+ $points[9]['lng'] = -96.6519;
+ $points[10]['lat'] = 40.8295;
+ $points[10]['lng'] = -96.6284;
+ $points[11]['lat'] = 40.8634;
+ $points[11]['lng'] = -96.6474;
+ $points[12]['lat'] = 40.8613;
+ $points[12]['lng'] = -96.7137;
+ $points[13]['lat'] = 40.8490;
+ $points[13]['lng'] = -96.8136;
+
+ $inBounds = array();
+ $x = 0;
+
+ //http://stackoverflow.com/questions/10939408/determine-if-lat-lng-in-bounds
foreach ($points as $point) {
- if ($bounds['sw']['lat'] < $point['lat'] && $point['lat'] < $bounds['ne']['lat'] && $bounds['sw']['lng'] < $point['lng'] < $bounds['ne']['lng']) {
+ if ($bounds['sw']['lat'] < $point['lat'] && $point['lat'] < $bounds['ne']['lat'] && $bounds['sw']['lng'] < $point['lng'] && $point['lng'] < $bounds['ne']['lng']) {
-
+ $inBounds[$x] = $point;
+ $x = $x + 1;
}
}
+ echo json_encode($inBounds);
+
?>
View
@@ -13,23 +13,57 @@
<div id="map" style="width: 600px; height: 400px"></div>
<script src="Leaflet/dist/leaflet.js"></script>
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+
<script>
var map = new L.Map('map');
+ var markersLayer = new L.LayerGroup();
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});
map.setView(new L.LatLng(40.81259, -96.70189), 13).addLayer(cloudmade);
+
+ $(function() {
+
+ loadMarkers();
+
+ map.on('drag', function(e) {
+ markersLayer.clearLayers();
+ });
+
+ map.on('dragend', function(e) {
+ loadMarkers();
+ });
+
+
+ });
+
+ function loadMarkers() {
+
+ markersLayer.clearLayers();
+ var bounds = map.getBounds();
- var markerLocation = new L.LatLng(40.81259, -96.70189),
- marker = new L.Marker(markerLocation);
-
- map.addLayer(marker);
-
-
+ bounds = bounds._northEast.lat + ',' + bounds._northEast.lng + ',' + bounds._southWest.lat + ',' + bounds._southWest.lng;
+
+ $.get("ajax.php?bounds=" + bounds, { name: "John", time: "2pm" }, function(data){
+
+ $(data).each(function() {
+ var marker = new L.Marker(new L.LatLng(this.lat, this.lng));
+
+ markersLayer.addLayer(marker);
+ map.addLayer(markersLayer);
+
+ });
+
+
+ }, 'json');
+
+ }
</script>
+
</body>
</html>

0 comments on commit 32e8b6a

Please sign in to comment.