Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Selection

JMap.Map.Selection

You can select features on the map with JMap, this where you can manage the selection.

You can select on the map programatically by passing a location, or by passing features.

And you can also removing some or all features of the selection.

Index

Functions

addFeaturesToLayerSelection

  • addFeaturesToLayerSelection(layerId: JId, features: Feature | Feature[]): void
  • JMap.Map.Selection.addFeaturesToLayerSelection

    Add to the current layer selection the provided feature(s).

    Don't cancel previous selection, but add features to it.

    throws

    Error if layer is not found or features format is not good

    example
    
    // Add one feature (id = 234) to layer 4 selection
    JMap.Map.Selection.addFeaturesToLayerSelection(4, {
     id: 234,
     type: "Point",
     geometry: {...},
     properties: [...]
    })
    
    // Add 2 features (id = 234 and 567) to layer 4 selection
    JMap.Map.Selection.addFeaturesToLayerSelection(4, [
      {
       id: 234,
       type: "Point",
       geometry: {...},
       properties: [...]
      },
      {
       id: 567,
       type: "Point",
       geometry: {...},
       properties: [...]
      }
    ])

    Parameters

    • layerId: JId

      The JMap layer id

    • features: Feature | Feature[]

      The feature(s) that will be selected on the map

    Returns void

clearLayersSelection

  • clearLayersSelection(layerIds: JId[]): void
  • JMap.Map.Selection.clearLayersSelection

    Clear selection for all specified layers.

    throws

    Error if a layer id is provided but not found

    example
    
    // Clear selection of layer 4, 5 and 6
    JMap.Map.Selection.clearLayersSelection([4, 5, 6])

    Parameters

    • layerIds: JId[]

      The JMap layer ids passed as an array

    Returns void

clearSelection

  • clearSelection(layerId?: JId): void
  • JMap.Map.Selection.clearSelection

    Clear all selection.

    If a layer id is provided, clear only the layer selection, else clear selection of all layers.

    throws

    Error if a layer id is provided but not found

    example
    
    // Clear selection of layer 4
    JMap.Map.Selection.clearSelection(4)
    
    // Clear selection of all layers
    JMap.Map.Selection.clearSelection()

    Parameters

    • Optional layerId: JId

      The JMap layer id

    Returns void

getSelectedFeatureIdsForLayer

  • getSelectedFeatureIdsForLayer(layerId: JId): string[]
  • JMap.Map.Selection.getSelectedFeatureIdsForLayer

    Returns the current selected feature ids for a specific JMap layer.

    This function is the equivalent of that code :

    // returns the same as JMap.Map.getSelectedFeatureIdsForLayer(3)
    JMap.Map.Selection
       .getSelectedFeaturesForLayer(layerId)
       .map(feature => feature.id)
    example
    
    // returns the current selected feature ids for layer 3
    JMap.Map.Selection.getSelectedFeatureIdsForLayer(3)

    Parameters

    Returns string[]

getSelectedFeatures

  • JMap.Map.Selection.getSelectedFeatures

    Returns the current map selection as a javascript map (= a javascript object) where :

    • the key is the layer element id
    • the value is an array of feature (an empty array if layer doesn't have features selected)
    example
    
    // returns the current selected features by layer id
    JMap.Map.Selection.getSelectedFeatures()

    Returns JMapSelection

getSelectedFeaturesForLayer

  • getSelectedFeaturesForLayer(layerId: JId): Feature[]
  • JMap.Map.Selection.getSelectedFeaturesForLayer

    Returns the current selected features for a specific JMap layer.

    example
    
    // returns the current selected features for layer 3
    JMap.Map.Selection.getSelectedFeaturesForLayer(3)

    Parameters

    Returns Feature[]

    an array of GeoJSON features

getSelectionCentroid

  • JMap.Map.Selection.getSelectionCentroid

    throws

    Error if selection is empty

    example
    
    // get the current selected features by layer id
    const selection = JMap.Map.Selection.getSelectedFeatures()
    
    // compute the centroid of the selection
    const centroid = JMap.Map.Selection.getSelectionCentroid(selection)
    
    console.log(`centroid of selection is located at: LAT: ${centroid.y}, LON: ${centroid.x}`)

    Parameters

    Returns JLocation

    a JLocation representing the centroid of the selection

isEmpty

  • isEmpty(): boolean
  • JMap.Map.Selection.isEmpty

    Returns true if no selection is made for all layers.

    If at least one feature is selected on one layer, returns false.

    example
    
    // Returns true if no selection is made for all layers.
    JMap.Map.Selection.isEmpty()

    Returns boolean

isEmptyByLayerId

  • isEmptyByLayerId(layerId: JId): boolean
  • JMap.Map.Selection.isEmptyByLayerId

    Returns true if no selection is made for the specified layer.

    If at least one feature is selected on the layer, returns false.

    example
    
    // Returns true if no selection is made for layer id 5.
    JMap.Map.Selection.isEmptyByLayerId(5)

    Parameters

    Returns boolean

removeFeaturesFromLayerSelection

  • removeFeaturesFromLayerSelection(layerId: JId, featureIds: JId | JId[]): void
  • JMap.Map.Selection.removeFeaturesFromLayerSelection

    Remove from current layer selection the provided feature(s).

    Don't cancel previous selection, just remove feature(s) from it.

    throws

    Error if layer is not found or feature id(s) format is not good

    example
    
    // Remove one feature (id = "234") from layer 4 selection
    JMap.Map.Selection.removeFeaturesFromLayerSelection(4, "234")
    
    // Remove 2 features (id = "234" and "567") from layer 4 selection
    JMap.Map.Selection.removeFeaturesFromLayerSelection(4, [ "234", "567" ])

    Parameters

    • layerId: JId

      The JMap layer id

    • featureIds: JId | JId[]

      The feature id(s) that will be remove from the layer selection

    Returns void

selectOnAllLayersAtLocation

  • JMap.Map.Selection.selectOnAllLayersAtLocation

    Select for all layers the features that are at the location.

    Same behavior as if you were clicking on the map in order to select features.

    throws

    Error if location format is not good

    example
    
    // Process a selection on the map for all layers, at the location in params
    JMap.Map.Selection.selectOnAllLayersAtLocation({ x: 34.23, y: 55.5 })

    Parameters

    Returns JMapSelection

    The new feature selection

selectOnAllLayersFromCircle

  • JMap.Map.Selection.selectOnAllLayersFromCircle

    Select for all layers the features that intersect the circle.

    throws

    Error if circle format is not good

    example
    
    // Process a selection on the map for all layers,
    // select all features that intersect the circle
    JMap.Map.Selection.selectOnAllLayersFromCircle({
      center: { x: 34.23, y: 55.5 },
      radius: 100
    })

    Parameters

    Returns JMapSelection

    The new feature selection

selectOnAllLayersFromLine

  • JMap.Map.Selection.selectOnAllLayersFromLine

    Select for all layers the features that intersect the line.

    throws

    Error if line format is not good

    example
    
    // Process a selection on the map for all layers,
    // select all features that intersect the line
    JMap.Map.Selection.selectOnAllLayersFromLine([
      [ 34.23, 55.5 ],
      [ 36.24, 14.9 ],
      [ 45.23, 25.2 ]
    ])

    Parameters

    Returns JMapSelection

    The new feature selection

selectOnAllLayersFromPolygon

  • JMap.Map.Selection.selectOnAllLayersFromPolygon

    Select for all layers the features that intersect the polygon.

    throws

    Error if polygon format is not good

    example
    
    // Process a selection on the map for all layers,
    // select all features that intersect the polygon
    JMap.Map.Selection.selectOnAllLayersFromPolygon([
      [ 34.23, 55.5 ],
      [ 36.24, 14.9 ],
      [ 45.23, 25.2 ],
      [ 34.23, 55.5 ] // first and last point of a polygon must be equals
    ])

    Parameters

    Returns JMapSelection

    The new feature selection

selectOnOneLayerAtLocation

  • JMap.Map.Selection.selectOnOneLayerAtLocation

    Select for specific layer its features that are at the location.

    Same behavior as if you were clicking on the map in order to select features, but for only one layer.

    throws

    Error if layer is not found or location format is not good

    example
    
    // Process a selection on the map for layer id=4, at the location in params
    JMap.Map.Selection.selectOnOneLayerAtLocation(4, { x: 34.23, y: 55.5 })

    Parameters

    Returns Feature[]

    The features array

selectOnOneLayerFromCircle

  • JMap.Map.Selection.selectOnOneLayerFromCircle

    Select for specific layer its features that intersect the circle.

    throws

    Error if layer is not found or if circle format is not good

    example
    
    // Process a selection on the map for layer id=4,
    // selecting features intersecting the circle
    JMap.Map.Selection.selectOnOneLayerFromCircle(
      4, //layer id
      {
        center: { x: 34.23, y: 55.5 },
        radius: 100
      }
    )

    Parameters

    Returns Feature[]

    The features array

selectOnOneLayerFromLine

  • JMap.Map.Selection.selectOnOneLayerFromLine

    Select for specific layer its features that intersect the line.

    throws

    Error if layer is not found or if line format is not good

    example
    
    // Process a selection on the map for layer id=4,
    // selecting features that intersect the line
    JMap.Map.Selection.selectOnOneLayerFromLine(
      4, // The layer id
      [
        [ 34.23, 55.5 ],
        [ 36.24, 14.9 ],
        [ 45.23, 25.2 ]
      ]
    )

    Parameters

    Returns Feature[]

    The features array

selectOnOneLayerFromPolygon

  • JMap.Map.Selection.selectOnOneLayerFromPolygon

    Select for specific layer its features that intersect the line.

    throws

    Error if layer is not found or if line format is not good

    example
    
    // Process a selection on the map for layer id=4, selecting features intersecting the line
    JMap.Map.Selection.selectOnOneLayerFromPolygon(
      4, // The layer id
      [
        [ 34.23, 55.5 ],
        [ 36.24, 14.9 ],
        [ 45.23, 25.2 ],
        [ 34.23, 55.5 ]
      ]
    )

    Parameters

    Returns Feature[]

    The features array

setLayerSelection

  • setLayerSelection(layerId: JId, features: Feature | Feature[]): void
  • JMap.Map.Selection.setLayerSelection

    Set the selection for a specific layer.

    Cancel previous selection if exist, and replace by new selection

    throws

    Error if layer is not found or features format is not good

    example
    
    // will select feature (id = 234) of layer 4 on the map
    JMap.Map.Selection.setLayerSelection(4, {
     id: 234,
     type: "Point",
     geometry: {...},
     properties: [...]
    })
    
    // will select two features (id = 234 and 567) of layer 4 on the map
    JMap.Map.Selection.setLayerSelection(4, [
      {
       id: 234,
       type: "Point",
       geometry: {...},
       properties: [...]
      },
      {
       id: 567,
       type: "Point",
       geometry: {...},
       properties: [...]
      }
    ])

    Parameters

    • layerId: JId

      The JMap layer id

    • features: Feature | Feature[]

      The new selection. This is what will be selected on the map

    Returns void

setLayersSelection

  • JMap.Map.Selection.setLayersSelection

    Set the selection for multiple layers.

    For each layer:

    sets the selection of the specified layer with the new selection. Previous selection will be cleared.

    throws

    Error if any layer is not found for any of the ids, or if any of the layers is not a vector layer or if the params array is either not an array or an empty array

    example
    
    // set selection on layers id=5 and 6. Layer 6 selection will be emptied (empty array passed)
    JMap.Map.Selection.setLayersSelection([
       {layerId: 5, selectability: [...features...]},
       {layerId: 6, selectability: []}
    ])
    

    Parameters

    Returns void