Ignore:
Timestamp:
Oct 13, 2015, 3:38:06 AM (9 years ago)
Author:
ldelgass
Message:

First pass at making Rappture::Map object usable without an XML DOM tree. Add
setter methods for map "hints", ctor with no arguments, addViewpoint method.
Still needs methods to add layers.

File:
1 edited

Legend:

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

    r5883 r5909  
    2323
    2424itcl::class Rappture::Map {
    25     constructor {xmlobj path} {
     25    constructor {args} {
    2626        # defined below
    2727    }
     
    3030    }
    3131
     32    public method addViewpoint { name props }
    3233    public method earthfile {}
    3334    public method hints { args }
     
    4041    public method selectors { layerName }
    4142    public method selector { layerName selectorName }
     43    public method setAttribution { attribution }
     44    public method setCamera { camera }
     45    public method setExtents { xmin ymin xmax ymax }
     46    public method setLabel { label }
     47    public method setProjection { projection }
     48    public method setStyle { style }
     49    public method setToolInfo { id name command title revision }
     50    public method setType { type }
    4251    public method type { layerName }
    4352    public method viewpoint { viewpointName }
     
    7483# CONSTRUCTOR
    7584# ----------------------------------------------------------------------
    76 itcl::body Rappture::Map::constructor {xmlobj path} {
    77     if {![Rappture::library isvalid $xmlobj]} {
    78         error "bad value \"$xmlobj\": should be LibraryObj"
    79     }
    80     Parse $xmlobj $path
     85itcl::body Rappture::Map::constructor {args} {
     86    if {$args == ""} {
     87        set _tree [blt::tree create]
     88        set parent [$_tree insert root -label "layers"]
     89        setLabel "Map"
     90        setType "projected"
     91        setProjection "global-mercator"
     92        setExtents ""
     93        setStyle ""
     94        setCamera ""
     95        set _isValid 1
     96    } else {
     97        set xmlobj [lindex $args 0]
     98        set path [lindex $args 1]
     99        if {![Rappture::library isvalid $xmlobj]} {
     100            error "bad value \"$xmlobj\": should be LibraryObj"
     101        }
     102        Parse $xmlobj $path
     103    }
    81104}
    82105
     
    368391}
    369392
     393itcl::body Rappture::Map::setToolInfo { id name command title revision } {
     394    foreach key [list id name command title revision] {
     395        set str [set $key]
     396        if { "" != $str } {
     397            $_tree set root "tool$key" $str
     398        }
     399    }
     400}
     401
     402itcl::body Rappture::Map::setType { type } {
     403    if { ![info exists _mapTypes($type)] } {
     404        error "unknown map type \"$mapType\": should be one of [array names _mapTypes]"
     405    }
     406    $_tree set root "type" $type
     407}
     408
     409itcl::body Rappture::Map::setProjection { projection } {
     410    $_tree set root "projection" $projection
     411}
     412
     413itcl::body Rappture::Map::setExtents { xmin ymin xmax ymax } {
     414    $_tree set root "extents" "$xmin $ymin $xmax $ymax"
     415}
     416
     417itcl::body Rappture::Map::setLabel { label } {
     418    $_tree set root "label" $label
     419}
     420
     421itcl::body Rappture::Map::setAttribution { attribution } {
     422    $_tree set root "attribution" $attribution
     423}
     424
     425itcl::body Rappture::Map::setStyle { style } {
     426    $_tree set root "style" $style
     427}
     428
     429itcl::body Rappture::Map::setCamera { camera } {
     430    $_tree set root "camera" $camera
     431}
     432
    370433# ----------------------------------------------------------------------
    371434# USAGE: layers
     
    445508    }
    446509    return [$_tree get $id]
     510}
     511
     512itcl::body Rappture::Map::addViewpoint { name props } {
     513    set nodeid "viewpoint[incr _nextViewpoint]"
     514    set child [$_tree insert $parent -label $nodeid]
     515    $_tree set $child "name" $name
     516    set haveX 0
     517    set haveZ 0
     518    set haveSRS 0
     519    set haveVertDatum 0
     520    array set info $props
     521    foreach key { label description x y z distance heading pitch srs verticalDatum } {
     522        if {[info exists info($key)]} {
     523            set val $info($key)
     524            if {$key == "x"} {
     525                set haveX 1
     526            } elseif {$key == "z"} {
     527                set haveZ 1
     528            } elseif {$key == "srs"} {
     529                set haveSRS 1
     530            } elseif {$key == "verticalDatum"} {
     531                set haveVertDatum 1
     532            }
     533            $_tree set $child $key $val
     534        }
     535    }
     536    if {!$haveX} {
     537        set lat $info(latitude)
     538        set long $info(longitude)
     539        $_tree set $child x $long
     540        $_tree set $child y $lat
     541        if {!$haveSRS} {
     542            $_tree set $child srs wgs84
     543        }
     544        if {!$haveVertDatum} {
     545            $_tree set $child verticalDatum ""
     546        }
     547    }
     548    if {!$haveZ && [info exists info(altitude)]} {
     549        $_tree set $child z $info(altitude)
     550    }
    447551}
    448552
Note: See TracChangeset for help on using the changeset viewer.