Map = {};
var map, geoJson, districtData;
var myStyle = {
    "color": "#ff7800",
    "weight": 2,
    "opacity": 0.5,
    "dashArray": '8',
};
$(document).ready(function () {
    Map.load();
}, 100);
Map.load = function () {

    map = L.map('mapid').setView([20.5937, 78.9629], 5);        //sets view of india map
    geoJson = L.geoJson(Map.statesData, { style: myStyle, onEachFeature: onEachFeature }).addTo(map);
    $('.leaflet-bottom,.leaflet-control-container').empty();
    map.dragging.disable();
    map.touchZoom.disable();
    map.doubleClickZoom.disable();
    map.scrollWheelZoom.disable();
}
function onEachFeature(feature, layer) {
    layer.on({
        mouseover: highlightFeature,
        mouseout: resetHighlight,
        click: zoomToFeature
    });
}
var arr = [];
function zoomToFeature(e) {

    // map.fitBounds(e.target.getBounds());
    /* // add text labels:
    var myIcon = L.divIcon({
        className: 'custom-div-icon',
        iconSize: new L.Point(35, 35),
        html: '<div    class="map-label stateLabels" id="' + 'stateName' + '_val">' + e.sourceTarget.feature.properties.NAME_1 + '</div>'
    });
    L.marker([e.latlng.lat, e.latlng.lng], { icon: myIcon }).addTo(map) */
    if (districtData != undefined) {
        for (let i = 0; i < arr.length; i++) {
            map.removeLayer(arr[i]);
        }
        arr = [];
    }

    for (let i = 0; i < Map.districtData.features.length; i++) {
        if (Map.districtData.features[i].properties.NAME_1.includes(e.sourceTarget.feature.properties.NAME_1)) {
            districtData = L.geoJson(Map.districtData.features[i], { style: myStyle, onEachFeature: onEachFeature }).addTo(map);
            arr.push(districtData);
            // map.fitBounds(districtData.getBounds());
            //            break;
        }

    }
}
Map.recenterMap = function () {
    map.setView([20.5937, 78.9629], 5);
}
function highlightFeature(e) {
    var layer = e.target;

    layer.setStyle({
        weight: 5,
        color: '#666',
        dashArray: '',
        fillOpacity: 0.7
    });

    if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
        layer.bringToFront();
    }
}
function resetHighlight(e) {
    geoJson.resetStyle(e.target);
}