source: trunk/examples/mapviewer/feature/feature_multiple_selection_by_updated_layer.tcl @ 6370

Last change on this file since 6370 was 6370, checked in by dkearney, 6 years ago

adding feature multiple selection examples, not all ideas work right now.
using the afr_elas shapefile because they include country elasticity values from the landuse tool.
adding an example of using large stylesheets with multiple colors.
adding example of performing multiple selection by:

  1. deleting and adding a layer by the same name
  2. using a callback
  3. updating a layer with map object's addSelector method and mapviewer's refresh method.
File size: 2.6 KB
Line 
1package require Tk
2package require Rappture
3package require RapptureGUI
4
5Rappture::resources::load
6
7set commondir [file join [file dirname [info script]] .. common]
8source [file join $commondir geovis_settings.tcl]
9
10set width 400
11set height 300
12wm geometry . ${width}x${height}
13update
14
15set mapviewer [Rappture::MapViewer .g]
16
17pack .g -expand yes -fill both
18
19
20# Parameters for feature layer
21array set ogrParams {
22    url {local://afr_elas.shp}
23}
24array set countries {
25    label   "Countries"
26    opacity 1.0
27}
28set stylesheet {
29  s1 {
30    fill: #98AFC7;
31    stroke: #000000;
32    stroke-width: 3;
33    altitude-clamping: terrain-drape;
34  }
35  s2 {
36    fill: #00FFFF;
37    stroke: #000000;
38    stroke-width: 3;
39    altitude-clamping: terrain-drape;
40  }
41}
42array set selector1 {
43    id    1
44    style s1
45    query "POP2005 >= 0"
46}
47array set selector2 {
48    id    2
49    style s2
50    query "FID IN (0,1)"
51}
52set numSelectors 2
53for {set i 1} {$i <= $numSelectors} {incr i} {
54   lappend selectors [array get selector$i]
55}
56
57# Create a map object
58set map [Rappture::Map #auto]
59
60# Configure layers
61set layerId 0
62$map addLayer feature \
63    countries$layerId [array get countries] \
64    ogr [array get ogrParams] \
65    $stylesheet "" $selectors
66
67# Add map to viewer
68$mapviewer add $map
69$mapviewer scale $map
70
71after 2000 {
72    $mapviewer camera zoom layer $map countries$layerId
73}
74
75after 5000 {
76    puts "updating layer: reusing layer name (delete/add)"
77
78    $map deleteLayer countries$layerId
79
80    set selector2(query) "FID IN (0,1,2,3,4,5,6,7,8,12,15,44)"
81    set selectors ""
82    for {set i 1} {$i <= $numSelectors} {incr i} {
83       lappend selectors [array get selector$i]
84    }
85
86    $map addLayer feature \
87        countries$layerId [array get countries] \
88        ogr [array get ogrParams] \
89        $stylesheet "" $selectors
90
91    puts "refreshing mapviewer"
92    $mapviewer refresh
93}
94
95
96after 10000 {
97    puts "updating layer: new layer name"
98
99    set selector2(query) "FID IN (7,8,12,15,44)"
100    set selectors ""
101    for {set i 1} {$i <= $numSelectors} {incr i} {
102       lappend selectors [array get selector$i]
103    }
104
105    incr layerId
106    $map addLayer feature \
107        countries$layerId [array get countries] \
108        ogr [array get ogrParams] \
109        $stylesheet "" $selectors
110
111    puts "refreshing mapviewer"
112    $mapviewer refresh
113}
114
115
116after 15000 {
117    puts "updating layer selectors using addSelector/deleteSelector"
118
119    $map deleteSelector countries$layerId $selector2(id)
120    set selector2(query) "FID IN (33,34,35,36,37,38,39,4,48,21,43)"
121    $map addSelector countries$layerId $selector2(id) [array get selector2]
122
123    puts "refreshing mapviewer"
124    $mapviewer refresh
125}
Note: See TracBrowser for help on using the repository browser.