1 | package require Tk |
---|
2 | package require Rappture |
---|
3 | package require RapptureGUI |
---|
4 | |
---|
5 | Rappture::resources::load |
---|
6 | |
---|
7 | set commondir [file join [file dirname [info script]] .. common] |
---|
8 | source [file join $commondir geovis_settings.tcl] |
---|
9 | |
---|
10 | # This method is called when a user modifies the selection in the map view. |
---|
11 | # This callback is installed in the viewer using setSelectCallback in the code below. |
---|
12 | # The callback has two arguments: |
---|
13 | # option - should be one of "annotation", "clear", "feature", "region" |
---|
14 | # args - depends on option, see below |
---|
15 | proc selectHandler {option {args ""}} { |
---|
16 | switch $option { |
---|
17 | "annotation" { |
---|
18 | # An annotation (not in a feature layer) was selected, the single argument |
---|
19 | # is a list of the selected annotation names. |
---|
20 | } |
---|
21 | "clear" { |
---|
22 | # Previously selected features or annotations have been deselected. |
---|
23 | # No arguments. |
---|
24 | puts "select clear" |
---|
25 | } |
---|
26 | "feature" { |
---|
27 | # The feature selection set changed, the arguments are: |
---|
28 | # op - "add", "delete" or "set" |
---|
29 | # featureIdList - a list of feature identifiers. |
---|
30 | # layerName - the name of the layer the features were found in. |
---|
31 | foreach {op featureIdList layerName} $args break |
---|
32 | switch $op { |
---|
33 | "add" { |
---|
34 | puts "select feature add:\nfeatureIDList=\"$featureIdList\"\nlayerName=\"$layerName\"" |
---|
35 | } |
---|
36 | "delete" { |
---|
37 | puts "select feature delete:\nfeatureIDList=\"$featureIdList\"\nlayerName=\"$layerName\"" |
---|
38 | } |
---|
39 | "set" { |
---|
40 | puts "select feature set:\nfeatureIDList=\"$featureIdList\"\nlayerName=\"$layerName\"" |
---|
41 | } |
---|
42 | default { |
---|
43 | error "bad op \"$op\": should be one of: add, delete or set" |
---|
44 | } |
---|
45 | } |
---|
46 | } |
---|
47 | "region" { |
---|
48 | # An area defined by two wgs84 corner points was selected. |
---|
49 | # Here x is wgs84 decimal degrees longitude and y is wgs84 decimal degrees latitude. |
---|
50 | foreach {xmin ymin xmax ymax} $args break |
---|
51 | puts "select region: ($xmin, $ymin) - ($xmax, $ymax)" |
---|
52 | } |
---|
53 | default { |
---|
54 | error "bad option \"$option\": should be one of: annotation, clear, feature or region" |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | set width 400 |
---|
60 | set height 300 |
---|
61 | wm geometry . ${width}x${height} |
---|
62 | update |
---|
63 | |
---|
64 | set mapviewer [Rappture::MapViewer .g] |
---|
65 | |
---|
66 | pack .g -expand yes -fill both |
---|
67 | |
---|
68 | # Driver parameter array for XYZ provider |
---|
69 | array set xyzParams { |
---|
70 | url {http://otile[1234].mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg} |
---|
71 | } |
---|
72 | # Image layer parameter array |
---|
73 | array set osmParams { |
---|
74 | label "OSM Map" |
---|
75 | description "MapQuest OpenStreetMap Street base layer" |
---|
76 | opacity 1.0 |
---|
77 | } |
---|
78 | |
---|
79 | # Driver parameter array for OGR provider |
---|
80 | array set ogrParams { |
---|
81 | url {local://station_clean.csv} |
---|
82 | } |
---|
83 | # Icon layer parameter array |
---|
84 | array set stationParams { |
---|
85 | label "CSV data" |
---|
86 | description "using OGR data provider to load data from a CSV file" |
---|
87 | style "-icon pin4" |
---|
88 | } |
---|
89 | # Stylesheet for use with generic feature layer |
---|
90 | set stylesheet " |
---|
91 | station { |
---|
92 | icon: /opt/hubzero/rappture/render/lib/resources/pin04.png; |
---|
93 | icon-declutter: true; |
---|
94 | text-content: \[Building_Name\]; |
---|
95 | text-fill: #000000; |
---|
96 | text-halo: #FFFFFF; |
---|
97 | text-declutter: true; |
---|
98 | } |
---|
99 | " |
---|
100 | |
---|
101 | # Create a map object |
---|
102 | set map [Rappture::Map #auto] |
---|
103 | |
---|
104 | # Add all layers to the map object |
---|
105 | $map addLayer image \ |
---|
106 | osm [array get osmParams] \ |
---|
107 | xyz [array get xyzParams] |
---|
108 | $map addLayer icon \ |
---|
109 | stations [array get stationParams] \ |
---|
110 | ogr [array get ogrParams] |
---|
111 | #$map addLayer feature \ |
---|
112 | stations [array get stationParams] \ |
---|
113 | ogr [array get ogrParams] \ |
---|
114 | $stylesheet |
---|
115 | |
---|
116 | # Add a map to the vis client |
---|
117 | $mapviewer scale $map |
---|
118 | $mapviewer add $map |
---|
119 | |
---|
120 | |
---|
121 | # Set the proc/method to be called when a feature is selected on the map. |
---|
122 | # In this case we give the full path to the previously defined |
---|
123 | # procedure named "selectHandler". For an itcl class method, you may need to |
---|
124 | # use itcl::code to get the full path of the callback method, e.g. |
---|
125 | # [itcl::code $this selectHandler] |
---|
126 | $mapviewer setSelectCallback ::selectHandler |
---|