2

I have number of markers and needs to be clustered based on the city property of the marker. Currently I'm able to cluster without any criteria. Is it possible to specify criteria (for example by city) and cluster them?

Below is my code:

    var markerClusters = L.markerClusterGroup({maxClusterRadius:70});

function cluster(data) {
  data.records.forEach(function (obj) {

    {
      var popup = obj.type +
              '<br/>' + obj.status; 
      markers[obj]= new L.Marker([obj.Latitude,obj.Longitude]).bindPopup(popup);
      markerClusters.addLayer(markers[obj])
      m.addLayer(markerClusters)
    }
  }
  )}

  cluster(alldatas)

Below is my sample json:

    var alldatas = {
    "records": [{
        "sno": "12778",
        "providercode": "20000",
        "ABHI_code": "2",
        "status": "Phase1",
        "type": "Hospital",
        "name": "Aakash Hospital",
        "address": "90-43- Malviya Nagar",
        "city": "DELHI",
        "state": "Delhi",
        "Nofbeds": "50",
        "Speciality": "Multispeciality",
        "Grading": "A",
        "Loftest": "null",
        "Latitude": "28.535081",
        "Longitude": "77.214854",
        "acf": "222",
        "newcol": "abc"
    }, {
        "sno": "12779",
        "providercode": "20001",
        "ABHI_code": "1",
        "status": "Phase2",
        "type": "Hospital",
        "name": "Centre For Sight- Faridabad",
        "address": "Sector-16A",
        "city": "FARIDABAD",
        "state": "Haryana",
        "Nofbeds": "15",
        "Speciality": "Eye Speciality",
        "Grading": "A",
        "Loftest": "0",
        "Latitude": "28.40298",
        "Longitude": "77.31858",
        "acf": "0",
        "newcol": null
    }, {
        "sno": "12780",
        "providercode": "20002",
        "ABHI_code": "0",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Centre For Sight- Gurgaon",
        "address": "Sco 317- Sector 29",
        "city": "GURGAON",
        "state": "Haryana",
        "Nofbeds": "15",
        "Speciality": "Eye Speciality",
        "Grading": "null",
        "Loftest": "null",
        "Latitude": "28.46377",
        "Longitude": "77.06549",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12781",
        "providercode": "20003",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Centre For Sight- Preet Vihar",
        "address": "F-19 Main Vikas Marg Preet Vihar",
        "city": "DELHI",
        "state": "Delhi",
        "Nofbeds": "15",
        "Speciality": "Eye Speciality",
        "Grading": "nulll",
        "Loftest": "null",
        "Latitude": "28.64159",
        "Longitude": "77.29549",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12782",
        "providercode": "20004",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Centre For Sight- Safdarjung Enclave",
        "address": "B 5-24- Safdarjung Enclave",
        "city": "DELHI",
        "state": "Delhi",
        "Nofbeds": "15",
        "Speciality": "Eye Speciality",
        "Grading": "null",
        "Loftest": "null",
        "Latitude": "28.560055",
        "Longitude": "77.19097",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12783",
        "providercode": "20007",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Pushpanjali Crosslay Hospital",
        "address": "W-3, Sector -1, Vaishali",
        "city": "GHAZIABAD",
        "state": "Uttar Pradesh",
        "Nofbeds": "300",
        "Speciality": "Multispeciality",
        "Grading": "",
        "Loftest": "",
        "Latitude": "28.634583",
        "Longitude": "77.33303",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12784",
        "providercode": "20008",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Pushpanjali Medical Centre Heart & Trauma Centre",
        "address": "A-14\/15, Vikas Marg Extn.",
        "city": "DELHI",
        "state": "Delhi",
        "Nofbeds": "50",
        "Speciality": "Multispeciality",
        "Grading": "",
        "Loftest": "",
        "Latitude": "28.65468",
        "Longitude": "77.30586",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12785",
        "providercode": "20009",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Bgs Global Hospital",
        "address": "Bgs Health And Education City,No.67, Uttarahalliroad, Kengeri",
        "city": "BENGALURU",
        "state": "Karnataka",
        "Nofbeds": "17",
        "Speciality": "Multispeciality",
        "Grading": "",
        "Loftest": "",
        "Latitude": "12.90009",
        "Longitude": "77.49697",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12786",
        "providercode": "20010",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Global Hospitals & Health City",
        "address": "439, Cheran Nagar, Perumbakkam",
        "city": "CHENNAI",
        "state": "Tamil Nadu",
        "Nofbeds": "300",
        "Speciality": "Multispeciality",
        "Grading": "",
        "Loftest": "",
        "Latitude": "12.89849",
        "Longitude": "80.20669",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12787",
        "providercode": "20011",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Global Hospitals, Lakdi-Ka-Pool",
        "address": "6-1-1070\/1 To 4,Lakdi-Ka-Pool",
        "city": "HYDERABAD",
        "state": "Telangana",
        "Nofbeds": "200",
        "Speciality": "Multispeciality",
        "Grading": "",
        "Loftest": "",
        "Latitude": "17.40529",
        "Longitude": "78.463215",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12788",
        "providercode": "20012",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Aware Global Hospitals",
        "address": "08-16-01, Sowbhagya Nagar, Sagar Road, Lingojiguda Saroornagar",
        "city": "HYDERABAD",
        "state": "Telangana",
        "Nofbeds": "300",
        "Speciality": "Multispeciality",
        "Grading": "",
        "Loftest": "",
        "Latitude": "17.34601",
        "Longitude": "78.53994",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12789",
        "providercode": "20013",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Global Hospitals, Banjara Hills",
        "address": "6-3-345\/1, Nims Lane, Opp Vengal Rao Park,Road No-I, Banjara Hills",
        "city": "HYDERABAD",
        "state": "Telangana",
        "Nofbeds": "300",
        "Speciality": "Multispeciality",
        "Grading": "",
        "Loftest": "",
        "Latitude": "17.421269",
        "Longitude": "78.451405",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12790",
        "providercode": "20014",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "Navchetna Hospital",
        "address": "4047\/48 Sector 23\/24 Main Road Sanjay Colony",
        "city": "FARIDABAD",
        "state": "Haryana",
        "Nofbeds": "25",
        "Speciality": "Multispeciality",
        "Grading": "",
        "Loftest": "",
        "Latitude": "28.386692",
        "Longitude": "77.295299",
        "acf": null,
        "newcol": null
    }, {
        "sno": "12791",
        "providercode": "20015",
        "ABHI_code": "",
        "status": "Phase 1",
        "type": "Hospital",
        "name": "National Hospital, Mumbai",
        "address": "Matruashish, M. G. Road, Borivli(East)",
        "city": "MUMBAI",
        "state": "Maharashtra",
        "Nofbeds": "16",
        "Speciality": "Multispeciality",
        "Grading": "",
        "Loftest": "",
        "Latitude": "19.231237",
        "Longitude": "72.861512",
        "acf": null,
        "newcol": null
    }
]}
2

Is it possible to specify criteria (for example by city) and cluster them?

No.

What you can do, however, is split your markers into several groups beforehand, and then create a L.MarkerClusterGroup for each of those.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.