Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Layer

JMap.Layer

Layer related methods.

Index

Functions

attributeExists

  • attributeExists(layerId: JId, attributeName: string): boolean
  • JMap.Layer.attributeExists

    Returns true if the layer has the given attribute.

    throws

    Error if layer is not found

    example
    
     // returns true if the attribute named "SPECIES" exist on layer id=4
     JMap.Layer.attributeExists(4, "SPECIES")

    Parameters

    • layerId: JId

      The JMap layer id

    • attributeName: string

      The JMap attribute name

    Returns boolean

deleteLayer

  • deleteLayer(layerId: JId): void
  • JMap.Layer.deleteLayer

    Deletes the layer in the data store and in the map.

    The layer is not deleted server side, but only in the browser.

    Use this function if you want to dynamically remove a layer.

    throws

    Error if layer is not found

    example
    
    // Removes layer 4 (only client side)
    JMap.Layer.deleteLayer(4)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns void

ensureLayerIsVisible

  • ensureLayerIsVisible(layerId: JId): void
  • JMap.Layer.ensureLayerIsVisible

    Make sure a layer is visible on the Map. All parent layers will also be made visible

    example
    
    // show layer id=5 (and all parent layers)
    JMap.Layer.ensureLayerIsVisible(5)
    

    Parameters

    • layerId: JId

      The JMap layer id

    Returns void

ensureLayersAreVisible

  • ensureLayersAreVisible(layerIds: JId[]): void
  • JMap.Layer.ensureLayersAreVisible

    Make sure that all specified layers are visible on the Map. All parent layers of all Layers will also be made visible

    example
    
    // show layer ids 5, 6 and 7 (and all parent layers)
    JMap.Layer.ensureLayersAreVisible([5, 6, 7])
    

    Parameters

    • layerIds: JId[]

      An array of JMap layer ids

    Returns void

exists

  • exists(layerId: JId): boolean
  • JMap.Layer.exists

    Returns true if a layer having the id exists.

    example
    
    // returns true if layer id=3 exists
    JMap.Layer.exists(3)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns boolean

getById

  • JMap.Layer.getById

    Returns the JMap layer having the id.

    throws

    Error if no layer found for the id

    example
    
    // returns the JMap layer id=3
    JMap.Layer.getById(3)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns JLayerTreeElement

getDescription

  • getDescription(layerId: JId): string
  • JMap.Layer.getDescription

    Returns the descrition of the layer.

    throws

    Error if no layer found for the id

    example
    
    // returns the description of layer id=3
    JMap.Layer.getDescription(3)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns string

getEPSG4326Extent

  • JMap.Layer.getEPSG4326Extent

    Returns the extent of the layer in ESPG:4326 coordinates

    With a JMap Cloud server, a call is made to the server.

    With a JMap 7 server, no call to server is made, returns the cached extent.

    example
    
    // returns the bounding box (JBoundaryBox) of the layer ID 3 in decimal degrees
    JMap.Layer
     .getEPSG4326Extent(3)
     .then(extent => console.info("Extent of layer id=3", extent))
     .catch(error => console.error(error))

    @throws Error if no layer found for the id @param layerId The JMap layer id

    Parameters

    Returns Promise<JBoundaryBox | null>

getLayerAttribute

  • JMap.Layer.getLayerAttribute

    Returns the attribute descriptor for a given layer and attribute

    throws

    Error if layer or attribute not found

    example
    
     // returns the layer attribute descriptor
     JMap.Layer.getLayerAttribute(4, "SPECIES")

    Parameters

    • layerId: JId

      The JMap layer id

    • attributeName: string

      The JMap attribute name

    Returns JLayerAttribute

getLayerAttributes

  • JMap.Layer.getLayerAttributes

    Returns all attribute descriptors for a particuler layer

    throws

    Error if layer is not found

    example
    
     JMap.Layer.getLayerAttributes(4)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns JLayerAttribute[]

getLayerIds

  • getLayerIds(): JId[]
  • JMap.Layer.getLayerIds

    Returns an array with JMap layer ids.

    The array order is the same as the one in the tree.

    If no project is loaded, returns en empty array.

    This function is equivalent to :

    JMap.Layer.getLayers().map(layer => layer.id)
    example
    
    // returns all JMap layer ids
    JMap.Layer.getLayerIds()

    Returns JId[]

getLayerTree

  • JMap.Layer.getLayerTree

    Returns project's layer tree.

    The layer tree is an array of tree element.

    A tree element is a layer group or a layer.

    A layer group contains layer and/or other layer group, and has a negative id.

    A layer has a positive id.

    If no project is loaded, returns an empty array.

    example
    
    // returns the entire layer tree of the project
    JMap.Layer.getLayerTree()

    Returns JLayerTree

getLayerTreeElementsById

  • getLayerTreeElementsById(): object
  • JMap.Layer.getLayerTreeElementsById

    Returns a map (= a javascript object) where :

    • the key is the tree element id
    • the value is the tree element

    A tree element is a layer group or a layer.

    A layer group contains layer(s) and/or other layer group(s), and has a negative id.

    A layer has a positive id.

    If no project is loaded, returns en empty object.

    example
    
    // returns a map of layer elements defined by layer id
    JMap.Layer.getLayerTreeElementsById()

    Returns object

getLayers

  • JMap.Layer.getLayers

    Returns an array with JMap layers.

    The array order is the same as the one in the tree.

    If no project is loaded, returns en empty array.

    example
    
    // returns all JMap layers
    JMap.Layer.getLayers()

    Returns JLayer[]

getMetadataSchema

  • JMap.Layer.getMetadataSchema

    Returns the metadata schema associated with the current project's layers.

    The layer metadata schema is an array of JLayerMetadataSchemaItem.

    If no project is loaded, returns an empty array.

    example
    
    // returns the metadata schema
    JMap.Layer.getMetadataSchema()

    Returns JLayerMetadataSchemaItem[]

getName

  • getName(layerId: JId): string
  • JMap.Layer.getName

    Returns the name of the layer.

    throws

    Error if no layer found for the id

    example
    
    // returns the name of layer id=3
    JMap.Layer.getName(3)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns string

getSelfOrChildren

  • JMap.Layer.getSelfOrChildren

    If the layerId is a layer returns it. If the layerId is a layer group, returns all of its layers children (remove all layer groups).

    Returns an empty array if it's an empty layer group

    throws

    Error if no layer found for the id

    example
    
    // returns an array with only JMap layers (no layer group)
    JMap.Layer.getSelfOrChildren(3)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns JLayer[]

getVectorLayerIds

  • getVectorLayerIds(): JId[]
  • JMap.Layer.getVectorLayerIds

    Returns an array with vector JMap layer ids.

    Vector Layers are layers that can be selected on the map and served via Vector Tiles or geoJSON, as opposed to raster layers for instance.

    The array order is not garanteed to be the same as the one in the tree.

    If no project is loaded, returns en empty array.

    This function is equivalent to :

    JMap.Layer.getVectorLayers().map(layer => layer.id)
    example
    
    // returns all vector JMap layer ids
    JMap.Layer.getVectorLayerIds()

    Returns JId[]

getVectorLayers

  • JMap.Layer.getVectorLayers

    Returns an array with vector JMap layers.

    Vector Layers are layers that can be selected on the map and served via Vector Tiles or geoJSON, as opposed to raster layers for instance.

    The array order is not garanteed to be the same as the one in the tree.

    If no project is loaded, returns en empty array.

    example
    
    // returns all vector JMap layers
    JMap.Layer.getVectorLayers()

    Returns JLayer[]

hasInformationReport

  • hasInformationReport(layerId: JId): boolean
  • JMap.Layer.hasInformationReport

    Returns true if the given layer has an information report set in JMap Admin.

    throws

    if layerId not valid or layer not found

    example
    
    // returns true if JMap layer id="3" has an information report set in JMap admin
    JMap.Layer.hasInformationReport(3)

    Parameters

    • layerId: JId

      the JMap layer id

    Returns boolean

isAllLayerParentsVisible

  • isAllLayerParentsVisible(layerId: JId): boolean
  • JMap.Layer.isAllLayerParentsVisible

    Returns true if all parents of the element have the visibility property equals to true.

    If element has no parent it returns true.

    throws

    Error if no layer found for the id

    example
    
    // returns true if all parents of layer id=3 have the property visible set to true
    JMap.Layer.isAllLayerParentsVisible(3)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns boolean

isSelectableById

  • isSelectableById(layerId: JId): boolean
  • JMap.Layer.isSelectableById

    Returns the tree element selectable property.

    The selectable property is initialy defined on the project, and can be changed by the user through the JMap NG Core library.

    If this property is false, the layer's features can't be selected on the map by user interaction, or by API calls.

    If this property is true, the layer's features can be selected.

    throws

    Error if no layer found for the id or of layer is not a vector layer

    example
    
    // returns false if layer id=3 is not selectable
    JMap.Layer.isSelectableById(3)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns boolean

isVectorLayerById

  • isVectorLayerById(layerId: JId): boolean
  • JMap.Layer.isVectorLayerById

    returns true if specified layer is a vector layer

    example
    
    // returns true if layer id 5 is a vector layer
    JMap.Layer.isVectorLayerById(5)

    Parameters

    • layerId: JId

      the JMap layer Id

    Returns boolean

isVisible

  • isVisible(layerId: JId, checkParentVisibility?: undefined | false | true): boolean
  • JMap.Layer.isVisible

    Returns the tree element visibility property.

    The visibility property is initialy defined on the project, and can be changed by the user through the JMap NG Core library.

    If this property is false, the layer cannot be displayed on the map.

    If it's true, the layer can be rendered on the map. The layer is rendered depending on the current map scale of the map, and the min / max scale defined for this layer.

    throws

    Error if no layer found for the id

    example
    
    // returns false if layer id=3 is not set as visible
    JMap.Layer.isVisible(3)

    Parameters

    • layerId: JId

      The JMap layer id

    • Optional checkParentVisibility: undefined | false | true

      If true will check if all parent elements have the property visible equals to true

    Returns boolean

openInformationReportInNewTab

  • openInformationReportInNewTab(layerId: JId, featureIds: JId[]): Promise<string>
  • JMap.Layer.openInformationReportInNewTab

    Open a new tab in order to display the information report for the given layer id and feature ids

    throws

    if layerId not valid or layer not found, or layer has no information report set, or featureIds is not an array or empty

    example
    
    // open a new tab that display the information report of features ids=33 and 44, for layer id=3
    JMap.Layer
     .openInformationReportInNewTab(3, [33, 44])
     .then(() => console.log("Information report opened in new tab"))
     .catch(error => console.error("Cannot open the information report in new tab", error))

    Parameters

    • layerId: JId

      the JMap layer id

    • featureIds: JId[]

      the JMap feature ids

    Returns Promise<string>

setLayerGroupExpansion

  • setLayerGroupExpansion(layerGroupId: JId, isExpanded: boolean): void
  • JMap.Layer.setLayerGroupExpansion

    Set the layer group expansion state.

    throws

    Error if layer group is not found, or is not a layer group but a layer

    example
    
    // Expand the layer group id -4
    JMap.Layer.setLayerGroupExpansion(-4, true)

    Parameters

    • layerGroupId: JId

      The JMap layer group id

    • isExpanded: boolean

      if true will expand, if false will collapse the layer group

    Returns void

setLayerGroupsExpansion

  • JMap.Layer.setLayerGroupsExpansion

    Set the group expansion state of multiple layer groups.

    throws

    Error if any layer group is not found for any group id, or if any group found is not a layer group but a layer

    example
    
    // Expand the layer group id -4, collapse group id -5
    JMap.Layer.setLayerGroupsExpansion([{layerGroupId: -4, open: true}, {layerGroupId: -5, open: false}])

    Parameters

    Returns void

setLayersSelectability

  • JMap.Layer.setLayersSelectability

    Set the selectability property of multiple layers.

    For each layer:

    If it's a JMap layer, it applies the selectability to it.

    The selectability property is initialy defined on the project, and can be changed by the user through the JMap NG Core library.

    If this property is true, the layer's features can be selected on the map.

    throws

    Error if any layer is not found for any of the ids, or if any of the layers is not a vector layer

    example
    
    // show layers id=5 and 6, hide layer 3
    JMap.Layer.setLayersSelectability([
       {layerId: 5, selectability: true},
       {layerId: 6, selectability: true},
       {layerId: 3, selectability: false}
    ])
    

    Parameters

    Returns void

setLayersVisibility

  • JMap.Layer.setLayersVisibility

    Set the visibility property of multiple layers.

    For each layer:

    If it's a JMap layer, it apply the visibility to it.

    The visibility property is initialy defined on the project, and can be changed by the user through the JMap NG Core library.

    If this property is false, the layer cannot be displayed on the map.

    If it's true, the layer can be rendered on the map. The layer is rendered depending on the current map scale of the map, and the min / max scale defined for this layer.

    throws

    Error if any layer is not found for any of the ids

    example
    
    // show layers id=5 and 6, hide layer 3
    JMap.Layer.setLayersVisibility([
       {layerId: 5, visibility: true},
       {layerId: 6, visibility: true},
       {layerId: 3, visibility: false}
    ])
    

    Parameters

    Returns void

setSelectabilityById

  • setSelectabilityById(layerId: JId, selectability: boolean, ignoreVisibility?: undefined | false | true): void
  • JMap.Layer.setSelectabilityById

    Set the selectability property of the layer.

    If it's true, the layer's features can be selected on the map.

    throws

    Error if no layer found for the id or if it is not a vector layer

    example
    
    // make layer id=5 selectable
    JMap.Layer.setSelectabilityById(5, true)
    
    // make layer id=3 unselectable (will clear the pre-existing selection if present)
    JMap.Layer.setSelectabilityById(3, false)

    Parameters

    • layerId: JId

      The JMap layer id

    • selectability: boolean

      The new selectability property value for the layer

    • Optional ignoreVisibility: undefined | false | true

      If false or unspecified will make sure that the layer is visible

    Returns void

setVisible

  • setVisible(layerId: JId, isVisible: boolean): void
  • JMap.Layer.setVisible

    Set the visibility property of the layer.

    If it's a JMap layer, it apply the visibility to it.

    The visibility property is initialy defined on the project, and can be changed by the user through the JMap NG Core library.

    If this property is false, the layer cannot be displayed on the map.

    If it's true, the layer can be rendered on the map. The layer is rendered depending on the current map scale of the map, and the min / max scale defined for this layer.

    throws

    Error if no layer found for the id

    example
    
    // show layer id=5
    JMap.Layer.setVisible(5, true)
    
    // hide layer id=3
    JMap.Layer.setVisible(3, false)

    Parameters

    • layerId: JId

      The JMap layer id

    • isVisible: boolean

      The new visibility property value for the layer

    Returns void