How can I turn the following code into a variable, so that I can choose, or not, to load it in the layer control? and not anymore on moving the map or reaching this zoom level.
I added a var wikilayer =
before "function on moveend" and brackets here and at the very end, but it's resulting in the browser minding on the ending bracket and the page not to function from this code
Following is a working code with the following js file found at Github from Turban's repositery https://github.com/turban/Leaflet.Wikipedia
// wikipedia
var start_at_zoom_wiki = 10;
function onMoveEnd(evt) {
if (map.getZoom() > start_at_zoom_wiki) {
var template = '<h2>{label}</h2><p><img src="{thumbnail}" width="150"><br>{abstract}</p><p><a href="{link}" target="_blank">Wikipedia...</a></p>';
L.wikipedia({
query: {
fields: ['label', 'lat', 'lng', 'abstract', 'link', 'thumbnail'],
bounds: map.getBounds()
},
marker: {
icon: L.icon({ // Icons from http://www.icondrawer.com/social-icons.php
iconUrl: 'http://mappingforyou.eu/icons/wikipedia_16.png',
iconRetinaUrl: 'http://mappingforyou.eu/icons/wikipedia_32.png',
iconSize: [16, 16]
})
}
}).addTo(map).on('click', function (evt) {
evt.layer.bindPopup(L.Util.template(template, evt.layer.data), customOptions);
});
}
}
map.on('moveend', onMoveEnd);
and this is my alternate layer control from here
var baseLayers = [];
var overLayers = [{
group: " ",
layers: [{
active: false,
name: "Wikipedia (test)",
icon: '<i class="icon icon-restaurant"></i>',
layer: wiki,
}, ]
}, ];
// panel
var panelLayers = new L.Control.PanelLayers(baseLayers, overLayers, {
compact: true,
collapsed: true,
collapsibleGroups: false
});
map.addControl(panelLayers);