Different popup CSS styles for different layers in Leaflet
HTML
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css">
<div id="map"></div>
CSS
html,
body,
#map {
height: 100%;
width: 100%;
padding: 0px;
margin: 0px;
}
.tallPop {
min-height: 400px;
}
.shortPop {
min-height: 50px;
}
JavaScript
////////////////////////////////////////////////////////////////////////////////////////////
//setting up the map//
////////////////////////////////////////////////////////////////////////////////////////////
// set center coordinates
var coords = [34.069, -118.293];
// set default zoom level
var zoomLevel = 14;
// initialize map
var map = L.map('map').setView(coords, zoomLevel);
// set source for map tiles
ATTR = '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> | ' +
'© <a href="http://cartodb.com/attributions">CartoDB</a>';
CDB_URL = 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png';
// add tiles to map
L.tileLayer(CDB_URL, {
attribution: ATTR
}).addTo(map);
/////////////////////////////////////////////////////////////////////////////////////////////
//adding data//
/////////////////////////////////////////////////////////////////////////////////////////////
var points1 = getPoints1();
var points2 = getPoints2();
var tallIcon = L.icon({
iconUrl: 'http://leafletjs.com/docs/images/leaf-green.png',
shadowUrl: 'http://leafletjs.com/docs/images/leaf-shadow.png',
iconSize: [38, 95],
shadowSize: [50, 64],
iconAnchor: [22, 94],
shadowAnchor: [4, 62],
popupAnchor: [-3, -76]
});
var tallPoints = L.geoJson(points1,{onEachFeature: onEachTall}).addTo(map);
var shortPoints = L.geoJson(points2,{onEachFeature: onEachShort}).addTo(map);
function onEachTall(feature, layer) {
layer.bindPopup('<div class="tallPop">Tall Popup is Tall</div>');
layer.setIcon(tallIcon);
}
function onEachShort(feature, layer) {
layer.bindPopup('<div class="shortPop">Short Popup is not so Tall</div>');
}
/////////////////////////////////////////////////////////////////////////////////////////////
//data loading functions//
/////////////////////////////////////////////////////////////////////////////////////////////
function getPoints1() {
var...