$(window).on('entity:map', function (e, data) {

    var map = data.map;
    var loaded_district = false;
    var loaded_city = false;

    $.each([[tr("Districts"), 'district'], [tr("Cities"), 'city']], function (i, modelname, name) {
        var style = L.Util.extend({clickable: false},
                                  window.SETTINGS.map.styles[modelname[1]] || {});
        var nameHTML = '<span style="color: '+ style['color'] + ';">&#x2B24;</span>&nbsp;' + modelname[0];
        var layer = new L.ObjectsLayer(null, {
                indexing: false,
                modelname: modelname[1],
                style: style,
        });
        map.layerscontrol.addOverlay(layer, nameHTML, tr('Zoning'));

        map.on('layeradd', function(e){
            var options = e.layer.options || {'modelname': 'None'};
            if (! loaded_district){
                if (options.modelname == 'district'){
                    e.layer.load(window.SETTINGS.urls.district_layer);
                    loaded_district = true;
                }
            }
            if (! loaded_city){
                if (options.modelname == 'city'){
                    e.layer.load(window.SETTINGS.urls.city_layer);
                    loaded_city = true;
                }
            }
        });
    });
});
$(window).on('entity:map', function (e, data) {

    var map = data.map;

    var landLayers = [{url: window.SETTINGS.urls.district_layer, name: tr("Districts"), id: 'district'},
                      {url: window.SETTINGS.urls.city_layer, name: tr("Cities"), id: 'city'}];

    landLayers = landLayers.concat(window.SETTINGS.map['restricted_area_types']);
    console.log(landLayers);
    var result = landLayers.map(function(el) {
        var o = Object.assign({}, el);
        o.isActive = false;
        return o;
    })

    for (var i=0; i<landLayers.length; i++) {
        var landLayer = landLayers[i];
        var style = L.Util.extend({clickable: false},
                                  window.SETTINGS.map.styles[landLayer.id] || {});
        var nameHTML = '<span style="color: '+ style['color'] + ';">&#x2B24;</span>&nbsp;' + landLayer.name;
        var colorspools = L.Util.extend({}, window.SETTINGS.map.colorspool),
            colorspool = colorspools[landLayer.id];
        if (colorspool) {
            var color = colorspool[i % colorspool.length];
            style['color'] = color;
        }
        var layer = new L.ObjectsLayer(null, {
                indexing: false,
                modelname: landLayer.name,
                style: style,
        });
        map.layerscontrol.addOverlay(layer, nameHTML, tr('Zoning'));
    };

    map.on('layeradd', function(e){
        var options = e.layer.options || {'modelname': 'None'};
        console.log(options);
        for (var i=0; i<landLayers.length; i++) {
            if (! landLayers[i].isActive){
                if (options.modelname == landLayers[i].name){
                    e.layer.load(landLayers[i].url);
                    landLayers[i].isActive = true;
                }
            }
        }
    });
});
Fix problem with restricted area