LayerLoader Class
Layer Loader class.
Handles the asynchronous loading of map layers (excluding basemaps) This includes dealing with errors, and raising appropriate events when the layer loads
Item Index
Methods
- _generatePart
- _generateParts
- _getFeatures
- _getField
- _hideLoadingImg
- _initEventHandlers
- _initListeners
- _initRepublishers
- _initScale
- _loadLayer
- _setParts
- _showLoadingImg
- _template
- _updateScale
- _wrapFileCallInPromise
- addLayer
- AddStaticLayer
- adjustPaneWidth
- applyExtentDefaulting
- checkBoundary
- createGroups
- enhanceLayer
- finishExtentProjection
- getBoundingBoxMapping
- getFeatureLayer
- getLayerItem
- getLayerState
- getVisibleFeatureLayers
- init
- initListeners
- initScrollListeners
- initTooltips
- loadLayer
- localProjectExtent
- makeFeatureLayer
- makeStaticLayer
- makeWmsLayer
- onFeatureDeselect
- onFeatureMouseOut
- onFeatureMouseOver
- onFeatureSelect
- onLayerError
- onLayerError
- onLayerError
- onLayerLoaded
- onLayerRemove
- onLayerRemove
- onLayerUpdateEnd
- onLayerUpdateStart
- prepLayer
- projectConfigExtents
- projectExtent
- projectFullExtent
- projectMaxExtent
- registerWMSClick
- removeLayer
- republish
- setBoundingBoxVisibility
- setButtonEvents
- setLayerOffScaleState
- setLayerOffScaleStates
- setLayerReorderingEvents
- setLayerState
- setState
- ui.addLayerGroup
- ui.update
- zoomToLayerScale
Properties
- _config
- _controlsNode
- _controlStore
- _displayNameNode
- _imageContainerNode
- _noticeStore
- _togglesNode
- _toggleStore
- baseLayer
- boundingBoxMapping
- featureLayers
- featureLayerStartIndex
- fullExtent
- getMap
- getMaxExtent
- id
- InitExtent
- maxExtent
- node
- state
- stateMatrix
- templates
- transitionMatrix
- type
- url
- wmsLayers
Events
- FilterManager.BOX_VISIBILITY_TOGGLED
- FilterManager.LAYER_TRANSPARENCY_CHANGED
- FilterManager.LAYER_VISIBILITY_TOGGLED
- FilterManager.SELECTION_CHANGED
- FilterManager.TOGGLE_BOX_VISIBILITY [subscribed]
- FilterManager.TOGGLE_LAYER_VISIBILITY [subscribed]
- FilterManager.UI_COMPLETE
- LayerLoader.LAYER_ERROR
- LayerLoader.LAYER_LOADED
- LayerLoader.LAYER_UPDATED
- LayerLoader.LAYER_UPDATING
- LayerLoader.RELOAD_LAYER
- LayerLoader.REMOVE_LAYER
Methods
_generatePart
-
templateKey
-
pKey
-
[data]
Generates a control given the template name and additional data object to pass to the template engine.
Parameters:
Returns:
Created part node
_generateParts
-
partType
-
templateKey
-
partStore
Generates control, toggle, and notice nodes for the LayerItem object to be used in different states.
_getFeatures
-
fl
Queries all map points on a given feature layer and returns their attributes
Parameters:
-
fl
ObjectA feature layer to query
Returns:
An array of attributes from the designated feature layer
_getField
-
fl
-
field
Grabs all distinct values of the given field from a featureLayer.
Parameters:
Returns:
deferred A deferred object which will resolve to an array of unique values
_hideLoadingImg
()
private
Hides the loading image.
_initEventHandlers
-
map
Creates event handlers for the map control: click, mouse-over, load, extent change, and update events.
Parameters:
-
map
ObjectA ESRI map object
_initListeners
-
map
Subscribe to external events (published using topic.publish) and react accordingly
Parameters:
-
map
Objectmap object
_initRepublishers
-
map
Republishes map events to the outside using topic.publish
Parameters:
-
map
Objectobject
_loadLayer
-
layer
-
reloadIndex
This function initiates the loading of an ESRI layer object to the map. Will add it to the map in the appropriate spot, wire up event handlers, and generate any bounding box layers Note: a point of confusion. The layer objects "load" event may have already finished by the time this function is called. This means the object's constructor has initialized itself with the layers data source. This functions is not event triggered to guarantee the order in which things are added.
Parameters:
-
layer
Objectan instantiated, unloaded ESRI layer object
-
reloadIndex
IntegerOptional. If reloading a layer, supply the index it should reside at. Do not set for new layers
_setParts
-
partType
-
partStore
-
target
Sets controls, toggles, and notices of the LayerItem according to its state.
_showLoadingImg
()
private
Shows the loading image.
_template
-
key
-
data
Populates a template specified by the key with the supplied data.
Returns:
a string template filled with supplied data
_wrapFileCallInPromise
-
readMethod
Helper function for wrapping File API calls in Promise objects. Used for building a series of helpers which call different file read methods.
Parameters:
-
readMethod
Stringa string indicating the FileReader method to call
Returns:
a function which accepts a {File} object and returns a Promise
addLayer
-
layerType
-
layerConfig
-
initState
Add a provided layer to the layer selector.
AddStaticLayer
-
layer_type
-
layer_url
-
layer_op
Add a static, non-interactive Layer to the map
adjustPaneWidth
()
private
Changes the width of the layers pane to accommodate for the scrollbar if it's needed.
applyExtentDefaulting
()
private
Apply extent defaulting prior to URL overrides.
checkBoundary
-
e
-
maxExtent
Given an ESRI Extent Object, returns a new ESRI Extent Object that contains the extent adjusted according to this map's maximum extent
NOTE: this method is currently unused!
Parameters:
-
e
Esri/geometry/Extentthe extent Object
-
maxExtent
Esri/geometry/Extentthe maximum extent
Returns:
An adjusted extent, if the target extent is outside the boundary
createGroups
()
private
Sets UI status of a layer presentation (checkbox and eye) according to the user action: select / de-select a layer. publishes event "filterManager/box-visibility-toggled" every time a layer status changed. There should only be one eye and one global checkbox, but we say checkbox"es" because jquery returns a list and it's easier to write a function that takes a list of checkboxes than to write two functions, one to take a list and one to take an individual checkbox
enhanceLayer
-
layer
-
config
-
userLayer
Adds custom ramp properties to layer. Adds handlers to loading events.
finishExtentProjection
-
projectedMaxExtent
process the projected maximum extent, then alert app to continue loading the map. used as an asynchronous gate for the projection.
Parameters:
-
projectedMaxExtent
Arrayan array containing the maximum extent object in the map's projection
getBoundingBoxMapping
()
Object
Returns the mapping of feature layer ids to assocciated bounding box layers.
Returns:
A dictionary of String, Esri/layers/GraphicsLayer pairs.
getFeatureLayer
-
featureId
Return the feature layer corresponding to the given id.
Parameters:
-
featureId
Stringthe id of the feature layer
Returns:
feature layer
getLayerItem
-
layerId
Returns a LayerItem object with specified layerId.
Parameters:
-
layerId
Stringa layer id
getLayerState
-
layerId
Returns the state of the layer with the specified layer id.
Parameters:
-
layerId
Stringa layer id
getVisibleFeatureLayers
()
Array
Returns a list of feature layers that are currently visible on the map.
Returns:
an array of Esri/layers/FeatureLayer objects
init
()
Initializes properties. Set up event listeners
initListeners
()
private
Initiates a listener to handle tab deselected event
initScrollListeners
()
private
Adjusts filter style according to the scroll action on the layers.
initTooltips
()
private
initialize a tooltip for each layer, using the layer name.
loadLayer
-
layer
-
reloadIndex
Public endpoint to initiate the loading of an ESRI layer object to the map.
Parameters:
-
layer
Objectan instantiated, unloaded ESRI layer object
-
reloadIndex
IntegerOptional. If reloading a layer, supply the index it should reside at. Do not set for new layers
localProjectExtent
-
extent
-
sr
Will project an extent to a desired spatial reference, using client side projection library. Avoids the need for Esri Geometry Service
Parameters:
-
extent
Esri/Extentextent to be projected
-
sr
Esri/SpatialReferenceEsri/SpatialReference to project to
Returns:
extent in the desired projection
makeFeatureLayer
-
layerConfig
-
userLayer
Create a new FeatureLayer object based on the config input
Parameters:
Returns:
feature layer object (unloaded)
makeStaticLayer
-
layerConfig
-
userLayer
Return the static layer corresponding to the given url.
Parameters:
Returns:
layer object of the appropriate type
makeWmsLayer
-
layerConfig
-
userLayer
Return the feature layer corresponding to the given url.
Parameters:
Returns:
WMS layer
onFeatureDeselect
()
This function is called whenever the "Details" button is deselected (either by the user click on another "Details" button, clicking on another point, or by clicking on an already highlighted "Details" button, or clicking somewhere on the map where is no features present).
onFeatureMouseOut
-
evt
This function is called whenever the user moves the mouse away from a feature being hovered over.
onFeatureMouseOver
-
evt
This function is called whenever the user hovers over a feature on the map when another feature already has been selected.
onFeatureSelect
-
evt
This function is called whenever the feature on the map is clicked/selected by the user. Publish the "Gui/subPanelOpen" message to indicate a feature has been selected. Panel content and Panel event handler information is passed in as the additional object for the event handler.
onLayerError
-
layerId
Will remove a layer from the map, and adjust counts.
Parameters:
-
layerId
Stringconfig id of the layer
onLayerError
-
layerId
-
newState
-
abortIfError
Will set a layerId's layer selector state to a new state.
onLayerError
-
evt
Deals with a layer that had an error when it tried to load.
onLayerLoaded
-
evt
Reacts when a layer has loaded successfully. This means the site has shaken hands with the layer and it seems ok. This does not mean data has been downloaded
onLayerRemove
-
evt
Reacts to a request for a layer to be reloaded. Usually the case when a layer errors and user wants to try again
onLayerRemove
-
evt
Reacts to a request for a layer to be removed. Usually the case when a layer errors and the user clicks remove.
onLayerUpdateEnd
-
evt
Reacts when a layer has updated successfully. This means the layer has pulled its data and displayed it.
onLayerUpdateStart
-
evt
Reacts when a layer begins to update. This happens when a feature layer starts to download its data. Data download doesn't start until points are made visible. It also happens when a WMS requests a new picture.
prepLayer
-
layer
-
config
-
userLayer
Sets up loading event handlers and initializes the .ramp object of a layer Circular reference errors prevent us from calling LayerLoader directly from this module
projectConfigExtents
()
initiate the projection of the config extents to basemap extents
projectExtent
-
extent
-
sr
-
callWhenDone
project an extent to a new spatial reference, if required when projection is finished, call another function and pass the result to it.
Parameters:
-
extent
Objectan extent object from the configuration
-
sr
Esri/SpatialReferenceEsri/SpatialReference to project to
-
callWhenDone
Functionfunction to call when extent is projected. expects geometry parameter
projectFullExtent
-
projectedDefaultExtent
process the projected default extent, begin projection of full extent. used as an asynchronous gate for the projection.
Parameters:
-
projectedDefaultExtent
Arrayan array containing the default extent object in the map's projection
projectMaxExtent
-
projectedFullExtent
process the projected full extent, begin projection of maximum extent. used as an asynchronous gate for the projection.
Parameters:
-
projectedFullExtent
Arrayan array containing the full extent object in the map's projection
registerWMSClick
-
map
This function should be called after the map has been created. It will subscribe to the Map.CLICK event and trigger GUI.SUBPANEL_OPEN events for displaying the response data.
Parameters:
-
map
Objectan EsriMap instance
removeLayer
-
layerType
-
layerId
Remove a layer from the layer selector.
setBoundingBoxVisibility
-
layerId
Sets the visibility of the bounding box that belongs to the layer with the given layerId. Note: the layerId needs to be the ID of the featurelayer, not the ID of the actual bounding box layer.
Parameters:
-
layerId
Stringthe id of the layer whose bounding box visibility should be set
setButtonEvents
()
private
Sets event handlers for various controls that may be present in the layer items. All event handlers are set on the main list container and are independed of the individual layer items.
setLayerOffScaleState
-
layerId
Checks if a specific layer has data that is not visible and sets the appropriate layer state.
Parameters:
-
layerId
Stringa layer id
setLayerOffScaleStates
()
private
Checks if any of the layers have data that is not visible and sets the appropriate layer state.
setLayerReorderingEvents
()
private
Sets all the events to handle layer reordering with both mouse and keyboard.
setLayerState
-
layerId
-
layerState
-
[options]
Set the state of the specified layer to the provided value.
setState
-
state
-
[options]
-
force
Changes the state of the LayerItem and update its UI representation.
Parameters:
-
state
Stringname of the state to be set
-
[options]
Object optionaladditional options
-
[notices]
Object optionalcustom information to be displayed in a notice for the current state if needed; object structure is not set; look at the appropriate template;
-
-
force
Booleanif
true
, forces the state change even if it's no allowed by thetransitionMatrix
Example:
{
notices: {
error: {
message: "I'm error"
},
scale: {
message: "All your base are belong to us"
}
}
}
ui.addLayerGroup
()
private
Add the provided layer group node to the layer selector ui.
ui.update
()
private
Updates certain UI aspects like layer settings panel (visibility sliders for now only), layer visibility and bounding box toggles, and layer sorting.
zoomToLayerScale
-
layerId
For a specified layer, zooms to the closest level that has some visible data.
Parameters:
-
layerId
Stringa layer id to zoom to.
Properties
_config
Object
private
A copy of the layer config supplied during LayerItem creation; is set to config
value.
Default: null
_controlsNode
JObject
private
A node of the layer controls.
Default: null
_displayNameNode
JObject
private
A node of the layer display name.
Default: null
_imageContainerNode
JObject
private
A node of the image container.
Default: null
_togglesNode
JObject
private
A node of the layer toggles.
Default: null
boundingBoxMapping
Object
private
Maps the id of a graphic layer to the GraphicsLayer Object that represents its extent bounding box. A dictionary of String, Esri/layers/GraphicsLayer pairs.
featureLayerStartIndex
Integer
private
The map not only contains feature layers, but also other layers such as the basemap layer, highlight layer, bounding box layer, etc. This variable is used to store the starting index of the feature layers in the map.
fullExtent
Esri/geometry/Extent
private
Used for full extent in nav widget
InitExtent
Esri/geometry/Extent
private
The initial extent of the map
maxExtent
Esri/geometry/Extent
private
The maximum extent of the map
node
JObject
A node of the LayerItem.
Default: null
state
String
State of this LayerItem; can be overwritten by options.state
.
Default: LayerItem.state.DEFAULT
stateMatrix
Object
Specifies a state matrix for this particular LayerItem. The default is mixed with options.stateMatrix
upon initialization.
The state matrix prescribes what controls, toggles, and notices are present in specific states.
Default: LayerItem.stateMatrix
templates
Object
Templates to be used in construction of the layer nodes.
Default: layer_selector_template.json
transitionMatrix
Object
Specifies a state transition matrix for this particular LayerItem. The default is mixed with options.transitionMatrix
upon initialization.
The state transition matrix prescribes the direction of state changes for specific states.
Default: LayerItem.transitionMatrix
type
String
Specifies type of this LayerItem and the name of the layer item template to use; can be overwritten by options.type
.
Default: null
Events
FilterManager.BOX_VISIBILITY_TOGGLED
Published whenever the "box" button for a layer is clicked
FilterManager.LAYER_TRANSPARENCY_CHANGED
Published each time the transparency of a layer is modified.
FilterManager.LAYER_VISIBILITY_TOGGLED
Published whenever the "eye" button for a layer is clicked
FilterManager.SELECTION_CHANGED
Published whenever the layer list is rearranged
FilterManager.TOGGLE_BOX_VISIBILITY [subscribed]
Tells the filter manager to toggle a layer on or off
FilterManager.TOGGLE_LAYER_VISIBILITY [subscribed]
Tells the filter manager to toggle a layer on or off
FilterManager.UI_COMPLETE
Published after the ui for the filter manager finishes initializing.
LayerLoader.LAYER_ERROR
Indicates that a map layer has errored
LayerLoader.LAYER_LOADED
Indicates that a map layer has loaded. This means the constructor initialized and shook hands with it's data source
LayerLoader.LAYER_UPDATED
Indicates that a map layer has updated. This means the data it is showing is visible and up-to-date
LayerLoader.LAYER_UPDATING
Indicates that a map layer has started updating. This means it is getting data from its source
LayerLoader.RELOAD_LAYER
Indicates that a map layer should be removed from the map