Skip to content

Instantly share code, notes, and snippets.

@wboykinm
Last active December 20, 2015 21:18
Show Gist options
  • Save wboykinm/6196545 to your computer and use it in GitHub Desktop.
Save wboykinm/6196545 to your computer and use it in GitHub Desktop.
OPHZ client demo
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.css' rel='stylesheet' />
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/css/bootstrap.min.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<!--[if lte IE 8]>
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.ie.css' rel='stylesheet' />
<![endif]-->
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
#map-ui {
position: absolute;
top: 120px;
left: 10px;
width:220px;
z-index: 100;
}
#footer {
position:absolute;
bottom:0px;
left:0px;
right:0px;
background:#3A7CC2;
z-index:999;
overflow:auto;
color:#fff;
padding:5px;
opacity:0.95;
}
ul.inline > li, ol.inline > li {
display: inline-block;
padding-right: 5px;
padding-left: 5px;
}
</style>
<div id='map'>
<div id='map-ui'>
<div class="btn-group-vertical">
<a style="color:#fff;" class="btn btn-primary" href="https://github.com/wboykinm/ophz/tree/master/ophz-b/ophz-b-wgs84" target="_blank"><i class="icon-download"></i> Download Zones (~70MB)</a></li>
<a style="color:#fff;" class="btn btn-primary" href='#' id='geolocate'><i class="icon-map-marker"></i> What zone am I in?</a></li>
</div>
</div>
</div>
<div id='footer'>
<div class="container">
<ul class="inline">
<li><h2 class="switch-title">Open Plant Hardiness Zones</h2></li>
<li class="divider"></li>
</ul>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.js'></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/js/bootstrap.min.js"></script>
<script type='text/javascript'>
var map = L.mapbox.map('map', 'landplanner.map-7d8eg3wy,landplanner.map-73h9vsq0', {maxZoom:9,minZoom:4})
.addControl(L.mapbox.geocoderControl('landplanner.map-7d8eg3wy,landplanner.map-73h9vsq0'));
var geolocate = document.getElementById('geolocate');
// This uses the HTML5 geolocation API, which is available on
// most mobile browsers and modern browsers, but not in Internet Explorer
//
// See this chart of compatibility for details:
// http://caniuse.com/#feat=geolocation
if (!navigator.geolocation) {
geolocate.innerHTML = 'geolocation is not available';
} else {
geolocate.onclick = function (e) {
e.preventDefault();
e.stopPropagation();
map.locate();
};
}
// Once we've got a position, zoom and center the map
// on it, and add a single marker.
map.on('locationfound', function(e) {
map.fitBounds(e.bounds);
map.markerLayer.setGeoJSON({
type: "Feature",
geometry: {
type: "Point",
coordinates: [e.latlng.lng, e.latlng.lat]
},
properties: {
'marker-color': '#000',
'marker-symbol': 'star-stroked'
}
});
// And hide the geolocation button
geolocate.parentNode.removeChild(geolocate);
});
// If the user chooses not to allow their location
// to be shared, display an error message.
map.on('locationerror', function() {
geolocate.innerHTML = 'position could not be found';
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment