gxp.Viewer¶
-
class
gxp.Viewer(config)¶ A map viewer application framework that can be extended with plugins for layer sources and tools. Types of viewers that can be built with this framework range from simple map viewers to complex web-based GIS applications with capabilities like feature editing, styling and more.
Example Use¶
A viewer can be added to an HTML page with a script block containing something like this for a minimal viewer with an OSM layer:
var app = new gxp.Viewer({
sources: {
osm: {
ptype: "gxp_osmsource"
}
},
map: {
center: [0, 0],
zoom: 2,
layers: [{
source: "osm",
name: "mapnik"
}]
}
});
Config Options¶
Configuration properties in addition to those listed for Ext.util.Observable.
-
authenticate FunctionA global authentication function that is invoked bydoAuthorized()if no user is logged in or the current user is not authorized. That process is supposed to callsetAuthorizedRoles()upon successful authentication, andcancelAuthentication()if the user cancels the login process. Typically this function creates and opens a login window. Optional, default is null.
-
defaultSourceType StringThe default layer source plugin type.
-
defaultToolType StringThe default tool plugin type. Default is “gxp_tool”
-
field gxp.form.ViewerFieldOptional - set bygxp.form.ViewerFieldso plugins likegxp.plugins.FeatureToFieldcan set the form field’s value.
-
map ObjectMap configuration for this viewer. This object is similar to theGeoExt.MapPanelconfiguration, with the following exceptions:center:
Arrayof lon (x) and lat (y) valuesitems: not available - use
mapItemsinsteadtbar: not available - use
gxp.Toolplugins to populate the tbarwrapDateLine:
BooleanShould we wrap the dateline? Defaults to truenumZoomLevels:
IntegerThe number of zoom levels to use.layers:
Array(Object). Each object has asourceproperty referencing agxp.plugins.LayerSource. The viewer will call thecreateLayerRecordof this source with the object as argument, which will result in a layer being created with the configuration provided here.Valid config options for all layer sources:
- source:
Stringreferencing a source fromsources - name:
String- the name from the source’sstore(only for sources that maintain a store) - visibility:
Boolean- initial layer visibility - opacity:
Number- initial layer.opacity - group:
String- group for the layer when the viewer also uses agxp.plugins.LayerTree. Set this to “background” to make the layer a base layer - fixed:
Boolean- Set to true to prevent the layer from being removed by agxp.plugins.RemoveLayertool and from being dragged in agxp.plugins.LayerTree - selected:
Boolean- Set to true to mark the layer selected
- source:
map: not available, can be configured with
maxExtent,numZoomLevelsandtheme.restrictedExtent:
Arrayto be consumed byOpenLayers.Bounds.fromArray- the restrictedExtent of the mapmaxExtent:
Arrayto be consumed byOpenLayers.Bounds.fromArray- the maxExtent of the mapnumZoomLevels:
Number- the number of zoom levels if not available on the first layertheme:
String- optional theme for theOpenLayers.Map, as inOpenLayers.Map.theme.
-
mapItems Array(Ext.Component)Any items to be added to the map panel. A typical item to put on a map would be aGeoExt.ZoomSlider.
-
mapPlugins Array(Ext.util.Observable)Any plugins to be added to the map panel.
-
portalConfig ObjectConfiguration object for the wrapping container of the viewer. This will be anExt.Panelif it has arenderToproperty, or anExt.Viewportotherwise.
-
portalItems ArrayItems for the portal. A MapPanel will automatically be added to the portal, unlessportalConfighasitemsconfigured.
-
proxy StringAn optional proxy url which can be used to bypass the same origin policy. This will be set asOpenLayers.ProxyHost.
-
saveErrorText String
-
sources ObjectLayer source configurations for this viewer, keyed by source id. The source id will be used to reference the layer source in thelayersarray of themapobject.
-
tools Array(gxp.plugins.Tool)Any tools to be added to the viewer. Tools are plugins that will be plugged into this viewer’sportal. Thetoolsarray is usually populated with configuration objects for plugins (using a ptype), rather than instances. A default ptype can be configured with this viewer’sdefaultToolTypeoption.
Public Properties¶
Public properties in addition to those listed for Ext.util.Observable.
-
Viewer.authenticate¶ FunctionLike the config option above, but this can be set after configuration e.g. by a plugin that provides authentication. It can also be accessed to check if an authentication mechanism is available.
ArrayRoles the application is authorized for. This property is usually set by thesetAuthorizedRoles()method, which is typically called by a component that authenticates the user (e.g. a login window. After authentication, if the client is authorized to do everything, this should be set to["ROLE_ADMINISTRATOR"].If this property is undefined, the
isAuthorized()method will return undefined, so plugins can check for that to do their own auth checks in this case. So if the application uses an authentication component (e.g. a login window), it is recommended to set this to[](equivalent to “not authorized to do anything”) initially.
-
Viewer.field¶ gxp.form.ViewerFieldUsed by plugins to access the form field. Only available if this viewer is wrapped into anExt.form.ViewerField.
-
Viewer.portalItems¶ Array(Ext.Component)Items that make up the portal.
-
Viewer.selectedLayer¶ GeoExt.data.LayerRecordThe currently selected layer
-
Viewer.tools¶ ObjectStorage of tool instances for this viewer, keyed by id
Public Methods¶
Public methods in addition to those listed for Ext.util.Observable.
-
Viewer.cancelAuthentication()¶ Cancel an authentication process.
-
Viewer.createLayerRecord()¶ Parameters: - config –
ObjectA minimal layer configuration object with source and name properties. - callback –
FunctionA function to be called with the layer record that corresponds to the given config. - scope –
ObjectOptional scope for the callback.
Asyncronously retrieves a layer record given a basic layer config. The callback will be called as soon as the desired layer source is ready. This method should only be called to retrieve layer records from sources configured before the call.
- config –
-
Viewer.destroy()¶
-
Viewer.doAuthorized()¶ Parameters: - roles –
ArrayRoles required for invoking the action - callback –
FunctionThe action to perform - scope –
ObjectThe execution scope for the callback
Performs an action (defined as
callbackfunction), but only if the user is authorized to perform it. If no user is logged in or the logged in user is not authorized, the viewer’sauthenticate()function will be invoked. This method is usually called by plugins.- roles –
-
Viewer.getLayerRecordFromMap()¶ Parameters: config – ObjectA minimal layer configuration object with source and name properties.Returns: GeoExt.data.LayerRecordRetrieves a layer record from the map.
-
Viewer.getSource()¶ Parameters: layerRec – GeoExt.data.LayerRecordthe layer to get the source for.
-
Viewer.isAuthenticated()¶ Returns: BooleanThe user has authenticated.Determines whether a user has logged in. In cases where the application doesn’t provide a login dialog, the user will be considered logged in. In this same case, where components require authentication, the browser will prompt for credentials when needed.
-
Viewer.isAuthorized()¶ Parameters: roles – String|Arrayoptional, default is “ROLE_ADMINISTRATOR”. If an array is provided, this method will return if any of the roles in the array is authorized.Returns: BooleanThe user is authorized for the given role.Returns true if the client is authorized with the provided role. In cases where the application doesn’t explicitly handle authentication, the user is assumed to be authorized for all roles. This results in authentication challenges from the browser when an action requires credentials.
-
Viewer.loadConfig()¶ Parameters: config – ObjectThe config object passed to the constructor.Subclasses that load config asynchronously can override this to load any configuration before applyConfig is called.
-
Viewer.selectLayer()¶ Parameters: record – GeoExt.data.LayerRecord`Layer record. Call with no layer record to remove layer selection.Returns: BooleanLayers were set as selected.TODO: change to selectLayers (plural)
-
Viewer.setAuthorizedRoles()¶ Parameters: authorizedRoles – ArrayChange the authorized roles.
Events¶
Events in addition to those listed for Ext.util.Observable.
-
authorizationchange Fired when the authorizedRoles are changed, e.g. when a user logs in or out.
-
beforecreateportal Fires before the portal is created by the Ext ComponentManager.
-
beforehashchange Fires before the hash is updated after saving a map. Return false in the listener not to update the hash.
Listeners arguments: * hash -
StringThe hash which will be set aswindow.location.hash
-
beforelayerselectionchange Fired before the selected set of layers changes. Listeners can return
falseto stop the selected layers from being changed.Listeners arguments:
- layerRecord -
GeoExt.data.LayerRecordthe record of the selected layer, or null if no layer is selected.
- layerRecord -
-
beforesave Fires before application saves a map. If the listener returns false, the save is cancelled.
Listeners arguments:
- requestConfig -
Objectconfiguration object for the request, which has the following properties: method, url and data. - callback -
FunctionOptional callback function which was passed on to the save function.
- requestConfig -
-
featureedit Fired when features were edited.
Listener arguments:
- featureManager -
gxp.plugins.FeatureManagerthe the feature manager that was used for editing - layer -
Objectobject with name and source of the layer that was edited
- featureManager -
-
layerselectionchange Fired when the selected set of layers changes.
Listeners arguments:
- layerRecord -
GeoExt.data.LayerRecordthe record of the selected layer, or null if no layer is selected.
- layerRecord -
-
portalready Fires after the portal is initialized.
-
ready Fires when application is ready for user interaction.
-
save Fires when the map has been saved.
Listener arguments: * id -
IntegerThe identifier of the saved map