Changeset 4303 for trunk


Ignore:
Timestamp:
Mar 31, 2014 2:58:41 AM (10 years ago)
Author:
ldelgass
Message:

Map fixes: rename "raster" layer type to "image". Add "label" layer type for
text label layer. Retain old code path (without earth file usage) and add a
flag to toggle use of earth files.

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

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

    r4300 r4303  
    3131    private common _mapTypes
    3232    array set _layerTypes {
    33         "raster"        0
     33        "image"         0
    3434        "elevation"     1
    3535        "polygon"       2
    3636        "points"        3
    37         "circle"        4
     37        "icon"          4
    3838        "line"          5
     39        "label"         6
    3940    }
    4041    array set _mapTypes {
     
    128129            $_tree set $child $key [$layers get $layer.$key]
    129130        }
    130        
    131         foreach {key defval} { opacity 1.0 visible true style "" } {
     131        # Common settings (for all layer types) with defaults
     132        foreach {key defval} { visible true } {
    132133            $_tree set $child $key $defval
     134            set val [$layers get $layer.$key]
     135            if {$val != ""} {
     136                $_tree set $child $key $val
     137            }
     138        }
     139        # These are settings for which there should be no default
     140        # We want to know if they have been set by the user or not
     141        # Not all layer types use these
     142        foreach key { opacity content priority style } {
    133143            set val [$layers get $layer.$key]
    134144            if {$val != ""} {
     
    223233# USAGE: isGeocentric
    224234#
    225 # Returns (like a bad penny) if the map is geocentric (1) or projected (0)
     235# Returns if the map is geocentric (1) or projected (0)
    226236# ----------------------------------------------------------------------
    227237itcl::body Rappture::Map::isGeocentric {} {
     
    236246    append out " version=\"2\""
    237247    append out ">\n"
    238     append out " <profile"
    239     append out " srs=\"$info(projection)\""
    240     if { $info(extents) != "" } {
    241         foreach {x1 y1 x2 y2} $extents break
    242         append out " xmin=\"$x1\""
    243         append out " ymin=\"$y1\""
    244         append out " xmax=\"$x2\""
    245         append out " ymax=\"$y2\""
    246     }
    247     append out " >\n"
    248     append out " </profile>"
     248    # Profile is optional
     249    if { [info exists info(projection)] } {
     250        append out " <options>\n"
     251        append out "  <profile"
     252        append out " srs=\"$info(projection)\""
     253        if { [info exists info(extents)] && $info(extents) != "" } {
     254            foreach {x1 y1 x2 y2} $info(extents) break
     255            append out " xmin=\"$x1\""
     256            append out " ymin=\"$y1\""
     257            append out " xmax=\"$x2\""
     258            append out " ymax=\"$y2\""
     259        }
     260        append out "/>\n"
     261        append out " </options>\n"
     262    }
    249263    foreach node [$_tree children root->"layers"] {
    250264        array unset info
    251265        array set info [$_tree get $node]
    252266        set label [$_tree label $node]
    253         append out " <image"
    254         append out " name=\"$label\""
    255         append out " driver=\"gdal\""
    256         append out " opacity=\"$info(opacity)\""
    257         append out " visible=\"$info(visible)\""
    258         append out " >\n"
    259         append out "  <url>$info(url)<url>\n"
    260         append out " </image>"
     267        switch -- $info(type) {
     268            "image" {
     269                append out " <image"
     270                append out " name=\"$label\""
     271                append out " driver=\"gdal\""
     272                if { [info exists info(opacity)] } {
     273                    append out " opacity=\"$info(opacity)\""
     274                }
     275                if { $info(visible) } {
     276                    append out " visible=\"true\""
     277                } else {
     278                    append out " visible=\"false\""
     279                }
     280                append out ">\n"
     281                append out "  <url>$info(url)</url>\n"
     282                append out " </image>\n"
     283            }
     284            "elevation" {
     285                append out " <elevation"
     286                append out " name=\"$label\""
     287                append out " driver=\"gdal\""
     288                if { $info(visible) } {
     289                    append out " visible=\"true\""
     290                } else {
     291                    append out " visible=\"false\""
     292                }
     293                append out ">\n"
     294                append out "  <url>$info(url)</url>\n"
     295                append out " </elevation>\n"
     296            }
     297            default {
     298                puts stderr "Type $info(type) not implemented in earthfile"
     299            }
     300        }
    261301    }
    262302    append out "</map>\n"
    263303}
    264 
  • trunk/gui/scripts/mapviewer.tcl

    r4300 r4303  
    135135    private variable _rotateDelay 150
    136136    private variable _motion
     137    private variable _sendEarthFile 1
    137138}
    138139
     
    628629            }
    629630            if { ![info exists _mapsettings(y2)] || $y2 > $_mapsettings(y2) } {
    630                 set _mapsettings(y2) $y1
     631                set _mapsettings(y2) $y2
    631632            }
    632633        }
     
    854855            # The map must be reset once before any layers are added This
    855856            # should not be done more than once as it is very expensive.
    856             set bytes [EarthFile]
    857             set f [open "/tmp/earth.txt" "w"]
    858             puts $f $bytes
    859             close $f
    860             set length [string length $bytes]
    861             SendCmd "map load data follows $length"
    862             append _outbuf $bytes
    863 
    864             # FIXME: do I still need to delete the base layer?
    865             SendCmd "map layer delete base"
    866 
    867             if { $_haveTerrain } {
    868                 if { [info exists _mapsettings(style)] } {
    869                     SetTerrianStyle $_mapsettings(style)
    870                 } else {
    871                     FixSettings terrain-edges terrain-lighting \
    872                         terrain-vertscale terrain-wireframe
    873                 }
     857            if {$_sendEarthFile} {
     858                set bytes [EarthFile]
     859                if {0} {
     860                    set f [open "/tmp/map.earth" "w"]
     861                    puts $f $bytes
     862                    close $f
     863                }
     864                set length [string length $bytes]
     865                SendCmd "map load data follows $length"
     866                append _outbuf $bytes
     867            } else {
     868                if { $_mapsettings(type) == "geocentric" } {
     869                    SendCmd "map reset geocentric"
     870                }  else {
     871                    set proj $_mapsettings(projection)
     872                    if { $proj == "" } {
     873                        SendCmd "map reset projected global-mercator"
     874                    } elseif { ![info exists _mapsettings(extents)] || $_mapsettings(extents) == "" } {
     875                        SendCmd [list map reset "projected" $proj]
     876                    } else {
     877                        #foreach {x1 y1 x2 y2} $_mapsettings(extents) break
     878                        foreach key "x1 y1 x2 y2" {
     879                            set $key $_mapsettings($key)
     880                        }
     881                        SendCmd [list map reset "projected" $proj $x1 $y1 $x2 $y2]
     882                    }
     883                }
     884                SendCmd "map layer delete base"
     885            }
     886
     887            # Most terrain settings are global to the map and apply even
     888            # if there is no elevation layer.  The exception is the
     889            # vertical scale, which only applies if there is an elevation
     890            # layer
     891            if { [info exists _mapsettings(style)] } {
     892                SetTerrainStyle $_mapsettings(style)
     893            } else {
     894                FixSettings terrain-edges terrain-lighting \
     895                    terrain-vertscale terrain-wireframe
    874896            }
    875897            SendCmd "imgflush"
     
    890912                if { ![info exists info(url)] }  {
    891913                    continue
    892                 }
    893                 # FIXME: wms, tms layers have additional options
    894                 switch -- $info(type) {
    895                     "raster" {
    896                         set type "image"
    897                     }
    898                     default {
    899                         set type "$info(type)"
    900                     }
    901914                }
    902915                if { $_reportClientInfo }  {
     
    910923                    SendCmd [list "clientinfo" $cinfo]
    911924                }
    912                 SendCmd [list map layer add $type $info(url) $layer]
    913925                set _layers($layer) 1
    914926                SetLayerStyle $dataobj $layer
    915927            }
    916928            lappend _obj2datasets($dataobj) $layer
     929            # FIXME: This is overriding all layers' initial visibility setting
    917930            if { [info exists _obj2ovride($dataobj-raise)] } {
    918931                SendCmd "map layer visible 1 $layer"
     
    15901603    array set info [$dataobj layer $layer]
    15911604    set _visibility($layer) 1
    1592     if { [info exists info(status)] } {
    1593         if { $info(status) == "hidden" } {
    1594             set _visibility($layer) 0
    1595             SendCmd "map layer visible 0 $layer"
    1596         }
    1597     }
    15981605
    15991606    switch -- $info(type) {
    1600         "raster" {
     1607        "image" {
    16011608            array set settings {
    16021609                -min_level 0
     
    16101617                set settings(-opacity) $info(opacity)
    16111618            }
     1619            if {!$_sendEarthFile} {
     1620                SendCmd [list map layer add image $info(url) $layer]
     1621            }
    16121622            SendCmd "map layer opacity $settings(-opacity) $layer"
    16131623        }
     
    16191629            if { [info exists info(style)] } {
    16201630                array set settings $info(style)
     1631            }
     1632            if {!$_sendEarthFile} {
     1633                SendCmd [list map layer add elevation $info(url) $layer]
    16211634            }
    16221635        }
     
    16341647                set settings(-opacity) $info(opacity)
    16351648            }
     1649            SendCmd [list map layer add line $info(url) $layer]
    16361650            SendCmd "map layer opacity $settings(-opacity) $layer"
    16371651        }
     
    16481662                set settings(-opacity) $info(opacity)
    16491663            }
     1664            SendCmd [list map layer add polygon $info(url) $layer]
    16501665            SendCmd "map layer opacity $settings(-opacity) $layer"
     1666        }
     1667        "label" {
     1668            array set settings {
     1669                -align "center-center"
     1670                -color black
     1671                -declutter 1
     1672                -font Arial
     1673                -fontsize 16.0
     1674                -halocolor white
     1675                -halowidth 2.0
     1676                -layout "ltr"
     1677                -minbias 1000
     1678                -opacity 1.0
     1679                -removedupe 1
     1680            }
     1681            if { [info exists info(style)] } {
     1682                array set settings $info(style)
     1683            }
     1684            if { [info exists info(opacity)] } {
     1685                set settings(-opacity) $info(opacity)
     1686            }
     1687            set contentExpr $info(content)
     1688            if {[info exists info(priority)]} {
     1689                set priorityExpr $info(priority)
     1690            } else {
     1691                set priorityExpr ""
     1692            }
     1693            SendCmd [list map layer add text $info(url) $contentExpr $priorityExpr $layer]
     1694            SendCmd "map layer opacity $settings(-opacity) $layer"
     1695        }
     1696    }
     1697
     1698    if { [info exists info(visible)] } {
     1699        if { !$info(visible) } {
     1700            set _visibility($layer) 0
     1701            SendCmd "map layer visible 0 $layer"
    16511702        }
    16521703    }
     
    17211772}
    17221773
     1774#
     1775# Generate an OSG Earth file to send to server.  This is inteneded
     1776# as a stopgap and testing tool until the protocol is fleshed out.
     1777#
     1778# Note that the lighting settings are required to be "hard-coded"
     1779# as below for the runtime control to work.  Don't make those user
     1780# configurable.
     1781#
     1782# Also note: Use "true"/"false" for boolean settings.  Not sure if
     1783# the parser in OSG Earth accepts all of Tcl's forms of boolean vals.
     1784#
    17231785itcl::body Rappture::MapViewer::EarthFile {} {
    17241786    append out "<map"
     
    17271789    append out " version=\"2\""
    17281790    append out ">\n"
    1729     append out " <options"
    1730     append out " lighting=\"true\""
    1731     #append out " elevation_interpolation=\"bilinear\""
    1732     #append out " elevation_tile_size=\"8\""
    1733     #append out " overlay_texture_size=\"4096\""
    1734     #append out " overlay_blending=\"true\""
    1735     #append out " overlay_resolution_ratio=\"3.0\""
    1736     append out ">\n"
    1737     append out "  <profile"
    1738     append out " srs=\"$_mapsettings(projection)\""
    1739     if { [info exists _mapsettings(extents)] } {
    1740         append out " xmin=\"$_mapsettings(x1)\""
    1741         append out " ymin=\"$_mapsettings(y1)\""
    1742         append out " xmax=\"$_mapsettings(x2)\""
    1743         append out " ymax=\"$_mapsettings(y2)\""
    1744     }
    1745     append out "/>\n"
    1746     if { $_haveTerrain } {
    1747         array set terrain {
    1748             -color white
    1749             -lighting 0
    1750         }
    1751         array set terrain $_mapsettings(style)
    1752         append out "  <terrain"
    1753         append out " lighting=\"$terrain(-lighting)\""
    1754         append out " color=\"$terrain(-color)\""
    1755         #append out " min_tile_range_factor=\"$terrain(-mintile)\""
    1756         #append out " min_lod=\"$terrain(-minlod)\""
    1757         #append out " max_lod=\"$terrain(-maxlod)\""
    1758         #append out " first_lod=\"$terrain(-firstlod)\""
    1759         #append out " cluster_culling=\"$terrain(-clusterculling)\""
    1760         #append out " mercator_fast_path=\"$terrain(-mercatorfastpath)\""
    1761         #append out " blending=\"$terrain(-blending)\""
     1791    append out " <options lighting=\"true\">\n"
     1792    # FIXME: convert color setting to hex
     1793    # array set style $_mapsettings(style)
     1794    # if {[info exists style(-color)]} {
     1795    #     set color "?"
     1796    # }
     1797    set color "#ffffffff"
     1798    append out "  <terrain lighting=\"false\" color=\"$color\"/>\n"
     1799    if { [info exists _mapsettings(projection)] } {
     1800        append out "  <profile"
     1801        append out " srs=\"$_mapsettings(projection)\""
     1802        if { [info exists _mapsettings(extents)] } {
     1803            append out " xmin=\"$_mapsettings(x1)\""
     1804            append out " ymin=\"$_mapsettings(y1)\""
     1805            append out " xmax=\"$_mapsettings(x2)\""
     1806            append out " ymax=\"$_mapsettings(y2)\""
     1807        }
    17621808        append out "/>\n"
    17631809    }
     
    17691815            array unset info
    17701816            array set info [$dataobj layer $layer]
    1771             append out " <image"
    1772             append out " name=\"$layer\""
    1773             append out " driver=\"gdal\""
    1774             append out " opacity=\"$info(opacity)\""
    1775             append out " visible=\"true\""
    1776             append out ">\n"
    1777             append out "  <url>$info(url)</url>\n"
    1778             append out " </image>\n"
     1817            switch -- $info(type) {
     1818                "image" {
     1819                    append out " <image"
     1820                    append out " name=\"$layer\""
     1821                    append out " driver=\"gdal\""
     1822                    if { [info exists info(opacity)] } {
     1823                        append out " opacity=\"$info(opacity)\""
     1824                    }
     1825                    if { $info(visible) } {
     1826                        append out " visible=\"true\""
     1827                    } else {
     1828                        append out " visible=\"false\""
     1829                    }
     1830                    append out ">\n"
     1831                    append out "  <url>$info(url)</url>\n"
     1832                    append out " </image>\n"
     1833                }
     1834                "elevation" {
     1835                    append out " <elevation"
     1836                    append out " name=\"$layer\""
     1837                    append out " driver=\"gdal\""
     1838                    if { $info(visible) } {
     1839                        append out " visible=\"true\""
     1840                    } else {
     1841                        append out " visible=\"false\""
     1842                    }
     1843                    append out ">\n"
     1844                    append out "  <url>$info(url)</url>\n"
     1845                    append out " </elevation>\n"
     1846                }
     1847                default {
     1848                    puts stderr "Type $info(type) not implemented in earthfile"
     1849                }
     1850            }
    17791851        }
    17801852    }
Note: See TracChangeset for help on using the changeset viewer.