Changeset 5120


Ignore:
Timestamp:
Mar 11, 2015 3:13:19 AM (5 years ago)
Author:
ldelgass
Message:

first attempt at legend for colormap map layers

File:
1 edited

Legend:

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

    r5106 r5120  
    9494    private method DoRotate {}
    9595    private method DoSelect {}
     96    private method DrawLegend { colormap min max }
    9697    private method EarthFile {}
    9798    private method EnablePanningMouseBindings {}
     
    115116    private method ReceiveMapInfo { args }
    116117    private method ReceiveScreenInfo { args }
     118    private method RequestLegend { colormap w h }
    117119    private method Rotate {option x y}
    118120    private method Select {option x y}
     
    614616}
    615617
     618itcl::body Rappture::MapViewer::DrawLegend { colormap min max } {
     619    if { [info exists itk_component(legend-$colormap) ] } {
     620        $itk_component(legend-$colormap-min) configure -text $min
     621        $itk_component(legend-$colormap-max) configure -text $max
     622        $itk_component(legend-$colormap) configure -image $_image(legend-$colormap)
     623    }
     624}
     625
     626itcl::body Rappture::MapViewer::RequestLegend { colormap w h } {
     627    SendCmd "legend $colormap $w $h 0 [Color2RGB #d9d9d9]"
     628}
     629
    616630# ----------------------------------------------------------------------
    617631# USAGE: add <dataobj> ?<settings>?
     
    10311045        set bytes [ReceiveBytes $size]
    10321046        if { ![info exists _image(legend)] } {
    1033             set _image(legend) [image create photo]
    1034         }
    1035         $_image(legend) configure -data $bytes
    1036 puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    1037         #if { [catch {DrawLegend} errs] != 0 } {
    1038         #    global errorInfo
    1039         #    puts stderr "errs=$errs errorInfo=$errorInfo"
    1040         #}
     1047            set _image(legend-$colormap) [image create photo]
     1048        }
     1049        if 0 {
     1050            set f [open "/tmp/legend-${colormap}.ppm" "w"]
     1051            fconfigure $f -translation binary -encoding binary
     1052            puts $f $bytes
     1053            close $f
     1054        }
     1055        $_image(legend-$colormap) configure -data $bytes
     1056puts stderr "read $size bytes for [image width $_image(legend-$colormap)]x[image height $_image(legend-$colormap)] legend>"
     1057        if { [catch {DrawLegend $colormap $min $max} errs] != 0 } {
     1058            global errorInfo
     1059            puts stderr "errs=$errs errorInfo=$errorInfo"
     1060        }
    10411061    }
    10421062}
     
    24782498            if { $info(type) == "image" } {
    24792499                incr imgIdx
     2500                if { $info(driver) == "colorramp" } {
     2501                    set colormap $layer
     2502                    if { ![info exists _image(legend-$colormap)] } {
     2503                        set _image(legend-$colormap) [image create photo]
     2504                    }
     2505                    itk_component add legend-$colormap-min {
     2506                        label $f.${layer}_legend-$colormap-min -text 0
     2507                    }
     2508                    itk_component add legend-$colormap-max {
     2509                        label $f.${layer}_legend-$colormap-max -text 1
     2510                    }
     2511                    itk_component add legend-$colormap {
     2512                        label $f.${layer}_legend-$colormap -image $_image(legend-$colormap)
     2513                    }
     2514                    blt::table $f $row,0 $f.${layer}_legend-$colormap-min -anchor w -pady 0
     2515                    blt::table $f $row,1 $f.${layer}_legend-$colormap-max -anchor e -pady 0
     2516                    incr row
     2517                    blt::table $f $row,0 $f.${layer}_legend-$colormap -anchor w -pady 2 -cspan 2
     2518                    incr row
     2519                    RequestLegend $colormap 256 16
     2520                }
    24802521            }
    24812522            if { $info(type) != "elevation" && ($info(type) != "image" || $imgIdx > 1) } {
Note: See TracChangeset for help on using the changeset viewer.