Created
November 18, 2013 06:11
-
-
Save wboykinm/7523403 to your computer and use it in GitHub Desktop.
Try 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>Point in Polygon</title> | |
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' /> | |
<script src='http://api.tiles.mapbox.com/mapbox.js/v1.4.2/mapbox.js'></script> | |
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.4.2/mapbox.css' rel='stylesheet' /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<style> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body> | |
<style> | |
#state { | |
position:absolute; | |
bottom:10px; | |
right:10px; | |
background:#fff; | |
font-size:30px; | |
padding:10px; | |
z-index:999; | |
} | |
#content { | |
position:absolute; | |
top:0; | |
right:0; | |
width:200px; | |
bottom:0; | |
background:#000; | |
background:rgba(0, 0, 0, 0.5); | |
} | |
#content.container { | |
padding:10px; | |
} | |
</style> | |
<script src='https://www.mapbox.com/mapbox.js/assets/leaflet-pip.js'></script> | |
<div id='map'></div> | |
<div id='content'> | |
<div class="container"> | |
<h2>Ward Locator</h2> | |
<p>Burlington's ward map will be changing if the voters approve the new layout on town meeting day. Drag the marker to you location to see what your new ward will be.</p> | |
</div> | |
</div> | |
<div id='state'></div> | |
<script> | |
var map = L.mapbox.map('map', baselayer) | |
map.fitBounds([ | |
[44.54790950833806, -72.99247741699219], | |
[44.403618239739515, -73.43193054199219] | |
], { | |
paddingTopRight: [200, 0] | |
}); | |
var baselayer = L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png', { | |
maxZoom: 17, | |
attribution: "<a href='https://maps.stamen.com' target='_blank'>Stamen<\/a>", | |
}).addTo(map); | |
$.ajax({ | |
url: 'map.geojson', | |
dataType: 'json', | |
success: function load(d) { | |
var states = L.geoJson(d).addTo(map); | |
L.marker([44.4758825, -73.212072], { | |
icon: L.mapbox.marker.icon({ | |
'marker-color': '#f22', | |
'marker-size': 'large', | |
'marker-symbol': 'circle-stroked' | |
}), | |
draggable: true | |
}).addTo(map) | |
.on('dragend', function(e) { | |
var layer = leafletPip.pointInLayer(this.getLatLng(), states, true); | |
document.getElementById('state').innerHTML = layer.length ? | |
layer[0].feature.properties.name : ''; | |
}); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment