Options
All
  • Public
  • Public/Protected
  • All
Menu

Module DynamicFilter

JMap.Layer.DynamicFilter

Methods used to manage dynamic filters for a layer.

Index

Functions

canAttributeTypeAcceptMultipleValuesOperators

  • JMap.Layer.DynamicFilter.canAttributeTypeAcceptMultipleValuesOperators

    Returns true if the attribute type accept multiple value operator ("EQUALS" or "NOT_EQUALS" for example).

    This function is safe, it throws nothing.

    example
    
    // returns true
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptMultipleValuesOperators("string")
    
    // returns true
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptMultipleValuesOperators("number")
    
    // returns false
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptMultipleValuesOperators("date")
    
    // returns false
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptMultipleValuesOperators("datetime")
    
    // returns false
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptMultipleValuesOperators("boolean")

    Parameters

    Returns boolean

canAttributeTypeAcceptTwoValuesOperators

  • JMap.Layer.DynamicFilter.canAttributeTypeAcceptTwoValuesOperators

    Returns true if the attribute type accept two value operator ("IS_IN_RANGE").

    This function is safe, it throws nothing.

    example
    
    // returns false
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptTwoValuesOperators("string")
    
    // returns true
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptTwoValuesOperators("date")
    
    // returns true
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptTwoValuesOperators("datetime")
    
    // returns true
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptTwoValuesOperators("number")
    
    // returns false
    JMap.Layer.DynamicFilter.canAttributeTypeAcceptTwoValuesOperators("boolean")

    Parameters

    Returns boolean

createCondition

  • JMap.Layer.DynamicFilter.createCondition

    Add a new condition for a JMap Layer dynamic filter.

    Returns the new conditon id, and set the id in the object passed in parameter

    throws

    Error if invalid condition

    example
    
    const newCondition = {
     layerId: 3,
     attributeName: "city"
     filterOperator: "EQUALS"
     value: ["Paris", "Ottawa"]
    }
    JMap.Layer.DynamicFilter.createCondition(newCondition)
    console.log(`New condition id="${newCondition.id}" created`)

    Parameters

    Returns number

existSimilarCondition

  • JMap.Layer.DynamicFilter.existSimilarCondition

    Returns true if the condition already exist for the layer.

    It doesn't check the id of the condition, only the values.

    throws

    if condition is not correct

    example
    
    // log in console a message if this condition already exist
    if (!JMap.Layer.DynamicFilter.existSimilarCondition(myCondition)) {
     console.log("Same condition values already exist")
    }

    Parameters

    • condition: JDynamicFilterCondition

      The condition to verify

    • Optional isUpdate: undefined | false | true

      tell if the check is for a creation or an update

    Returns boolean

getAllLastOperatorUnits

  • getAllLastOperatorUnits(): string[]
  • JMap.Layer.DynamicFilter.getAllLastOperatorUnits

    Returns list of all "LAST" operator available units:

    • "mi": minutes
    • "h": hours
    • "d": days
    • "w": weeks
    • "mo": months
    • "y": years
    example
    
    const allUnits = JMap.Layer.DynamicFilter.getAllLastOperatorUnits()
    console.log(`All unit for 'LAST' operator are: ${allUnits.join(", ")}`)

    Returns string[]

getAllMultipleValuesOperators

  • JMap.Layer.DynamicFilter.getAllMultipleValuesOperators

    Returns the list of all operators that require an array values.

    Warning: EQUALS, NOT_EQUALS are operators that takes an array of values, they act like "IN" or "NOT IN".

    example
    
    // returns the list of all operators that require two values
    const allMultipleValuesOperators = JMap.Layer.DynamicFilter.getAllMultipleValuesOperators()
    console.log(allMultipleValuesOperators)

    Returns JLAYER_DYNAMIC_FILTER_OPERATORS[]

getAllOperators

  • JMap.Layer.DynamicFilter.getAllOperators

    Returns the list of all availables operators

    example
    
    // returns the list of all available operators
    const allOperators = JMap.Layer.DynamicFilter.getAllOperators()
    console.log(allOperators)

    Returns JLAYER_DYNAMIC_FILTER_OPERATORS[]

getAllTwoValuesOperators

  • JMap.Layer.DynamicFilter.getAllTwoValuesOperators

    Returns the list of all operators that require two values (ex: IS_IN_RANGE, IS_NOT_IN_RANGE)

    example
    
    // returns the list of all operators that require two values
    const allTwoValuesOperators = JMap.Layer.DynamicFilter.getAllTwoValuesOperators()
    console.log(allTwoValuesOperators)

    Returns JLAYER_DYNAMIC_FILTER_OPERATORS[]

getByLayerId

  • JMap.Layer.DynamicFilter.getByLayerId

    Returns the dynamic filter of a given layer id

    throws

    Error if layer is not found

    example
    
    // returns the filter of layer id=3
    const filter = JMap.Layer.DynamicFilter.getByLayerId(3)
    console.log(filter)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns JDynamicFilter

getConditionError

  • JMap.Layer.DynamicFilter.getConditionError

    Returns a string error (human readable) if the condition is not correct.

    If correct returns undefined.

    It doesn't check the id of the condition.

    example
    
    // returns a string error if the condition is not correct
    const error = JMap.Layer.DynamicFilter.getConditionError({
     layerId: 3,
     attributeName: "City",
     filterOperator: "EQUALS",
     value: "Montreal"
    })
    console.log("Error:", error)

    Parameters

    Returns string | undefined

getConditionValueError

  • JMap.Layer.DynamicFilter.getConditionValueError

    Returns an error if value is not correct.

    This function is safe, it throws nothing.

    example
    
    // returns an error
    const error = JMap.Layer.DynamicFilter.getConditionValueError("IS_IN_RANGE", "date", date1)
    
    // if date1 and date2 are not date objects, or date1 >= date2, returns an error
    const error = JMap.Layer.DynamicFilter.getConditionValueError("IS_IN_RANGE", "date", [date1, date2])
    
    // returns an error value must be an array for EQUALS operator
    const error = JMap.Layer.DynamicFilter.getConditionValueError("EQUALS", "string", ["Montreal"])
    
    // no error, returns undefined
    const error = JMap.Layer.DynamicFilter.getConditionValueError("EQUALS", "string", ["Montreal"])
    
    // no error, returns undefined
    const error = JMap.Layer.DynamicFilter.getConditionValueError("EQUALS", "string", [""])
    
    // returns an error
    const error = JMap.Layer.DynamicFilter.getConditionValueError("EQUALS", "string", undefined)
    
    // returns an error
    const error = JMap.Layer.DynamicFilter.getConditionValueError("IS_EMPTY", "string")
    
    // no error, returns undefined
    const error = JMap.Layer.DynamicFilter.getConditionValueError("EQUALS", "number", "test")
    
    // no error, returns undefined
    const error = JMap.Layer.DynamicFilter.getConditionValueError("EQUALS", "number", 22)

    Parameters

    Returns string | undefined

getIsBetweenValuesError

  • getIsBetweenValuesError(attributeType: JLAYER_ATTRIBUTE_TYPES, value1: any, value2: any): string | undefined
  • JMap.Layer.DynamicFilter.getIsBetweenValuesError

    Returns true if the attribute type accept two value operator ("IS_IN_RANGE").

    This function is safe, it throws nothing.

    example
    
    // returns an error
    const error = JMap.Layer.DynamicFilter.getIsBetweenValuesError("number", 4, 2)
    
    // returns no error
    const error = JMap.Layer.DynamicFilter.getIsBetweenValuesError("number", 2, 4)

    Parameters

    Returns string | undefined

getNowValue

  • getNowValue(): string
  • JMap.Layer.DynamicFilter.getNowValue

    Returns the now value, used for date.

    example
    
    const nowValue = JMap.Layer.DynamicFilter.getNowValue()
    console.log(`Now value is '${nowValue}'`) // display "Now value is 'Now'"

    Returns string

getOperatorsForAttributeType

  • JMap.Layer.DynamicFilter.getOperatorsForAttributeType

    Returns list of all operators available for a given attribute type.

    example
    
    // returns the list of all operators that require two values
    const operators = JMap.Layer.DynamicFilter.getOperatorsForAttributeType("number")
    console.log("Available operators for attribute type:", operators)

    Parameters

    Returns JLAYER_DYNAMIC_FILTER_OPERATORS[]

isActive

  • isActive(layerId: JId): boolean
  • JMap.Layer.DynamicFilter.isActive

    Returns true if the layer has a dynamic filter, and its filter is active.

    Doesn't throw if the given layer doesn't support dynamic filter.

    example
    
    // returns true if layer has dynamic filter, and filter is active
    JMap.Layer.DynamicFilter.isActive(5)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns boolean

isAvailable

  • isAvailable(layerId: JId): boolean
  • JMap.Layer.DynamicFilter.isAvailable

    Returns true if the layer support dynamic filter.

    For example raster layers don't support dynamic filter.

    example
    
    // returns true if layer id=5 support dynamic filter, else false
    JMap.Layer.DynamicFilter.isAvailable(5)

    Parameters

    • layerId: JId

      The JMap layer id

    Returns boolean

isConditionValid

  • JMap.Layer.DynamicFilter.isConditionValid

    Returns a string error (human readable) if the condition is not correct.

    If correct returns undefined.

    It doesn't check the id of the condition.

    example
    
    // log in console a message if the condition is not valid
    if (!JMap.Layer.DynamicFilter.isConditionValid(myCondition)) {
     console.log("Condition is not valid")
    }

    Parameters

    Returns boolean

isConditionValueValid

  • JMap.Layer.DynamicFilter.isConditionValueValid

    Returns true if the condition value is valid.

    This function is safe, it throws nothing.

    example
    
    // if date1 is Date object, returns false
    JMap.Layer.DynamicFilter.isConditionValueValid("IS_IN_RANGE", "date", date1)
    
    // if date1 and date2 are Date objects, returns true
    JMap.Layer.DynamicFilter.isConditionValueValid("IS_IN_RANGE", "date", [date1, date2])
    
    // returns true
    JMap.Layer.DynamicFilter.isConditionValueValid("EQUALS", "string", "Montreal")
    
    // returns true
    JMap.Layer.DynamicFilter.isConditionValueValid("EQUALS", "string", "")
    
    // returns false
    JMap.Layer.DynamicFilter.isConditionValueValid("EQUALS", "string", undefined)
    
    // returns true
    JMap.Layer.DynamicFilter.isConditionValueValid("IS_EMPTY", "string")
    
    // returns false
    JMap.Layer.DynamicFilter.isConditionValueValid("EQUALS", "number", "test")
    
    // returns true
    JMap.Layer.DynamicFilter.isConditionValueValid("EQUALS", "number", 22)

    Parameters

    Returns boolean

isMultipleValuesOperator

  • JMap.Layer.DynamicFilter.isMultipleValuesOperator

    Returns true if the operator requires a value that is an array.

    This function is safe, it throws nothing.

    example
    
    // returns true
    JMap.Layer.DynamicFilter.isMultipleValuesOperator("EQUALS")
    
    // returns true
    JMap.Layer.DynamicFilter.isMultipleValuesOperator("NOT_EQUALS")
    
    // returns false
    JMap.Layer.DynamicFilter.isMultipleValuesOperator("CONTAINS")
    
    // returns false
    JMap.Layer.DynamicFilter.isMultipleValuesOperator("IS_IN_RANGE")

    Parameters

    Returns boolean

isNoValueOperator

  • JMap.Layer.DynamicFilter.isNoValueOperator

    Returns true if the operator doesn't require any value.

    This function is safe, it throws nothing.

    example
    
    // returns false
    JMap.Layer.DynamicFilter.isNoValueOperator("IS_IN_RANGE")
    
    // returns false
    JMap.Layer.DynamicFilter.isNoValueOperator("EQUALS")
    
    // returns true
    JMap.Layer.DynamicFilter.isNoValueOperator("IS_EMPTY")
    
    // returns true
    JMap.Layer.DynamicFilter.isNoValueOperator("IS_NOT_NULL")

    Parameters

    Returns boolean

isTwoValuesOperator

  • JMap.Layer.DynamicFilter.isTwoValuesOperator

    Returns true if the operator require two values.

    This function is safe, it throws nothing.

    example
    
    // returns true
    JMap.Layer.DynamicFilter.isTwoValuesOperator("IS_IN_RANGE")
    
    // returns false
    JMap.Layer.DynamicFilter.isTwoValuesOperator("EQUALS")

    Parameters

    Returns boolean

removeConditions

  • removeConditions(layerId: JId, conditionsIds: number[]): void
  • JMap.Layer.DynamicFilter.removeConditions

    Remove conditions for a given layer id and condition ids.

    throws

    Error if JMap layer not found, if invalid array of id

    example
    
    // for layer id=3, remove 2 conditions (id 2 and 12)
    JMap.Layer.DynamicFilter.removeConditions(3, [2, 12])

    Parameters

    • layerId: JId
    • conditionsIds: number[]

    Returns void

set

  • JMap.Layer.DynamicFilter.set

    Set multiple layer's dynamic filters at once.

    If some conditions where already set, will destroy them and replace it with the new given conditions.

    throws

    if invalid params

    example
    
    // set layer's id=3 dynamic filter
    JMap.Layer.DynamicFilter.set([{
      layerId: 3,
      conditions: [{
        layerId: 3,
        attributeName: "name",
        filterOperator: "EQUALS",
        value: ["Ottawa"]
      }]
    }])

    Parameters

    Returns void

setIsActive

  • setIsActive(layerId: JId, isActive: boolean): void
  • JMap.Layer.DynamicFilter.setIsActive

    Activate or deactivate a dynamic layer filter for a given JMap layer id

    throws

    Error if layer is not found

    example
    
    // activate the dynamic filter for layer id=5
    JMap.Layer.DynamicFilter.setIsActive(5, true)
    
    // deactivate the dynamic filter for layer id=2
    JMap.Layer.DynamicFilter.setIsActive(2, false)

    Parameters

    • layerId: JId

      The JMap layer id

    • isActive: boolean

      The new status of the filter

    Returns void

updateCondition

  • JMap.Layer.DynamicFilter.updateCondition

    Update an existing condition, for a JMap Layer dynamic filter.

    throws

    Error if invalid or not found condition

    example
    
    const condition = getCondition()
    condition.value = 3
    JMap.Layer.DynamicFilter.updateCondition(condition)
    console.log(`Condition new value is 3`)

    Parameters

    Returns void