What am I doing wrong here? Everything is working fine, except that the layer control is not showing at all.. hhLayer and wpLayer are L.geoJson(); in case that helps.
<script type="text/javascript">
var map = L.map('map').setView([23.27, 85.37], 12);
var tileUrl='http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
var tileAttrib='Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community';
var tile = new L.TileLayer(tileUrl, {minZoom: 8, maxZoom: 17, attribution: tileAttrib, opacity:1}).addTo(map);
map.addLayer(tile);
var hybUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var hybAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
var hyb = new L.TileLayer(hybUrl, {minZoom: 8, maxZoom: 14, attribution: hybAttrib, opacity:0.7}).addTo(map);
map.addLayer(hyb);
var hhMarkerOptions = {};
var wpMarkerOptions = {};
var hhLayer;
$.getJSON('fxb_hh.geojson', function(data) {
hhLayer = L.geoJson(data, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, hhMarkerOptions);
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.id}
});
//hhLayer.addTo(map);
map.addLayer(hhLayer);
});
var wpLayer;
$.getJSON('fxb_wp.geojson', function(data) {
wpLayer = L.geoJson(data, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, wpMarkerOptions);
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.id);
},
style: function (feature) {
if (feature.properties["Water Testing Report"] == 'BLACK') {return {fillColor: '#1D1061'}};
if (feature.properties["Water available at visit"] == "No") {return {fillColor: '#dd0022'}}
}
});
//wpLayer.addTo(map);
map.addLayer(wpLayer);
});
var baseLayer = {
"Satellite": tile,
"OSM Data": hyb
};
var overlay = {
"Household Data": hhLayer,
"Water Points": wpLayer
};
//var layerControl = new L.control.layers(baseLayer, overlay, {collapsed: false});
//map.addControl(layerControl);
L.control.layers(baseLayer, overlay, {collapsed: false}).addTo(map);
</script>
baseLayer
oroverlay
objects. Can you show the code that creates these layers, including base layers? I recreated a working example from your code here: jsfiddle.net/1ov0nLqb