Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Project

JMap.Project

From this section you can manage the project that is in use in the JMap NG Core library.

Index

Functions

activateById

  • JMap.Project.activateById

    Activate a project on the map, for a given project id.

    User session rigths are checked server side and an error is thrown if user doesn't have the access right for the project.

    throws

    Error missing project id or if project is not found

    example
    
    try {
      // activate project id=2
      const project = JMap.Project.activateById(2)
      console.info(`Project id=${project.id} has been activated.`, project)
    } catch (error) {
      console.error(`Cannot activate the project : ${error}`)
    }

    Parameters

    • projectId: JId

      The JMap project id

    Returns JProject

    a promise that is resolved when the project has been loaded successfully

activateByName

  • activateByName(projectName: string): JProject
  • JMap.Project.activateByName

    Activate a project on the map, for a given project name.

    User session rigths are checked server side and an error is thrown if user doesn't have the access right for the project.

    throws

    if missing project name or if project not found

    example
    
    try {
      // activate project name="My city"
      const project = JMap.Project.activateByName("My city")
      console.info(`Project id=${project.id} has been activated.`, project)
    } catch (error) {
      console.error(`Cannot activate the project : ${error}`)
    }

    Parameters

    • projectName: string

    Returns JProject

    the project

deactivate

  • deactivate(): void
  • JMap.Project.deactivate

    Deactivate the current displayed project. The map is destroyed.

    After calling this method :

    • In JMap Core : nothing is displayed on screen.
    • In JMap App : project list selection is displayed.
    example
    
    // deactivate the current project.
    JMap.Project.deactivate()

    Returns void

existsById

  • existsById(projectId: JId): boolean
  • JMap.Project.existsById

    Returns true if project exist for the given project id.

    example
    
    // returns true if the project id = 2 exists, else false
    JMap.Project.existsById(2)

    Parameters

    • projectId: JId

      The JMap project id

    Returns boolean

existsByName

  • existsByName(projectName: string): boolean
  • JMap.Project.existsByName

    Returns true if project exist for the given project name.

    example
    
    // returns true if the project "My Project" exists, else false
    JMap.Project.existsByName("My Project")

    Parameters

    • projectName: string

      The JMap project name

    Returns boolean

getActiveProject

  • JMap.Project.getActiveProject

    Returns the active project (the one displayed on the map).

    If no project is active, the object returned has an id equals to -1.

    example
    
    // returns the active project
    const activeProject = JMap.Project.getActiveProject()
    if (activeProject.id === -1) {
      console.info("No active project")
    } else {
      console.info(`Active project is "${activeProject.name}"`)
    }

    Returns JProject

getAllProjects

  • JMap.Project.getAllProjects

    Returns a promise that returns all JMap projects descriptors when resolved.

    If no project is loaded, returns empty array.

    example
    
    // This is asynchronous code, getAllProject returns a promise that is
    // resolved after the server returned all project data.
    JMap.Project
       .getAllProjects()
       .then(projects => {
         // Here you can start using the projects
         console.log(`Projects count = "${projects.length}"`
       }))

    Returns Promise<JProject[]>

getBackgroundColor

  • getBackgroundColor(): string
  • JMap.Project.getBackgroundColor

    Returns loaded JMap project background color in html hexa format. This color is used as the background of the map.

    throws

    If no project is loaded

    example
    
    // returns the project background color as a html hexa color
    JMap.Project.getBackgroundColor()

    Returns string

getBase64ImageThumbnail

  • getBase64ImageThumbnail(): string
  • JMap.Project.getBase64ImageThumbnail

    Returns loaded JMap project base64 image thumbnail.

    When JMap NG Core lib is started, it doesn't load projects thumbnails, but you can load it by setting the startup option "loadAllProjectThumbnails" as true.

    If no thumbnail has been loaded it returns an empty string.

    throws

    If no project is loaded

    example
    
    // returns the project initial extent if exists
    JMap.Project.getInitialExtent()

    Returns string

getById

  • JMap.Project.getById

    Returns the project for the given project id.

    throws

    error if the project doesn't exists or if projectId is not a valid JMap Id.

    example
    
    // Get Project id 2
    const project = JMap.Project.getById(2)
    console.log("Project '" + project.name + "' is loaded")

    Parameters

    • projectId: JId

      The JMap project id

    Returns JProject

getByName

  • getByName(projectName: string): JProject
  • JMap.Project.getByName

    Returns the project for the given project name.

    throws

    error if the project doesn't exists or if projectName is not a string.

    example
    
    // Get project "My Project"
    const project = JMap.Project.getByName("My Project")
    console.log("Project id '" + project.id + "' is loaded")

    Parameters

    • projectName: string

      The JMap project name

    Returns JProject

getDefaultDistanceUnit

  • JMap.Project.getDefaultDistanceUnit

    Returns the project distance unit, or "meters" if no distance unit is set on the project.

    throws

    if no project is loaded

    example
    
    // returns "meters", or "kilometers", or "miles", or "yards"...
    JMap.Project.getDefaultDistanceUnit()

    Returns JMAP_DISTANCE_UNITS

getDescription

  • getDescription(): string
  • JMap.Project.getDescription

    Returns loaded JMap project description.

    throws

    If no project is loaded

    example
    
    // returns the currently loaded project description
    JMap.Project.getDescription()

    Returns string

getId

  • JMap.Project.getId

    Returns loaded JMap project id.

    throws

    If no project is loaded

    example
    
    // returns the currently loaded project id
    JMap.Project.getId()

    Returns JId

getInitialExtent

  • getInitialExtent(): JBounds | null
  • JMap.Project.getInitialExtent

    Returns loaded JMap project initial extent. This is the extent that is automatically displayed when the project is opened.

    throws

    If no project is loaded

    example
    
    // returns the project initial extent if exists
    JMap.Project.getInitialExtent()

    Returns JBounds | null

getInitialRotation

  • getInitialRotation(): number
  • JMap.Project.getInitialRotation

    Returns loaded JMap project initial map rotation. This rotation is the one applied when the project is opened.

    throws

    If no project is loaded

    example
    
    // returns the project initial rotation
    JMap.Project.getInitialRotation()

    Returns number

getMapUnit

  • JMap.Project.getMapUnit

    Returns the project map unit.

    throws

    if no project is loaded

    example
    
    // return "meters", or "kilometers", or "miles", or "yards"...
    JMap.Project.getMapUnit()

    Returns JMAP_DISTANCE_UNITS

getName

  • getName(): string
  • JMap.Project.getName

    Returns loaded JMap project name.

    throws

    If no project is loaded

    example
    
    // returns the currently loaded project name
    JMap.Project.getName()

    Returns string

getProjection

  • JMap.Project.getProjection

    Returns loaded JMap project projection.

    In MapBox, projection is always "EPSG:3857", but that function returns the project defined projection (so it can be different than ESPG:3857).

    throws

    If no project is loaded

    example
    
    // returns the project projection
    JMap.Project.getProjection()

    Returns JProjection

getSelectionColor

  • getSelectionColor(): string
  • JMap.Project.getSelectionColor

    Returns loaded JMap project selection color in html hexa format.

    This is the color that is used for selected features of layers that don't have a specific selection style defined.

    throws

    If no project is loaded

    example
    
    // returns the project selection color as a html hexa color
    JMap.Project.getSelectionColor()

    Returns string

hasProjectActivated

  • hasProjectActivated(): boolean
  • JMap.Project.hasProjectActivated

    Returns true if a JMap project is active, that means a project is selected and displayed on the map.

    example
    
    // returns true if a project is active
     JMap.Project.hasProjectActivated()

    Returns boolean

isChangeDisabled

  • isChangeDisabled(): boolean
  • JMap.Project.isChangeDisabled

    Returns true if the project change has been disabled by startup option "disableProjectChange" (see JCoreOptions).

    Notice that as long the first project has not been loaded, this method returns false even if the parameter is true.

    It becomes true, if option "disableProjectChange" is set to true, and a project has been activated.

    example
    
    // We assert that :
    //  - the option "disableProjectChange" is true
    //  - no project is yet activated, no map is displayed.
    
    // returns false
    JMap.Project.isChangeDisabled()
    
    // first time a project is activated
    JMap.Project.activateByName("My project")
    
    // returns true
    JMap.Project.isChangeDisabled()

    Returns boolean

loadAllProjectThumbnails

  • JMap.Project.loadAllProjectThumbnails

    Load all project thumbnails in the data store.

    Default width is 348 and height 190.

    Image is a base 64 formatted string.

    throws

    if params are not correct

    example
    
    // Will load all projects thumbnail images
    JMap.Project
       .loadAllProjectThumbnails({
         width: 200,
         height: 200
       })
       .then(() => console.info("All project images has been loaded"))
       .catch(error => console.error("Cannot load project images"))
    
    // Then you can get current project thumnail like that
    const thumbnail = JMap.Project.getBase64ImageThumbnail()
    
    // Or you can get the project id=3 thumbnail like this
    const otherThumbnail = JMap.Project.getById(3).base64ImageThumbnail

    Parameters

    Returns Promise<void>

setChangeDisabled

  • setChangeDisabled(): void
  • JMap.Project.setChangeDisabled

    Disables project change.

    Can be used in a project extention for instance, to override the behaviour of this parameter inherited from startup options for the current user session.

    example
    
    // disable project change
    if (!JMap.Project.isChangeDisabled()) {
       JMap.Project.setChangeDisabled()
    }

    Returns void

setChangeEnabled

  • setChangeEnabled(): void
  • JMap.Project.setChangeEnabled

    Enables project change.

    Can be used in a project extention for instance, to override the behaviour of this parameter inherited from startup options for the current user session.

    example
    
    // enable project change
    if (JMap.Project.isChangeDisabled()) {
       JMap.Project.setChangeEnabled()
    }

    Returns void