Changeset 6279 for trunk


Ignore:
Timestamp:
Apr 20, 2016, 3:16:23 PM (8 years ago)
Author:
ldelgass
Message:

Update example for new protocol

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/mapviewer/select/select_feature_example.tcl

    r6278 r6279  
    77source [file join $commondir geovis_settings.tcl]
    88
    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
     14proc selectHandler {option {args ""}} {
    1415    switch $option {
    1516        "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.
    1719        }
    1820        "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.
    2123            puts "select clear"
    2224        }
    2325        "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            }
    4045        }
    4146        "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)"
    4351        }
    4452        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"
    4754        }
    4855    }
     
    9198"
    9299
    93 # create a map object
     100# Create a map object
    94101set map [Rappture::Map #auto]
    95102
    96 # add all layers to the map object
     103# Add all layers to the map object
    97104$map addLayer image \
    98105    osm [array get osmParams] \
     
    106113    $stylesheet
    107114
    108 # add a map to the vis client
     115# Add a map to the vis client
    109116$mapviewer scale $map
    110117$mapviewer add $map
    111118
    112119
    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 defined
    115 # procedure named "handler". for an itcl class method, you may need to
    116 # use itcl::code to get the full path of the  callback method:
    117 # for example: [itcl::code $this handler]
    118 $mapviewer setSelectCallback ::handler
     120# 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.