Maptitude GISDK Help |
Now you can add a dialog box ("get choice") to display the formatted list of distance, city and state, and allow the user to pick one or to cancel. You will revise the "find and zoom toolbox" dialog box code to call the "get choice" dialog box and, if the user picks a place, create a new scope for the map to show the clicked point and the chosen place, and then redraw the map. The test macro (now "lesson3") and the "get nearest points" macro remain the same and are not shown below. All of the Lesson 3 source code is stored in the LESSON3.RSC file in the GISDK\SAMPLES folder. Here is the the "get choice" dialog box:
// Create a dialog box to display the choices
DBox "get choice" (points_list) Title: "Choose an entry to zoom to"
// Displays the points_list formatted array of data; requires the
// user to choose one and click OK. Returns an array index for
// OK or null if Cancel is clicked.
Init do
// disable the OK button to start; enable it when a line
// in the scroll list is chosen.
DisableItem("OK")
endItem
// Add some titles for the scroll list.
Text "Distance" 1, 0
Text "City" 9, same
Text "State" 33, same
// Display the formatted array; the keyword "multiple" is not
// used, so only one choice will be possible. The points_idx
// variable will contain the index (subscript) of the selected
// array element.
Scroll List 1, 1, 40, 15 List: points_list Variable: points_idx
do
// When user makes a choice, enable the OK button.
EnableItem("OK")
endItem
// Add an OK button. The Default keyword allows the user to press Enter.
Button "OK" 21, 17, 7, 1 Default
Do
// Return the index (subscript) of the chosen element
return(points_idx)
endItem
// Add a Cancel button. The Cancel keyword allows the user to press Esc.
Button "Cancel" 31, same, 7, 1 Cancel
Do
// Return null if user cancels
return()
endItem
EndDBox
Most of the code for the "find and zoom toolbox" dialog box is the same as in Lesson 2. Only the new call to the dialog box and the code that follows are shown below:
// Call the dialog box to display the list and return the choice.
choice = RunDbox("get choice", formatting_array)
// If the user didn't press Cancel then create a scope and zoom
if choice<>null then do
// Get the conversion between miles and the current map units
mi_cmu = GetUnitSize("Miles", GetMapUnits("Plural"))
// Compute .1 and 5 miles in current units
tenth = .1 * mi_cmu
five = 5 * mi_cmu
// Create a tiny scope for the clicked point. A scope is a
// center point, and a width and height in the current map
// units. The last argument to Scope() must be zero.
clicked_pt_scp = Scope(clicked_point, tenth, tenth, 0)
// Create a tiny scope for chosen point; the coordinate is
// in array element 4.
chosen_pt_scp = Scope(points_list[choice][4], tenth, tenth, 0)
// Now combine the two scopes
new_scope = ScopeUnion(clicked_pt_scp, chosen_pt_scp)
// If the two points were less than five miles apart then set
// the scope width and height to 5 miles; otherwise expand
// the scope by 10% to add a margin.
if new_scope.height< five then
new_scope = Scope(new_scope.center, five, five, 0)
else new_scope = Scope(new_scope.center,
new_scope.width*1.1, new_scope.height*1.1, 0)
// Now set the new scope and redraw the current map.
SetMapScope(, new_scope)
RedrawMap()
end
To Compile and Run Lesson 3
You did not have to display the scroll list in a separate dialog box. You could easily have added it to the toolbox, but then it would have taken up a lot of space in a dialog box that stays on the screen all the time.
©2025 Caliper Corporation | www.caliper.com |