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
Imports RAMP Modules:
AttributeLoader EventManager FeatureClickHandler FilterManager GlobalStorage GraphicExtension LayerItem Map MapClickHandler Util
Item Index
Methods
- _loadLayer
- areaSearch
- executeSearch
- fsaSearch
- generalSearch
- geoSearch
- getConciseList
- getLayerConfig
- getProvCode
- getProvList
- init
- isInExtent
- isLatLong
- isLatLong
- isProvince
- isValidHilight
- loadLayer
- nextId
- onLayerError
- onLayerLoaded
- onLayerReload
- onLayerRemove
- onLayerUpdateEnd
- onLayerUpdateStart
- parseInput
- removeFromMap
- updateLayerSelectorState
Methods
_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
areaSearch
-
filters
-
defResult
Will trigger an area search and package the results
executeSearch
-
params
Will execute a specific search against the geoname service
Parameters:
-
params
Objectvalues to use in the search
Returns:
promise of results
fsaSearch
-
fsa
Will search for an FSA Promise delivers centroid lat long if FSA is found
Parameters:
-
fsa
StringFSA code
Returns:
promise of results
generalSearch
-
name
-
filters
-
defResult
Will trigger an basic name search, apply filters, and package the results
geoSearch
-
input
-
filters
Will search on user input string. Public endpoint for searches, will orchestrate the appropriate search calls. Accepts the following filter properties
- radius: size of search radius search in km. default 10. only used with lat/long or FSA searches
- prov: province code (numeric, e.g. 35, not 'ON')
- concise: concise type code
- showAll: show all results or clip to first 10. default false
- extent: extent of search area in lat/long [xmin, ymin, xmax, ymax]. caller will project from basemap to latlong. reasoning: caller can project once then cache until extent changes
Result object can have the following properties
- status: status of the search. values are list, none, hide. list means results are present. none means no results. hide means nothing should be shown (e.g. 1 char search string, bad postal code)
- defItem: a lonlat array of the default result to zoom to if a person hits enter. for FSA, it is FSA centroid; for lat/long, it is the lat/long point; otherwise it is the first result
- list: array of search results
- name: name of the result
- location: general area where the result is situated
- province: province code where the result is found (numeric, e.g. 35, not 'ON')
- lonlat: co-ordinate where the result is located. array of [longitude, latitude]
- type: concise type code for the result
Parameters:
Returns:
promise of results
getConciseList
()
Array
private
Returns a list of concise names and codes for the UI dropdown combo
Returns:
a list of concise names and codes
getLayerConfig
-
layerId
Get a layer config for a given layer ID.
Parameters:
-
layerId
Stringa RAMP layer ID
Returns:
a RAMP config object from the layer registry
getProvCode
-
prov
Convert a provice name to province code
Parameters:
-
prov
Stringprovince string
Returns:
province code. undefined if no match
getProvList
()
Array
private
Returns a list of provinces and codes for the UI dropdown combo
Returns:
a list of province names and codes
init
()
Initializes properties. Set up event listeners
isInExtent
-
point
-
extent
Will determine if a point is inside an extent
Parameters:
Returns:
tells if the point is inside the extent
isLatLong
-
value
Will determine if a value is a valid number for a lat/long co-ordinate
Parameters:
-
value
Stringvalue to test
Returns:
tells if value is valid lat/long
isLatLong
()
private
Will initialize the module. Download provice keys & info. Download concise types keys & info.
isProvince
-
value
Will determine if a value is a valid province identifier (en/fr name or 2-letter abbr)
Parameters:
-
value
Stringvalue to test
Returns:
tells if value is valid province identifier
isValidHilight
-
layer
-
state
Determines if the layer has an active hilight for the highlight type (defined by the state).
Parameters:
Returns:
if layer has valid highlight
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
nextId
()
String
Get an auto-generated layer id. This works because javascript is single threaded: if this gets called from a web-worker at some point it will need to be synchronized.
Returns:
an auto-generated layer id
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
onLayerReload
-
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. This removes the layer from the entire app.
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.
parseInput
-
input
Will examine the user search string. Returns any special type and related data Valid types are: none, fsa, lonlat, prov
Parameters:
-
input
Stringuser search string
Returns:
result of parse. has .type (string) and .data (object) properties
removeFromMap
-
layerId
Will remove a layer from the map, along with any related items (bounding box, feature data) and adjust counts.
Parameters:
-
layerId
Stringconfig id of the layer
updateLayerSelectorState
-
layerId
-
newState
-
abortIfError
-
[options]
Will set a layerId's layer selector state to a new state.
Events
LayerLoader.LAYER_ADDED
Indicates that a map layer has been added to the layer selector. This means the LayerLoader has added a layer to the map.
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_REMOVED
Indicates that a map layer has been removed to the layer selector. This means the LayerLoader has removed a layer from the map. When a layer errors, it's removed from the map, but it might still be in the layer selector in the error state.
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