Class: MapAsset

MapAsset()

A MapAsset Model comprises information required to fetch source data for some asset or resource that is displayed in a map, such as imagery (raster) tiles, vector data, a 3D tileset, or a terrain model. This model also contains metadata about the source data, like an attribution and a description. It represents the most generic type of asset, and can be extended to support specific assets that are compatible with a given map widget.

Constructor

new MapAsset()

Since:
  • 2.18.0
Source:

Extends

  • Backbone.Model

Members

defaults :Object

Default attributes for MapAsset models
Type:
  • Object
Properties:
Name Type Attributes Default Description
type 'Cesium3DTileset' | 'BingMapsImageryProvider' | 'IonImageryProvider' | 'WebMapTileServiceImageryProvider' | 'TileMapServiceImageryProvider' | 'CesiumTerrainProvider' The format of the data. Must be one of the supported types.
label string A user friendly name for this asset, to be displayed in a map.
icon string <optional>
'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M1.2 13.7 3.6 3.5l7.2 8.7zM5 3.3c2 .3 3.5.4 4.4.4H13l3 6.3-4 1.8-7-8.5Zm9.1.6 2.8 6 4.5-2.2a23 23 0 0 1-.7-4c0-.8-1.2-.7-2-.7l-4.6.9ZM1 15l11-1.9c1.2-.3 2.7-1 4.2-2l2.5 5.2c-1.2.3-3.6.4-7.3.4-2.8 0-7.3 0-9.4-.8a2 2 0 0 1-1-.9Zm16.4-4.2 4-1.8 1.3 5.5c0 .4.1 1-.4 1.2l-2.5.5-2.4-5.4ZM1.7 17l-.5 2.6c0 .7.2 1 1 1.3a64.1 64.1 0 0 0 19.8 0c.4-.3 1-.5.7-1.6l-.5-2.3a52.6 52.6 0 0 1-20.6 0Z"/></svg>' A PID for an SVG saved as a dataObject, or an SVG string. The SVG will be used as an icon that will be displayed next to the label in the layers list. It should be an SVG file that has no fills, borders, or styles set on it (since the icon will be shaded dynamically by the maps CSS using a fill attribute). It must use a viewbox property rather than a height and width.
description string <optional>
'' A brief description about the asset, e.g. which area it covers, the resolution, etc.
attribution string <optional>
'' A credit or attribution to display along with this map resource.
moreInfoLink string <optional>
'' A link to show in a map where a user can find more information about this resource.
downloadLink string <optional>
'' A link to show in a map where a user can go to download the source data.
id string <optional>
'' If this asset's data is archived in a DataONE repository, the ID of the data package.
selected Boolean <optional>
false Set to true when this asset has been selected by the user in the layer list.
opacity Number <optional>
1 A number between 0 and 1 indicating the opacity of the layer on the map, with 0 representing fully transparent and 1 representing fully opaque. This applies to raster (imagery) and vector assets, not to terrain assets.
visible Boolean <optional>
true Set to true if the layer is visible on the map, false if it is hidden. This applies to raster (imagery) and vector assets, not to terrain assets.
colorPalette AssetColorPalette <optional>
The color or colors mapped to attributes of this asset. This applies to raster/imagery and vector assets. For imagery, the colorPalette will be used to create a legend. For vector assets (e.g. 3Dtilesets), it will also be used to style the features.
featureTemplate MapConfig#FeatureTemplate <optional>
Configuration for content and layout of the Feature Info panel - the panel that shows information about a selected feature from a vector asset (FeatureInfoView).
customProperties MapConfig#CustomProperties <optional>
Configuration that allows for the definition of custom feature properties, potentially based on other properties. For example, a custom property could be a formatted version of an existing date property.
notification MapConfig#Notification <optional>
A custom badge and message to display about the layer in the Layer list. For example, this could highlight the layer if it is new, give a warning if they layer is under development, etc.
status 'ready' | 'error' | null <optional>
null Set to 'ready' when the resource is loaded and ready to be rendered in a map view. Set to 'error' when the asset is not supported, or there was a problem requesting the resource.
statusDetails string <optional>
null Any further details about the status, especially when there was an error.
Source:

type :string

The name of this type of model
Type:
  • string
Source:

Methods

addCustomProperties(properties) → {Object}

Given a set of properties from a Feature from this Map Asset model, add any custom properties to the properties object and return it.
Parameters:
Name Type Description
properties Object A set of key-value pairs representing the existing properties of a feature from this asset.
Since:
  • 2.19.0
Source:
Returns:
The properties object with any custom properties added.
Type
Object

featureIsSelected(feature) → {boolean}

Given a feature object from a Feature model, checks if it is part of the selectedFeatures collection. See featureObject property from Feature#defaults.
Parameters:
Name Type Description
feature * An object that a Map widget uses to represent this feature in the map, e.g. a Cesium.Entity or a Cesium.Cesium3DTileFeature
Source:
Returns:
Returns true if the given feature is part of the selectedFeatures collection in this asset
Type
boolean

featureIsVisible(properties) → {boolean}

This function checks whether a feature from the MapAsset is visible on the map based on the properties of the feature and the MapAsset's filter settings.
Parameters:
Name Type Description
properties Object The properties of the feature to be filtered. (See the 'properties' attribute of Feature#defaults.)
Source:
Returns:
Returns true if the feature passes all the filters, or if there are no filters set for this MapAsset. Returns false if the feature fails any of the filters.
Type
boolean

fetchIcon(pid)

Fetches an SVG given a pid, sanitizes it, then updates the model's icon attribute with the new and SVG string (after sanitizing it)
Parameters:
Name Type Description
pid string
Source:

formatDateProperty(config, properties) → {string}

Given a definition for a new date property, and the properties that already exist on a specific feature, returns a new string with the formatted date.
Parameters:
Name Type Description
config MapConfig#CustomDateProperty An object that defines the new date property to create
properties Object key-value pairs representing existing properties in a Feature
Since:
  • 2.19.0
Source:
Returns:
The value for the new date property, formatted as defined by config, for the given feature
Type
string

formatStringProperty(config, properties) → {string}

For a given set of Feature properties and a definition for a new sting property, returns the value of the custom property. Note that since only static strings are supported so far, this function essentially just returns the value of config.value. This function exists to allow support of dynamic strings in the future (e.g. combining strings from existing properties)
Parameters:
Name Type Description
config MapConfig#CustomStringProperty The object the defines the new custom property
properties Object key-value pairs representing existing properties in a Feature
Since:
  • 2.19.0
Source:
Returns:
The new string for the given Feature property
Type
string

getColor(properties) → {AssetColor#Color}

Given properties of a Feature model from this MapAsset, returns the color associated with that feature.
Parameters:
Name Type Description
properties Object The properties of the feature to get the color for; An object containing key-value mapping of property names to properties. (See the 'properties' attribute of Feature#defaults.)
Source:
Returns:
The color associated with the given set of properties.
Type
AssetColor#Color

isSVG(str) → {Boolean}

Simple test to see if a string is an SVG
Parameters:
Name Type Description
str string The string to check
Source:
Returns:
Returns true if the string starts with ``, regardless of case
Type
Boolean

isVisible() → {boolean}

Checks that the visible attribute is set to true and that the opacity attribute is greater than zero. If both conditions are met, returns true.
Source:
Returns:
Returns true if the MapAsset has opacity > 0 and is visible.
Type
boolean

resetStatus()

Resets the Map Asset's status and statusDetails attributes to their default values.
Since:
  • X.X.X
Source:

sanitizeIcon(icon, callback)

Takes an SVG string and returns it with only the allowed tags and attributes
Parameters:
Name Type Description
icon string The SVG icon string to sanitize
callback function Function to call once the icon has been sanitized. Will pass the sanitized icon string.
Source:

show()

Make sure the layer is visible. Sets visibility to true if false, and sets opacity to 0.5 if it's less than 0.05.
Source:

updateIcon(icon)

Sanitizes an SVG string and updates the model's 'icon' attribute the sanitized string. Also sets the 'iconStatus' attribute to 'success'.
Parameters:
Name Type Description
icon string An SVG string to use for the MapAsset icon
Source:

whenReady() → {Promise}

Checks if the asset information has been fetched and is ready to use.
Source:
Returns:
Returns a promise that resolves to this model when ready.
Type
Promise