Changeset 4280


Ignore:
Timestamp:
Mar 26, 2014 5:15:26 PM (10 years ago)
Author:
ldelgass
Message:

Fixes for map parser: layer/map type arrays weren't initialized properly. Add
method to get layer style (may want to revisit this format later), add back
convenience isGeocentric method. In map viewer, allow map specifying projection
and no extents, otherwise (neither) default to mercator.

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/map.tcl

    r4275 r4280  
    2525itcl::class Rappture::Map {
    2626    private variable _tree "";         # Tree of information about the map.
     27    private variable _isGeocentric 0;
    2728    private variable _isValid 0;
    2829    private variable _nextLayer 0;     # Counter used to generate unique
    2930                                       # layer names.
    30     private common _layerTypes {
     31    private common _layerTypes
     32    private common _mapTypes
     33
     34    protected method Parse { xmlobj path }
     35
     36    constructor {xmlobj path} {
     37        # defined below
     38    }
     39    destructor {
     40        # defined below
     41    }
     42    public method isGeocentric {}
     43    public method layers {}
     44    public method layer { name }
     45    public method hints { args }
     46    public method isvalid {} {
     47        return $_isValid;
     48    }
     49    public method type { name } {
     50        set id [$_tree findchild root->"layers" $name]
     51        if { $id < 0 } {
     52            error "unknown layer \"$name\""
     53        }
     54        return [$_tree get $id "type" ""]
     55    }
     56    public method style { name } {
     57        set id [$_tree findchild root->"layers" $name]
     58        if { $id < 0 } {
     59            error "unknown layer \"$name\""
     60        }
     61        return [$_tree get $id "style" ""]
     62    }
     63}
     64
     65# ----------------------------------------------------------------------
     66# CONSTRUCTOR
     67# ----------------------------------------------------------------------
     68itcl::body Rappture::Map::constructor {xmlobj path} {
     69    if {![Rappture::library isvalid $xmlobj]} {
     70        error "bad value \"$xmlobj\": should be LibraryObj"
     71    }
     72    array set _layerTypes {
    3173        "raster"        0
    3274        "elevation"     1
     
    3678        "line"          5
    3779    }
    38     private common _mapTypes {
     80    array set _mapTypes {
    3981        "geocentric"    0
    4082        "projected"     1
    4183    }
    42     protected method Parse { xmlobj path }
    43 
    44     constructor {xmlobj path} {
    45         # defined below
    46     }
    47     destructor {
    48         # defined below
    49     }
    50     public method layers {}
    51     public method layer { name }
    52     public method hints { args }
    53     public method isvalid {} {
    54         return $_isValid;
    55     }
    56     public method type { name } {
    57         set id [$_tree findchild root->"layers" $name]
    58         if { $id < 0 } {
    59             error "unknown layer \"$name\""
    60         }
    61         return [$_tree get $id "type" ""]
    62     }
    63 }
    64 
    65 # ----------------------------------------------------------------------
    66 # CONSTRUCTOR
    67 # ----------------------------------------------------------------------
    68 itcl::body Rappture::Map::constructor {xmlobj path} {
    69     if {![Rappture::library isvalid $xmlobj]} {
    70         error "bad value \"$xmlobj\": should be LibraryObj"
    71     }
     84
    7285    Parse $xmlobj $path
    7386}
     
    121134        $_tree set $child "title" [$layers get $layer.label]
    122135        set type [$layers get $layer.type]
    123         if { [info exists _layerTypes($type)] } {
    124             error "invalid layer type \"$type\""
     136        if { ![info exists _layerTypes($type)] } {
     137            error "invalid layer type \"$type\": should be one of [array names _layerTypes]"
    125138        }
    126139        $_tree set $child "type" $type
     
    138151    $_tree set root "projection"  [$map get "projection"]
    139152
    140     set type [$map get "type"]
    141     if { $type == "" } {
    142         set type "projected"
     153    set mapType [$map get "type"]
     154    if { $mapType == "" } {
     155        set mapType "projected"
    143156    }
    144     if { [info exists _mapTypes($type)] } {
     157    puts stderr "Map type: $mapType"
     158    if { ![info exists _mapTypes($mapType)] } {
    145159        error "unknown map type \"$mapType\": should be one of [array names _mapTypes]"
    146     }
    147     $_tree set root "type" $type
     160    } elseif {$mapType == "geocentric"} {
     161        set _isGeocentric 1
     162    }
     163    $_tree set root "type" $mapType
    148164
    149165    foreach {key path} {
     
    190206}
    191207
     208# ----------------------------------------------------------------------
     209# Returns if the map is geocentric (1) or projected (0)
     210# ----------------------------------------------------------------------
     211itcl::body Rappture::Map::isGeocentric {} {
     212    return $_isGeocentric
     213}
  • trunk/gui/scripts/mapviewer.tcl

    r4279 r4280  
    619619
    620620        foreach layer [$dataobj layers] {
    621             set type [$dataobj layer $layer]
    622             switch -- $type {
     621            set layerType [$dataobj type $layer]
     622            switch -- $layerType {
    623623                "elevation" {
    624624                    set _haveTerrain 1
     
    871871                SendCmd "map reset geocentric"
    872872            } else {
    873                 if { $_mapsettings(extents) == ""} {
    874                     SendCmd "map reset projected global-mercator"
     873                if { $_mapsettings(extents) == "" } {
     874                    if { $_mapsettings(projection) == "" } {
     875                        SendCmd "map reset projected global-mercator"
     876                    } else {
     877                        SendCmd "map reset projected $_mapsettings(projection)"
     878                    }
    875879                } else {
    876                     SendCmd \
    877         "map reset projected $_mapsettings(projection) $_mapsettings(extents)"
     880                    SendCmd "map reset projected $_mapsettings(projection) $_mapsettings(extents)"
    878881                }
    879882            }
     
    15671570    set _visibility($tag) 1
    15681571
    1569     return
    1570 
    1571     # The following code is a place holder for terrain styles.
    1572 
    15731572    set type [$dataobj type $layer]
    15741573    set style [$dataobj style $layer]
    1575     if { $dataobj != $_first } {
    1576         set settings(-wireframe) 1
    1577     }
    15781574    switch -- $type {
    15791575        "elevation" {
     
    15891585            SendCmd "map terrain edges $settings(-edges) $tag"
    15901586            set _settings(terrain-edges) $settings(-edges)
    1591             SendCmd "map terrain color [Color2RGB $settings(-color)] $tag"
     1587            #SendCmd "map terrain color [Color2RGB $settings(-color)] $tag"
    15921588            #SendCmd "map terrain colormode constant {} $tag"
    15931589            SendCmd "map terrain lighting $settings(-lighting) $tag"
    15941590            set _settings(terrain-lighting) $settings(-lighting)
    15951591            SendCmd "map terrain linecolor [Color2RGB $settings(-edgecolor)] $tag"
    1596             SendCmd "map terrain linewidth $settings(-linewidth) $tag"
     1592            #SendCmd "map terrain linewidth $settings(-linewidth) $tag"
    15971593            SendCmd "map terrain wireframe $settings(-wireframe) $tag"
    15981594            set _settings(terrain-wireframe) $settings(-wireframe)
Note: See TracChangeset for help on using the changeset viewer.