Changes between Version 2 and Version 3 of MapGuideTutorial


Ignore:
Timestamp:
Mar 12, 2008, 5:20:34 AM (16 years ago)
Author:
pagameba
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MapGuideTutorial

    v2 v3  
    204204The Fusion application object provides two specific events that can be used by applications to get notification of when Fusion initialization has completed and when an error occurs anywhere in Fusion.  These events are:
    205205
    206 FUSION_INITIALIZED:
     206{{{Fusion.Event.FUSION_INITIALIZED}}}:
    207207  This is triggered when Fusion's initialization is complete and the application is running.  This signals that it is safe for the application to communicate with specific widgets.  Note that the Map widget, specifically, will be ready but may not have actually loaded the map.  There is a separate event for that (see the Map widget in the Command API reference).  Applications should register for this event before calling Fusion.initialize().
    208 FUSION_ERROR:
     208{{{Fusion.Event.FUSION_ERROR}}}:
    209209  This is triggered when an internal error happens.  Details on the error are passed to the callback function.  Applications should register for this event before calling {{{Fusion.initialize()}}} to ensure that they receive errors that happen during initialization.
    210210
     
    219219The Map widget API is probably the most used one in Fusion.  It is completely documented in the Command API reference, but the most used methods are described here.
    220220
    221 loadMap(mapDefinition):
     221{{{loadMap(mapDefinition):}}}
    222222  This causes the Map widget to load the specified MapDefinition.
    223 reloadMap():
     223{{{reloadMap():}}}
    224224  This causes the Map widget to reload the current MapDefinition.  This is necessary when the map state has changed in certain ways (adding or removing layers in the map, for instance) and is primarily an internal function.
    225225setExtents(minx, miny, maxx, maxy).  This is used to set the map extents to a particular bounding box programmatically.
    226 drawMap():
     226{{{drawMap():}}}
    227227  This is used to render a map image and load it in the browser.  Normally, this is called automatically as required, but occasionally it may be required to be called programmatically when the state of the map has changed on the server without the knowledge of the Map widget.
    228 query(options):
     228{{{query(options):}}}
    229229  This is described more completely in the Command API Reference, but the query method is used to query the Map in some way and create (or modify) a selection.
    230 getSessionId():
    231 
    232 When a Map is defined in the ApplicationDefinition file, it can have a default MapDefinition that is automatically loaded when the application is loaded.  But it is not mandatory to specify a default map.  When no default map is specified, the Map widget is still initialized.  Loading of a MapDefinition is then done in response to a widget (such as the MapMenu widget) or some application-specific code.  Regardless of how it happens, when a MapDefinition has been loaded, the Map widget will trigger a MAP_LOADED event.  Most widgets are not useful if there is no map loaded, so they use the MAP_LOADED event to determine when they should be enabled.  This means that most widgets will appear initially disabled until the map has been loaded.  There are some notable exceptions, including the Map Menu widget which is used to provide a drop-down menu of MapDefinitions that the user can pick from.
     230{{{getSessionId():}}}
     231  This returns the session id that is used with the server side support scripts for this map.
     232 
     233When a Map is defined in the ApplicationDefinition file, it can have a default !MapDefinition that is automatically loaded when the application is loaded.  But it is not mandatory to specify a default map.  When no default map is specified, the Map widget is still initialized.  Loading of a !MapDefinition is then done in response to a widget (such as the MapMenu widget) or some application-specific code.  Regardless of how it happens, when a !MapDefinition has been loaded, the Map widget will trigger a {{{Fusion.Event.MAP_LOADED}}} event.  Most widgets are not useful if there is no map loaded, so they use the {{{Fusion.Event.MAP_LOADED}}} event to determine when they should be enabled.  This means that most widgets will appear initially disabled until the map has been loaded.  There are some notable exceptions, including the Map Menu widget which is used to provide a drop-down menu of !MapDefinitions that the user can pick from.
    233234
    234235Once the Map is loaded, many events may be triggered, including:
    235236
    236 MAP_SESSION_CREATED.  The Map widget is responsible for creating and maintaining a session with the server.  When the session has been created, this event is triggered.  Nothing can happen until this event has been triggered.
    237 MAP_LOADING.  The Map widget triggers this event when it is starting to load a new Map.  This is primarily used by widgets to prepare themselves for the new map by discarding their current state and temporarily disabling themselves.
    238 MAP_LOADED.  The Map widget triggers this event when a map has been loaded and is ready.
    239 MAP_EXTENTS_CHANGED.  The Map widget triggers this event for any navigation that changes the current extents.
    240 MAP_BUSY_CHANGED.  The Map widget maintains a reference count of asynchronous events as they start and finish.  An application can use this event to display a processing image so that the user is aware that some asynchronous activitity is happening.
    241 MAP_RESIZED.  The Map widget triggers this event when the size of the map is changed.
    242 MAP_SELECTION_ON.  The Map widget triggers this event when a new selection has been created.
    243 MAP_SELECTION_OFF.  The Map widget triggers this event when the current selection has been cleared.
    244 MAP_ACTIVE_LAYER_CHANGED.  The Map widget allows for a single layer to be marked as active by the application.  This event is triggered when the active layer is changed.
    245 MAP_GENERIC_EVENT.  Most widgets rely directly on their Map widget for everything.  In some cases, though, widgets need to be informed of changes in other widgets.  In these cases, the Map widget can act as a broker for events through the MAP_GENERIC_EVENT.  Widgets that employ the MAP_GENERIC_EVENT normally do so for a specific internal purpose, and the application should not normally register for this event.
    246 
    247 Working with Selections
     237{{{Fusion.Event.MAP_SESSION_CREATED}}}:
     238  The Map widget is responsible for creating and maintaining a session with the server.  When the session has been created, this event is triggered.  Nothing can happen until this event has been triggered.
     239{{{Fusion.Event.MAP_LOADING}}}:
     240  The Map widget triggers this event when it is starting to load a new Map.  This is primarily used by widgets to prepare themselves for the new map by discarding their current state and temporarily disabling themselves.
     241{{{Fusion.Event.MAP_LOADED}}}:
     242  The Map widget triggers this event when a map has been loaded and is ready.
     243{{{Fusion.Event.MAP_EXTENTS_CHANGED}}}:
     244  The Map widget triggers this event for any navigation that changes the current extents.
     245{{{Fusion.Event.MAP_BUSY_CHANGED}}}:
     246  The Map widget maintains a reference count of asynchronous events as they start and finish.  An application can use this event to display a processing image so that the user is aware that some asynchronous activitity is happening.
     247{{{Fusion.Event.MAP_RESIZED}}}:
     248  The Map widget triggers this event when the size of the map is changed.
     249{{{Fusion.Event.MAP_SELECTION_ON}}}:
     250  The Map widget triggers this event when a new selection has been created.
     251{{{Fusion.Event.MAP_SELECTION_OFF}}}:
     252  The Map widget triggers this event when the current selection has been cleared.
     253{{{Fusion.Event.MAP_ACTIVE_LAYER_CHANGED}}}:
     254  The Map widget allows for a single layer to be marked as active by the application.  This event is triggered when the active layer is changed.
     255{{{Fusion.Event.MAP_GENERIC_EVENT}}}:
     256  Most widgets rely directly on their Map widget for everything.  In some cases, though, widgets need to be informed of changes in other widgets.  In these cases, the Map widget can act as a broker for events through the MAP_GENERIC_EVENT.  Widgets that employ the {{{Fusion.Event.MAP_GENERIC_EVENT}}} normally do so for a specific internal purpose, and the application should not normally register for this event.
     257
     258== Working with Selections ==
    248259
    249260There are several widgets in Fusion that allow the user to interactively select features on the Map.  Fusion takes care of updating the Map image with the current selection, if necessary, but does not display attributes of the selected features to the user.  That is up to the application.
     
    251262Regardless of how the features are selected, the Map widget provides the API for an application to retrieve and work with the user's selection.  There are two events that can be used by an application to know when the user selection has changed:
    252263
    253 MAP_SELECTION_ON.  The Map widget triggers this event when a new selection has been created.
    254 MAP_SELECTION_OFF.  The Map widget triggers this event when the current selection has been cleared.
    255 
    256 When the application receives a MAP_SELECTION_ON event from the Map widget, it can use the following functions to work with the selection:
    257 
    258 hasSelection().  This method returns a boolean value which indicates if there is currently a selection or not
    259 getSelection(callback).  This method retrieves the current selection.  Retrieving the selection is potentially an asynchronous operation and so the callee provides a callback function that is called when the selection is ready.  The callback function is passed a single argument, a Selection object, described below.
    260 clearSelection().  This method is used to clear the current selection.  This removes the selection from the map and invalidates the current selection object.
     264{{{Fusion.Event.MAP_SELECTION_ON}}}:
     265  The Map widget triggers this event when a new selection has been created.
     266{{Fusion.Event.{MAP_SELECTION_OFF}}}:
     267  The Map widget triggers this event when the current selection has been cleared.
     268
     269When the application receives a {{{Fusion.Event.MAP_SELECTION_ON}}} event from the Map widget, it can use the following functions to work with the selection:
     270
     271{{{hasSelection()}}}:
     272  This method returns a boolean value which indicates if there is currently a selection or not
     273{{{getSelection(callback)}}}:
     274  This method retrieves the current selection.  Retrieving the selection is potentially an asynchronous operation and so the callee provides a callback function that is called when the selection is ready.  The callback function is passed a single argument, a Selection object, described below.
     275{{{clearSelection()}}}:
     276  This method is used to clear the current selection.  This removes the selection from the map and invalidates the current selection object.
    261277
    262278An application will typically call getSelection() in response to the MAP_SELECTION_ON event.  Typical code for this might look like:
    263279
     280{{{
    264281window.onload=function() {
    265     Fusion.registerForEvent(FUSION_INITIALIZED, onInitialized);
     282    Fusion.registerForEvent(Fusion.Event.FUSION_INITIALIZED, onInitialized);
    266283    Fusion.initialize();
    267284}
     
    270287function onInitialized() {
    271288    theMap = Fusion.getWidgetById('Map');
    272     theMap.registerForEvent(MAP_SELECTION_ON, selectionOn);
    273     theMap.registerForEvent(MAP_SELECTION_OFF, selectionOff);
     289    theMap.registerForEvent(Fusion.Event.MAP_SELECTION_ON, selectionOn);
     290    theMap.registerForEvent(Fusion.Event.MAP_SELECTION_OFF, selectionOff);
    274291}
    275292
     
    286303    //clear the selection results
    287304}
     305}}}
    288306
    289307A Selection object is used to access the selection results.  It provides the following API:
    290308
    291 getNumLayers() returns the number of layers that have features selected
    292 getNumElements() returns the total number of features that are selected
    293 getLowerLeftCoord() returns the lower, left coordinate of the bounding box of all selected features
    294 getUpperRightCoord() returns the upper, right coordinate of the bounding box of all selected features
    295 getLayerByName(name) gets the layer selection object for a layer from the name of the layer.  This returns null if there is no layer with the requested name in the selection results
    296 getLayer(index) gets the layer selection object for the requested layer where index is between 0 and one less that the value returned by getNumLayers().
     309{{{getNumLayers()}}}:
     310 returns the number of layers that have features selected
     311{{{getNumElements()}}}:
     312 returns the total number of features that are selected
     313{{{getLowerLeftCoord()}}}:
     314 returns the lower, left coordinate of the bounding box of all selected features
     315{{{getUpperRightCoord()}}}:
     316 returns the upper, right coordinate of the bounding box of all selected features
     317{{{getLayerByName(name)}}}:
     318 gets the layer selection object for a layer from the name of the layer.  This returns null if there is no layer with the requested name in the selection results
     319{{{getLayer(index)}}}:
     320 gets the layer selection object for the requested layer where index is between 0 and one less that the value returned by {{{getNumLayers()}}}.
    297321
    298322An application will typically loop over the layers in a selection and retrieve individual results using the Layer Selection object returned by getLayer() or getLayerByName().  Layer selection objects have the following API
    299323
    300 getName() returns the name of the layer that the selected features are in
    301 getNumElements() returns the number of features selected in this layer
    302 getNumProperties() returns the number of data properties, or attributes, of the features in this layer
    303 getPropertyNames() returns an array of the names of each of the properties
    304 getPropertyTypes() returns an array of the types of the properties
    305 getElementValue(elementIndex, propertyIndex) returns the actual value of a given property for a given element
    306 
    307        
     324{{{getName()}}}:
     325 returns the name of the layer that the selected features are in
     326{{{getNumElements()}}}:
     327 returns the number of features selected in this layer
     328{{{getNumProperties()}}}:
     329 returns the number of data properties, or attributes, of the features in this layer
     330{{{getPropertyNames()}}}:
     331 returns an array of the names of each of the properties
     332{{{getPropertyTypes()}}}:
     333 returns an array of the types of the properties
     334{{{getElementValue(elementIndex, propertyIndex)}}}:
     335 returns the actual value of a given property for a given element
     336
    308337The following code is an example of how to use the Selection and Layer Selection objects to create a tabular display of selected features.
    309338
     339{{{
    310340function displaySelection(selection) {
    311341    //display the selection to the user in some way ...
     
    352382    }
    353383}
    354 
     384}}}