queryRenderedFeatures method

List<Feature> queryRenderedFeatures(
  1. dynamic geometry, [
  2. Map<String, dynamic>? options
])

Adds a listener for events of a specified type occurring on features in a specified style layer.

@param {string} type The event type to listen for; one of 'mousedown', 'mouseup', 'click', 'dblclick', 'mousemove', 'mouseenter', 'mouseleave', 'mouseover', 'mouseout', 'contextmenu', 'touchstart', 'touchend', or 'touchcancel'. mouseenter and mouseover events are triggered when the cursor enters a visible portion of the specified layer from outside that layer or outside the map canvas. mouseleave and mouseout events are triggered when the cursor leaves a visible portion of the specified layer, or leaves the map canvas. @param {string} layerId The ID of a style layer. Only events whose location is within a visible feature in this layer will trigger the listener. The event will have a features property containing an array of the matching features. @param {Function} listener The function to be called when the event is fired. @returns {MapboxMap} this Removes an event listener for layer-specific events previously added with MapboxMap#on.

@param {string} type The event type previously used to install the listener. @param {string} layerId The layer ID previously used to install the listener. @param {Function} listener The function previously installed as a listener. @returns {MapboxMap} this Returns an array of GeoJSON Feature objects representing visible features that satisfy the query parameters.

@param {PointLike|Array

@returns {Array

Implementation

// Defined in evented.dart
// MapboxMap on(String type, [dynamic layerIdOrListener, Listener listener]);

///  Removes an event listener for layer-specific events previously added with `MapboxMap#on`.
///
///  @param {string} type The event type previously used to install the listener.
///  @param {string} layerId The layer ID previously used to install the listener.
///  @param {Function} listener The function previously installed as a listener.
///  @returns {MapboxMap} `this`
// Defined in evented.dart
// MapboxMap off(String type, [dynamic layerIdOrListener, Listener listener]);

///  Returns an array of [GeoJSON](http://geojson.org/)
///  [Feature objects](https://tools.ietf.org/html/rfc7946#section-3.2)
///  representing visible features that satisfy the query parameters.
///
///  @param {PointLike|Array<PointLike>} [geometry] - The geometry of the query region:
///  either a single point or southwest and northeast points describing a bounding box.
///  Omitting this parameter (i.e. calling {@link MapboxMap#queryRenderedFeatures} with zero arguments,
///  or with only a [options] argument) is equivalent to passing a bounding box encompassing the entire
///  map viewport.
///  @param {Object} [options]
///  @param {Array<string>} `options.layers` An array of [style layer IDs](https://docs.mapbox.com/mapbox-gl-js/style-spec/#layer-id) for the query to inspect.
///    Only features within these layers will be returned. If this parameter is undefined, all layers will be checked.
///  @param {Array} `options.filter` A [filter](https://www.mapbox.com/mapbox-gl-js/style-spec/#other-filter)
///    to limit query results.
///  @param {boolean} [options.validate=true] Whether to check if the `options.filter` conforms to the Mapbox GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
///
///  @returns {Array<Object>} An array of [GeoJSON](http://geojson.org/)
///  [feature objects](https://tools.ietf.org/html/rfc7946#section-3.2).
///
///  The `properties` value of each returned feature object contains the properties of its source feature. For GeoJSON sources, only
///  string and numeric property values are supported (i.e. `null`, `Array`, and `Object` values are not supported).
///
///  Each feature includes top-level `layer`, `source`, and `sourceLayer` properties. The `layer` property is an object
///  representing the style layer to  which the feature belongs. Layout and paint properties in this object contain values
///  which are fully evaluated for the given zoom level and feature.
///
///  Only features that are currently rendered are included. Some features will////// not** be included, like:
///
///  - Features from layers whose `visibility` property is `"none"`.
///  - Features from layers whose zoom range excludes the current zoom level.
///  - Symbol features that have been hidden due to text or icon collision.
///
///  Features from all other layers are included, including features that may have no visible
///  contribution to the rendered result; for example, because the layer's opacity or color alpha component is set to
///  0.
///
///  The topmost rendered feature appears first in the returned array, and subsequent features are sorted by
///  descending z-order. Features that are rendered multiple times (due to wrapping across the antimeridian at low
///  zoom levels) are returned only once (though subject to the following caveat).
///
///  Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature
///  geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple
///  times in query results. For example, suppose there is a highway running through the bounding rectangle of a query.
///  The results of the query will be those parts of the highway that lie within the map tiles covering the bounding
///  rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile
///  will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple
///  tiles due to tile buffering.
///
///  @example
///  // Find all features at a point
///  var features = map.queryRenderedFeatures(
///    [20, 35],
///    { layers: ['my-layer-name'] }
///  );
///
///  @example
///  // Find all features within a static bounding box
///  var features = map.queryRenderedFeatures(
///    [[10, 20], [30, 50]],
///    { layers: ['my-layer-name'] }
///  );
///
///  @example
///  // Find all features within a bounding box around a point
///  var width = 10;
///  var height = 20;
///  var features = map.queryRenderedFeatures([
///    [point.x - width / 2, point.y - height / 2],
///    [point.x + width / 2, point.y + height / 2]
///  ], { layers: ['my-layer-name'] });
///
///  @example
///  // Query all rendered features from a single layer
///  var features = map.queryRenderedFeatures({ layers: ['my-layer-name'] });
///  @see [Get features under the mouse pointer](https://www.mapbox.com/mapbox-gl-js/example/queryrenderedfeatures/)
///  @see [Highlight features within a bounding box](https://www.mapbox.com/mapbox-gl-js/example/using-box-queryrenderedfeatures/)
///  @see [Filter features within map view](https://www.mapbox.com/mapbox-gl-js/example/filter-features-within-map-view/)
List<Feature> queryRenderedFeatures(dynamic geometry,
    [Map<String, dynamic>? options]) {
  if (options == null) {
    return jsObject
        .queryRenderedFeatures(geometry)
        .map((dynamic f) => Feature.fromJsObject(f))
        .toList();
  }
  return jsObject
      .queryRenderedFeatures(geometry, jsify(options))
      .map((dynamic f) => Feature.fromJsObject(f))
      .toList();
}