using leaflet styled layer control and clusters

95 views
Skip to first unread message

Ailis

unread,
Aug 27, 2017, 6:25:41 PM8/27/17
to Leaflet

I'm creating a map that uses this styled layer control plug in and the marker clusters plug in.


I've gotten both plug ins to work on their own with my data, but can't figure out how to get them to work together.


I have downloaded and included the marker cluster layer support files and attempted to implement them but it didn't change anything.


Basically there will be a category for each day of the week, and then within each day filters to show food or drink information, so I need this kind of layer control. I'm also open to suggestions for how to create my own layer control that is like this (grouping layers and then allowing you to filter within those groups)


var base = L.tileLayer('https://api.mapbox.com/styles/v1/agrosh/cj6p9fuxu2di72ss05n5nhycx/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoiYWdyb3NoIiwiYSI6ImNpeWFscjNkZzAwN3AycW55aXB6eWtjZnoifQ.ZudIxK3hMrxAX8O4BXhiEg', {
        });

        var zoomLevel = 13;
        var setLat = 35.593464;
        var setLong = -82.551934;

        var map = L.map('map', {
            center: [setLat, setLong],
            zoom: zoomLevel
        });
        map.addLayer(base);


    var mondayFood = [
        {
"name":"Storm Rhum Bar & Bistrot",
"deal":"$10 burger, fries, and a beer or glass of wine",
"address":"",
"website":"",
"lat":35.591140,
"lng":-82.552111,
"yelp":"",
"google":"",
"img":"<img src='dealimages/stormr-01.png' alt='Storm Rhum Bar & Bistrot: $10 Burger, fries, & beer' style='width:200px;height:300px;'>"
      }];

    var mondayDrink = [
     {
"name":"Sonora Cocina Mexicana",
"deal":"1/2 off select margaritas, $2 Mexican cans, $5 mimosas",
"address":"",
"website":"",
"lat":35.594446,
"lng":-82.555602,
"yelp":"",
"google":"",
"img":"<img src='dealimages/sonora-1monday.png' alt='Sonora: 1/2 off select margaritas, $2 Mexican cans, $5 Mimosas' style='width:200px;height:300px;'>"
      }];



    var markerClusters = L.markerClusterGroup.layerSupport().addTo(map);

    // monday
    for ( var i = 0; i < mondayFood.length; ++i )
    {

    var monFood = mondayFood[i].img;

var mF = L.marker( [mondayFood[i].lat, mondayFood[i].lng], {icon: myIcon} )
              .bindPopup( monFood );

        markerClusters.addLayer( mF );

    }

    for ( var i = 0; i < mondayDrink.length; ++i )
    {
var monDrink = mondayDrink[i].img;

var mD = L.marker( [mondayDrink[i].lat, mondayDrink[i].lng], {icon: myIcon} )
              .bindPopup( monDrink );
 markerClusters.addLayer( mD );

    }

    var overlays = [
                        {
                            groupName : "Monday",
                            expanded : true,
                            layers    : { 
                                "Food" : mondayFood
                                "Drink" : mondayDrink,

                            }]; 
                         }

    var options = {
            container_width     : "300px",
            group_maxHeight     : "80px",
            //container_maxHeight : "350px", 
            exclusive           : false,
            collapsed : true, 
            position: 'topright'
        };

        var control = L.Control.styledLayerControl(overlays, options);
        map.addControl(control);



Reply all
Reply to author
Forward
0 new messages