Skip to content

Instantly share code, notes, and snippets.

@donpadre
Last active February 24, 2017 10:49
Show Gist options
  • Save donpadre/1acf8418d5a139ca9c5720622420d6f1 to your computer and use it in GitHub Desktop.
Save donpadre/1acf8418d5a139ca9c5720622420d6f1 to your computer and use it in GitHub Desktop.
My Map
<div class="map-legend" id="map-legend"></div>
<div id='map'></div>
//========== Mapbox
var map = L.mapbox.map('map', 'diccfish.map-fwz7rlzv')
.setView( [30, -30], 2);
map.scrollWheelZoom.disable();
// Link Address to Google Map Directions
function popupLink() {
$('.marker-title').on('click', function() {
window.open( 'http://maps.google.com/?q=' + $(this).html() );
});
}
// Link sidebar with map locations
map.markerLayer.on('ready', function(e) {
// Grab the Legend
var legend = document.getElementById('map-legend');
// Prepend each location under the legend div
var allPoints = map.markerLayer.eachLayer( function(e) {
$(legend).prepend('<section class="poi">' + e.feature.properties.title + '</section>');
});
// Attach click event to new sections
$('.poi').on('click', function() {
$title = $(this).html();
map.markerLayer.eachLayer( function(marker) {
if (marker.feature.properties.title === $title ) {
marker.openPopup();
map.panTo(marker.getLatLng());
popupLink();
}
});
});
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//api.tiles.mapbox.com/mapbox.js/v1.5.2/mapbox.js"></script>
body {
margin: 0;
padding: 0;
}
#map {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
width: 100%;
}
.map-legend {
background: rgba(11,130,135,0.9);
box-sizing: border-box;
font-family: 'Roboto Slab', serif;
height: 100%;
overflow: scroll;
padding: 2.5% 0;
position: absolute;
top: 0;
width: 35%;
z-index: 6;
section {
border-bottom: 1px dashed #13caba;
color: #1de79d;
cursor: pointer;
display: block;
font-size: .9125rem;
position: relative;
padding: 1rem 5% 1rem 15%;
text-rendering: geometricPrecision;
transition: 0.3s background ease;
width: 80%;
&:hover {
background: rgba(255,255,255,0.2);
transition: 0.3s background ease;
}
}
}
.marker-title {
color: #0b8287;
cursor: pointer;
font-family: 'Roboto Slab', serif;
font-size: .9125rem;
}
.marker-description {
color: #3f3f11;
font-family: 'Roboto Slab', serif;
font-size: .8125rem;
}
.leaflet-left {
right: 0;
}
.leaflet-control {
float: right;
margin-right: 10px;
}
<link href="//api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment