Esri / cluster-layer-js

One example of how to cluster many point features
http://esri.github.io/cluster-layer-js/
Apache License 2.0
62 stars 50 forks source link

Refreshing the layer with new query parameters #46

Open bsnider opened 7 years ago

bsnider commented 7 years ago

Hi @alaframboise, I'm implementing clusterfeaturelayer.js into a WAB widget. I'm using the layer as the result for a widget that executes queries (with where, geometry, unit, distance params) on a FL.

The user will be updating and executing the search multiple times, but I don't see a way to modify the clusterfeaturelayer once it has been instantiated and added to the map. It appears the CFL has a refresh method, but it doesn't appear to be working. Also, I'm not sure how to set new params.

Can you think of a quick way to do this? Ideally, it'd look something like this:

        this._clusterLayer.setWhere(whereString);
        if (this._searchByLocation == true) {
          this._clusterLayer.setGeometry(this._clickLocation);
          this._clusterLayer.setDistance($(".dist-input").val());
          this._clusterLayer.setUnits( $(".unit-input").val());
        }
        this._clusterLayer.refresh();

I've also modified your code slightly to take geometry params, as well:

      this._where = options.where || null;
      this._geom = options.geometry || null;
      this._dist = options.distance || null;
      this._units = options.units || null;
    // Get the features by IDs
    _getObjectIds: function(extent) {
      // debug
      // this._startGetOids = new Date().valueOf();
      // console.debug('#_getObjectIds start');

      if (this.url) {
        var ext = extent || this._map.extent;
        this._query.objectIds = null;
        if (this._where) {
          this._query.where = this._where;
        }
        if (this._geom) {
          this._query.geometry = this._geom;
        } else if (!this.MODE_SNAPSHOT) {
          this._query.geometry = ext;
        }
        if (this._dist) {
          this._query.distance = this._dist;
        }
        if (this._units) {
          this._query.units = this._units;
        }
        if (!this._query.geometry && !this._query.where) {
          this._query.where = '1=1';
        }
        this.queryTask.executeForIds(this._query).then(
          lang.hitch(this, '_onIdsReturned'), this._onError
        );
      }
    },