- Timestamp:
- Apr 20, 2016, 3:16:23 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/mapviewer/select/select_feature_example.tcl
r6278 r6279 7 7 source [file join $commondir geovis_settings.tcl] 8 8 9 # this method is called when a user clicks on a icon in the map 10 # the method is used at the bottom of this example 11 # the callback is called with two arguments: 12 # option - should be one of "annotation", "clear", "feature" 13 proc handler {option {args ""}} { 9 # This method is called when a user modifies the selection in the map view. 10 # This callback is installed in the viewer using setSelectCallback in the code below. 11 # The callback has two arguments: 12 # option - should be one of "annotation", "clear", "feature", "region" 13 # args - depends on option, see below 14 proc selectHandler {option {args ""}} { 14 15 switch $option { 15 16 "annotation" { 16 # pass 17 # An annotation (not in a feature layer) was selected, the single argument 18 # is a list of the selected annotation names. 17 19 } 18 20 "clear" { 19 # previously selected features have been unselected.20 # no arguments associated with this option.21 # Previously selected features or annotations have been deselected. 22 # No arguments. 21 23 puts "select clear" 22 24 } 23 25 "feature" { 24 # a feature was selected, the server returns 4 values about the feature 25 # that are held in args: 26 # globalObjId - the global object identifier 27 # featureIdList - a single value or list of feature identifiers. 28 # if multiple features are returned, they arei 29 # enclosed in curly brackets. 30 # numFeaturesInLayer - the number of features in the layer 31 # layerName - the name of the layer the features were found in. 32 # only features from a single layer can be selected 33 # at a time. 34 foreach {globalObjId featureIdList numFeaturesInLayer layerName} $args break 35 puts "handler caught\ 36 globalObjId=\"$globalObjId\"\ 37 featureIdList=\"$featureIdList\"\ 38 numFeaturesInLayer=\"$numFeaturesInLayer\"\ 39 layerName=\"$layerName\"" 26 # The feature selection set changed, the arguments are: 27 # op - "add", "delete" or "set" 28 # featureIdList - a list of feature identifiers. 29 # layerName - the name of the layer the features were found in. 30 foreach {op featureIdList layerName} $args break 31 switch $op { 32 "add" { 33 puts "select feature add:\nfeatureIDList=\"$featureIdList\"\nlayerName=\"$layerName\"" 34 } 35 "delete" { 36 puts "select feature delete:\nfeatureIDList=\"$featureIdList\"\nlayerName=\"$layerName\"" 37 } 38 "set" { 39 puts "select feature set:\nfeatureIDList=\"$featureIdList\"\nlayerName=\"$layerName\"" 40 } 41 default { 42 error "bad op \"$op\": should be one of: add, delete or set" 43 } 44 } 40 45 } 41 46 "region" { 42 puts "select region $args" 47 # An area defined by two wgs84 corner points was selected. 48 # Here x is wgs84 decimal degrees longitude and y is wgs84 decimal degrees latitude. 49 foreach {xmin ymin xmax ymax} $args break 50 puts "select region: ($xmin, $ymin) - ($xmax, $ymax)" 43 51 } 44 52 default { 45 error "bad option \"$option\": should be one of annotation,\ 46 clean, or feature" 53 error "bad option \"$option\": should be one of: annotation, clean, feature or region" 47 54 } 48 55 } … … 91 98 " 92 99 93 # create a map object100 # Create a map object 94 101 set map [Rappture::Map #auto] 95 102 96 # add all layers to the map object103 # Add all layers to the map object 97 104 $map addLayer image \ 98 105 osm [array get osmParams] \ … … 106 113 $stylesheet 107 114 108 # add a map to the vis client115 # Add a map to the vis client 109 116 $mapviewer scale $map 110 117 $mapviewer add $map 111 118 112 119 113 # set the proc/method to be called when a feature is selected on the map.114 # in this case we give the full path to the previously defined115 # procedure named " handler". for an itcl class method, you may need to116 # use itcl::code to get the full path of the callback method:117 # for example: [itcl::code $this handler]118 $mapviewer setSelectCallback :: handler120 # Set the proc/method to be called when a feature is selected on the map. 121 # In this case we give the full path to the previously defined 122 # procedure named "selectHandler". For an itcl class method, you may need to 123 # use itcl::code to get the full path of the callback method, e.g. 124 # [itcl::code $this selectHandler] 125 $mapviewer setSelectCallback ::selectHandler
Note: See TracChangeset
for help on using the changeset viewer.