Ignore:
Timestamp:
Dec 18, 2015 1:19:46 AM (7 years ago)
Author:
dkearney
Message:

adding data provider and layer objects, updating mapviewer to remove layers from client and server.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/geomap/gui/scripts/map.tcl

    r5917 r5949  
    3737        return $_isValid;
    3838    }
    39     public method layer { layerName }
     39    public method layer { option args }
    4040    public method layers {}
    4141    public method selectors { layerName }
     
    5454
    5555    protected method Parse { xmlobj path }
     56
     57    private method AddLayer { args }
     58    private method DeleteLayer { layerName }
     59    private method GetLayerNames {}
     60    private method GetLayerSettings { layerName }
     61
    5662
    5763    private variable _tree "";         # Tree of information about the map.
     
    446452
    447453# ----------------------------------------------------------------------
    448 # USAGE: layers
    449 #
    450 # Returns a list of IDs for the layers in the map
    451 # ----------------------------------------------------------------------
    452 itcl::body Rappture::Map::layers {} {
    453     set list {}
    454     foreach node [$_tree children root->"layers"] {
    455         lappend list [$_tree label $node]
    456     }
    457     return $list
    458 }
    459 
    460 # ----------------------------------------------------------------------
    461454# USAGE: viewpoints
    462455#
     
    472465
    473466# ----------------------------------------------------------------------
     467# USAGE: AddLayer -format <format>
     468#
     469# Associate a new layer to the map
     470# ----------------------------------------------------------------------
     471itcl::body Rappture::Map::AddLayer { args } {
     472    set layerName ""
     473    set valids "-format"
     474    set format "blt_tree"
     475
     476    set layerObj [lrange $args end end]
     477    set args [lrange $args 0 end-1]
     478
     479    while {[llength $args] > 0} {
     480        set flag [lindex $args 0]
     481        switch -- $flag {
     482            "-format" {
     483                if {[llength $args] > 1} {
     484                    set format [lindex $args 1]
     485                    set args [lrange $args 2 end]
     486                } else {
     487                    error "wrong number args: should be ?-format <format>?"
     488                }
     489            }
     490            default {
     491                error "invalid option \"$flag\": should be one of $valids"
     492            }
     493        }
     494    }
     495
     496    set valids "blt_tree"
     497
     498    switch -- $format {
     499        "blt_tree" {
     500            # check if a layer by the same name already exists
     501            set layerName "layer[incr _nextLayer]"
     502            if {[$_tree findchild root->"layers" $layerName] != -1} {
     503                error "key error \"$layerName\": layer name exists"
     504            }
     505            # copy the incomming layer data into our map object
     506            set id [$layerObj copy root $_tree root->"layers"]
     507            # give the layer a searchable layer name
     508            $_tree label $id $layerName
     509        }
     510        default {
     511            error "bad format \"$format\": should be one of $valids"
     512        }
     513    }
     514
     515    return $layerName
     516}
     517
     518# ----------------------------------------------------------------------
     519# USAGE: DeleteLayer <layerName>
     520#
     521# Remove a layer from the map
     522# ----------------------------------------------------------------------
     523itcl::body Rappture::Map::DeleteLayer { layerName } {
     524    set id [$_tree findchild root->"layers" $layerName]
     525    if {$id <= 0} {
     526        # layer not found
     527        error "invalid layer \"$layerName\": should be one of [GetLayerNames]"
     528    }
     529    # delete the layer
     530    $_tree delete $id
     531}
     532
     533
     534# ----------------------------------------------------------------------
     535# USAGE: GetLayerNames
     536# USAGE: layers
     537#
     538# Returns a list of IDs for the layers in the map
     539# ----------------------------------------------------------------------
     540itcl::body Rappture::Map::GetLayerNames {} {
     541    set list {}
     542    foreach node [$_tree children root->"layers"] {
     543        lappend list [$_tree label $node]
     544    }
     545    return $list
     546}
     547
     548# ----------------------------------------------------------------------
     549# USAGE: GetLayerSettings <layerName>
    474550# USAGE: layer <layerName>
    475551#
    476 # Returns an array of settings for the named layer
    477 # ----------------------------------------------------------------------
    478 itcl::body Rappture::Map::layer { layerName } {
     552# Returns a list of settings for the named layer
     553# ----------------------------------------------------------------------
     554itcl::body Rappture::Map::GetLayerSettings { layerName } {
    479555    set id [$_tree findchild root->"layers" $layerName]
    480556    if { $id < 0 } {
     
    483559    return [$_tree get $id]
    484560}
     561
     562# ----------------------------------------------------------------------
     563# USAGE: layer
     564#
     565#   This public method is called by clients using this widget to manage
     566#   layers in the map.
     567#
     568#       layer add ?-type type? layerData
     569#       layer delete layerName
     570#       layer names
     571#       layer settings layerName
     572#
     573itcl::body Rappture::Map::layer {option args} {
     574    set result ""
     575    switch -- $option {
     576        "add" {
     577            set result [eval AddLayer $args]
     578        }
     579        "delete" {
     580            set result [eval DeleteLayer $args]
     581        }
     582        "names" {
     583            set result [GetLayerNames]
     584        }
     585        "settings" {
     586            set result [GetLayerSettings $args]
     587        }
     588        default {
     589            error "unknown layer option \"$option\""
     590        }
     591    }
     592    return $result
     593}
     594
    485595
    486596# ----------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.