I have Esri Leaflet feature layers representing traffic accidents in multiple cluster marker groups. The cluster marker groups are created based on attributes that specify the geographic areas to which each feature belongs - they must be separate to ensure that features from different administrative boundaries are not clustered together. (There are only three different countries in this example, but eventually the same data at 51 different geographic areas will be shown at other zoom levels).

The user needs to be able to filter the data to show various accident severity levels. As long as a filter is set on a single feature layer, the filter displays the expected results. But when the filter is set on multiple feature layers, I experience multiple issues.

In the example below:

  • From the initial zoom, if 'fatal' is chosen as a severity level, I expect five features in England and two Scotland. Instead, 13 are shown in England (in two clusters) and one is shown in Scotland.

  • If 'serious' is chosen as severity level, the correct number of total features are shown (96), but they are in a single cluster rather than three different clusters (one per country).

I also tried using the setWhere() method of the esri-leaflet feature layer on each layer of a layer group, but the results were the same.

Is it possible to get correct results from a filter in this situation?

<!DOCTYPE html>
    <!-- Load Leaflet -->
    <link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css"/>
    <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>

    <!-- Load Esri Leaflet -->
    <script src="https://unpkg.com/esri-leaflet/dist/esri-leaflet.js"></script>

    <!-- Load Leaflet MarkerCluster and Esri Leaflet Cluster from CDN -->
    <link rel="stylesheet" type="text/css"
      href="https://unpkg.com/[email protected]/dist/MarkerCluster.Default.css"
    <link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/dist/MarkerCluster.css"
    <script src="https://unpkg.com/[email protected]/dist/leaflet.markercluster.js"
    <script src="https://unpkg.com/[email protected]/dist/esri-leaflet-cluster.js"

    <div id="query" class="leaflet-bar">
        <select id="severity">
          <!-- make sure to encase string values in single quotes for valid sql -->
          <option value="1=1">Any</option>
          <option value="Accident_S=1">Fatal</option>
          <option value="Accident_S=2">Serious</option>
          <option value="Accident_S=3">Slight</option>

      html, body, #map {
        margin:0; padding:0;  width : 100%; height : 100%;
        #query {
        position: absolute;
        top: 10px;
        right: 10px;
        z-index: 1000;
        background: white;
        padding: 1em;
      #query select {
        font-size: 16px;
        float: right;
      #severity {
        float: left
      #reference {
        float: right;
        margin-right: 50px;
    <div id="map"></div>
      var map = L.map('map').setView([54, -3.5], 6);

      var accidentsUrl = 'https://services5.arcgis.com/BMaSVn3J8DvKdFzq/arcgis/rest/services/accidents_2018_0730/FeatureServer/0';

      var accidents = L.esri.Cluster.featureLayer({
        url: accidentsUrl

      var accidentsEngland =  L.esri.Cluster.featureLayer({
            url: accidentsUrl,
            where: "Country = 'England'",
            maxClusterRadius: 500,

    var accidentsScotland =  L.esri.Cluster.featureLayer({
            url: accidentsUrl,
            where: "Country = 'Scotland'",
            maxClusterRadius: 400,

    var accidentsWales =  L.esri.Cluster.featureLayer({
            url: accidentsUrl,
            where: "Country = 'Wales'",
            maxClusterRadius: 300,

    var severity = document.getElementById('severity');
    severity.addEventListener('change', function() {
    // attempt to set filter on multiple feature layers


1 Answer 1


I had not realized that the setWhere() method resets an existing filter. Though a filter was set with one condition when each feature layer was created, all desired conditions have to be included when setWhere() is called.

The desired results are produced upon rewriting these lines in the example in the question.

    severity.addEventListener('change', function() {
    // reset filter feature layers
    accidentsEngland.setWhere(severity.value + " and Country = 'England'");
    accidentsScotland.setWhere(severity.value + " and Country = 'Scotland'");
    accidentsWales.setWhere(severity.value + " and Country = 'Wales'");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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