This namespace contains definitions of static functions for common tasks.
- Source:
- mapspace/util/util.jsdoc
Namespaces
Members
-
<static> randomColor
-
Returns a random color as string rgba(r,g,b). Maintains an internal value that ensure that new color returned is the best random color possible. We maintain a small cache of color strings. To provide cheap LRU-like semantics, whenever the cache grows too large we simply delete an arbitrary 25% of the entries. Based in: [How to create random colors] https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/ and also based in
ol.color.fromString
.- Source:
- mapspace/util/util.js
-
<static> uniqueNumber
-
Returns a unique number that be used to identify unique objects or events. Based in: [Generate unique number] http://qnimate.com/generate-unique-number-in-javascript/
- Source:
- mapspace/util/util.js
Methods
-
<static> a2b(a)
-
ATOB alternative (Base64 encoder/decoder)
Parameters:
Name Type Description a
string string to decode.
- Source:
- mapspace/util/util.js
Returns:
decoded string
- Type
- string
-
<static> addKartverketLayer(layers, index)
-
Adds a WMTS layer for Kartverket map provider to the collection of layers. If layer exists returns existing layer.
Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
index
number Index for the layer to be added.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Mapspace.layer.Tile
-
<static> addLayer(layers, layer, orderDef)
-
Adds a layer to a given collection but an array of types will be used to insert the layer before (below) the first layer that match any of those types.
Parameters:
Name Type Argument Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
layer
ol.layer.Base The layer to add.
orderDef
Mapspace.layer.OrderDefinition <nullable>
An optional array of layer types to use for the ordering. Each type must contain one
layerType
property with the type of layer and optionally can contain onesourceType
with the type of source. The layer will be ordered so it will be before (below) the first layer that is any of the types in the list.- Source:
- mapspace/util/util.js
-
<static> addOsmLayer(layers)
-
Adds an Open Street Maps layer to the collection of layers. If layer exists returns existing layer.
Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Mapspace.layer.Tile
-
<static> addTopowebbLayer(layers, index)
-
Adds a WMTS layer for Topowebb map provider to the collection of layers. If layer exists returns existing layer.
Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
index
number Index for the layer to be added.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Mapspace.layer.Tile
-
<static> anyItemHasValue(obj)
-
Checks if any key in object has a value or is an empty array.
Parameters:
Name Type Description obj
Object Object to check.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> anyMatchInArray(source, target)
-
Checks if any value in target array exists in source array.
Parameters:
Name Type Description source
Array Array to check.
target
Array Array with values to find in source.
- Source:
- mapspace/util/util.js
Returns:
True if any value found.
- Type
- boolean
-
<static> assignDefined(obj, other)
-
Return the same passed object but with values that are not undefined or null assigned.
Parameters:
Name Type Description obj
Object Object to change and return.
other
Object Object with values to assign.
- Source:
- mapspace/util/util.js
Returns:
The
obj
param is returned.- Type
- Object
-
<static> b2a(a)
-
BTOA alternative (Base64 encoder/decoder)
Parameters:
Name Type Description a
string string to encode.
- Source:
- mapspace/util/util.js
Returns:
encoded string
- Type
- string
-
<static> changeOverlays(overlays, className, visible)
-
Changes the visibility of the overlays inside the given collection that have elements that contain the given className.
Parameters:
Name Type Description overlays
ol.Collection.<ol.Overlay> The collection of overlays to modify.
className
string Only overlays with an HTML that have the given className will be modified.
visible
boolean If the overlays must be visible or not.
- Source:
- mapspace/util/util.js
-
<static> checkGeometryValidity(geom)
-
Checks if a given geometry is valid.
Parameters:
Name Type Description geom
ol.geom.Geometry Geometry.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> cloneGeometryTransf(geometry, transf)
-
Clones a geometry and transforms it using the provided transformation function.
Parameters:
Name Type Description geometry
ol.geom.Geometry The geometry to clone and transform.
transf
ol.TransformFunction The transformation function.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.geom.Geometry
-
<static> cloneStyle(style, viewType, removeImage)
-
Clones a style with some options.
Parameters:
Name Type Argument Description style
ol.style.Style Style.
viewType
Mapspace.ViewType Viewer type.
removeImage
boolean <nullable>
Optiona. If remove the image with point style. By default is false.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.style.Style
-
<static> copyToClipboard(elem)
-
Copy the content of the element to the Clipboard.
Parameters:
Name Type Argument Description elem
HTMLElement <nullable>
Element
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> createAddressOverlay(geocodingType, handler)
-
Creates and returns a new generic address overlay object.
Parameters:
Name Type Description geocodingType
Mapspace.GecodingType Type of geocoding action.
handler
function Handler when overlay is clicked.
- Source:
- mapspace/util/util.js
Returns:
A new overlay with no position.
- Type
- ol.Overlay
-
<static> createAnnotationOverlay(viewer, layer, feature)
-
Creates and returns a new generic annotation overlay object.
Parameters:
Name Type Description viewer
Mapspace.Viewer The viewer.
layer
Mapspace.layer.Vector The layer that stores de feature.
feature
ol.Feature The feature.
- Source:
- mapspace/util/util.js
Returns:
A new overlay with no position.
- Type
- ol.Overlay
-
<static> createDoubleArray(rows, cols)
-
Creates a new 2D array of the given dimensions.
Parameters:
Name Type Description rows
number The Y dimension.
cols
number The X dimension.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Array
-
<static> createFeatureInfoOverlay()
-
Creates and returns a new generic feature info overlay object.
- Source:
- mapspace/util/util.js
Returns:
A new overlay with no position and no content.
- Type
- ol.Overlay
-
<static> createLayerFromSourceDef(sourceDef, viewType, time)
-
Return a layer created from given source definition or null if no layer could be created.
Parameters:
Name Type Argument Description sourceDef
Mapspace.source.SourceDefinition The source definition.
viewType
Mapspace.ViewType <nullable>
Optional view type fo the viewer that the source is being for. By default is ORTHO.
time
string Optional time filter to apply in the source. The values supported are the same returned in
Mapspace.Viewer#getTime
.- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.layer.Base
-
<static> createLiDARLayer(project, detail, clippingPlanes)
-
Returns a
Mapspace.layer.Cesium3DTileset
from giving options.Parameters:
Name Type Argument Description project
Mapspace.LiDARProjectMetadata The LiDAR project metadata.
detail
number The maximum screen space error used to drive level of detail refinement.
clippingPlanes
Cesium.ClippingPlaneCollection <nullable>
Optional collection of clipping planes to be used to limit rendering. This are a temporary clipping planes that will be transformed to local LiDAR project coordinates when loading tileset metadata.
- Source:
- mapspace/util/util.js
Returns:
The layer created.
-
<static> createMeasurementOverlay(viewer, layer, feature)
-
Creates and returns a new generic measurement overlay object.
Parameters:
Name Type Description viewer
Mapspace.Viewer The viewer.
layer
Mapspace.layer.Vector The layer that stores de feature.
feature
ol.Feature The feature.
- Source:
- mapspace/util/util.js
Returns:
A new overlay with no position.
- Type
- ol.Overlay
-
<static> createOverlayLayer()
-
Returns a Mapspace overlay layer.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Mapspace.layer.Tile
-
<static> customizeDefaultWorkspace(workspaceOpt)
-
Gets a default workspace obtained from GetDefaultUserWorkspaces service and return a customized version of it, applying the user default location to coords and restricting viewers to only the allowed by user profiles.
Parameters:
Name Type Description workspaceOpt
Mapspace.WorkspaceOptions The default workspace definition.
- Source:
- mapspace/util/util.js
Returns:
-
<static> dataURItoBlob(dataURI)
-
Convert a Base64 image to binary.
Parameters:
Name Type Description dataURI
* - Source:
- mapspace/util/util.js
Returns:
- Type
- Blob
-
<static> dateToString(date, separator)
-
Converts from Date objecto to YYYYMMDD string format.
Parameters:
Name Type Description date
date Date to be converted to string. Must be a valid date object.
separator
string The separator to use in the values of the date.
- Source:
- mapspace/util/util.js
Returns:
Returns the date in string format.
- Type
- string
-
<static> decriptUserData(data)
-
Encript user data.
Parameters:
Name Type Description data
string Data.
- Source:
- mapspace/util/util.js
Returns:
Encripted string.
- Type
- string
-
<static> defaults(obj, defaultsObj)
-
Return object with default values if values do not exist.
Parameters:
Name Type Description obj
Object Object to set.
defaultsObj
Object Object with defaults.
- Source:
- mapspace/util/util.js
Returns:
Object with defaults if values not exist.
- Type
- Object
-
<static> encodeUrlXhr(url, data)
-
Encodes a URL.
Parameters:
Name Type Description url
string URL.
data
Object Object with params.
- Source:
- mapspace/util/util.js
Returns:
- Type
- string
-
<static> encriptUserData(user, pwd, newpwd)
-
Encript user data.
Parameters:
Name Type Description user
string User name.
pwd
string Password.
newpwd
string New password.
- Source:
- mapspace/util/util.js
Returns:
Encripted string.
- Type
- string
-
<static> encriptUserData2(user, pwd)
-
Encript user data.
Parameters:
Name Type Description user
string User name.
pwd
string Password.
- Source:
- mapspace/util/util.js
Returns:
Encripted string.
- Type
- string
-
<static> enforceLayer(layers, layerType, sourceType, sourceType2, enforce, ontop, options, conditionFunc)
-
Ensures that a layer (and only one) of the given type and with given source type is added on top of the collection of layers provided, and if not creates one with default options, returning it.
Parameters:
Name Type Argument Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
layerType
Object The layer type of the layer that should exist.
sourceType
Object The source type of the layer that should exist.
sourceType2
Object The source type of the layer that should not exist duplicated, usually it is a less restrictive type to ensure there is not duplication.
enforce
boolean If really enforce the existence of the layer or only ensure uniqueness (meaning the layer could exist or not, but if exist it exist only once).
ontop
boolean <nullable>
If we must ensure that the layer is on top or not. By default this is false, meaning that if the layer is found it is not changed in its position.
options
Object <nullable>
Non mandatory options for the new layer enforced.
conditionFunc
function <nullable>
An optional condition the layer and the source must comply with. Any function that receives a
ol.layer.Base
and returns a boolean.- Source:
- mapspace/util/util.js
Returns:
The layer enforced.
- Type
- ol.layer.Base
-
<static> enforceObliqueLayer(layers, enforce)
-
Ensure the oblique layer is added, is only once and it is at bottom. The
ol.Collection
passed is modified in place. Returns the oblique layer.Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers. This collection is modified.
enforce
boolean If really enforce the existence of the layer or only ensure uniqueness (meaning the layer could exist or not, but if exist it exist only once).
- Source:
- mapspace/util/util.js
Returns:
The oblique layer.
- Type
- Mapspace.layer.Tile
-
<static> enforceTileLayers(layers)
-
Ensures that any
ol.layer.Tile
is converted to aMapspace.layer.Tile
. This is needed to fix older layers that are not currently supported in viewers.Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> | Array.<ol.layer.Base> A collection or array of layers. Both arrays are modified in place with new instances for layers recreated.
- Source:
- mapspace/util/util.js
-
<static> enforceTileLayersInGlobal(layers, rotation, resolution)
-
Ensure any
Mapspace.layer.Tile
have source and also ensure thatMapspace.ortho.source.WMTS
non-overlay-sources have the correct options. This is needed to fix layers when adding to aMapspace.global.Viewer
. Theol.Collection
passed is modified in place.Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers. This collection is modified.
rotation
number The rotation to use in non-overlay-sources.
resolution
number The resolution to use in non-overlay-sources.
- Source:
- mapspace/util/util.js
-
<static> enforceVectorLayers(layers)
-
Ensures that any
ol.layer.Vector
is converted to aMapspace.layer.Vector
. This is needed to allow all selection functionality in all vector layers.Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> | Array.<ol.layer.Base> A collection or array of layers. Both arrays are modified in place with new instances for layers recreated.
- Source:
- mapspace/util/util.js
-
<static> ensureClosedGeometry(geometry)
-
Modifies a linestring geometry to ensure it is closed, that is the first and the last coordinate are the same.
Parameters:
Name Type Description geometry
ol.geom.LineString Geometry.
- Source:
- mapspace/util/util.js
-
<static> ensureEqualLastCoordinate(geometry)
-
Returns a new polygon geometry but ensuring that first point and last point of each linear ring are equals.
Parameters:
Name Type Description geometry
ol.geom.Polygon Polygon.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.geom.Polygon
-
<static> equalCoordinates(coord1, coord2)
-
Returns true if two coordinates are equal. A tolerance in the number of decimals is set through the global param Mapspace.COORDINATE_DECIMALS_TOLERANCE.
Parameters:
Name Type Description coord1
Mapspace.Coordinate First coordinate to compare.
coord2
Mapspace.Coordinate Second coordinate to compare.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> equalCoordinates3D(coord1, coord2)
-
Returns true if two 3D coordinates are equal. A tolerance in the number of decimals is set through the global param Mapspace.COORDINATE_DECIMALS_TOLERANCE.
Parameters:
Name Type Description coord1
Mapspace.Coordinate First coordinate to compare.
coord2
Mapspace.Coordinate Second coordinate to compare.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> equalResolutions(res1, res2)
-
Returns true if two resolutions are equal. A tolerance in the number of decimals is set through the global param Mapspace.RESOLUTION_DECIMALS_TOLERANCE.
Parameters:
Name Type Argument Description res1
number <nullable>
First resolution to compare.
res2
number <nullable>
Second resolution to compare.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> equalRotations(rot1, rot2)
-
Returns true if two rotations are equal. A tolerance in the number of decimals is set through the global param Mapspace.ROTATION_DECIMALS_TOLERANCE.
Parameters:
Name Type Argument Description rot1
number <nullable>
First rotation to compare.
rot2
number <nullable>
Second rotation to compare.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> equalsProfiles3d(p1, p2)
-
Returns true if two profile3d features are equal. A profile is one feature that contains these required observable properties:
name
: with the name of the profile.guid
: unique identifier for the profile.geometry
: the geometry of the profile.projects
: the array of LiDAR project names that must be loaded with the profile.
Parameters:
Name Type Argument Description p1
ol.Feature <nullable>
First profile feature to compare.
p2
ol.Feature <nullable>
Second profile feature to compare.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> equalTimestamps(t1, t2)
-
Returns true if two timestamp objects are equal. A timestamp is any object with a timestamp value (milliseconds passed from initial time) and with all the values (center, rotation, etc) that identify the state of a
Mapspace.Viewer
. It is important to ensure that both param timestamps have the same properties or result will be false.Parameters:
Name Type Description t1
Object Previous timestamp.
t2
Object Current timestamp.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> existsOverlay(overlays, className)
-
Returns true if the given collection contains any element with the given className.
Parameters:
Name Type Description overlays
ol.Collection.<ol.Overlay> The collection of overlays.
className
string Only overlays with an HTML that have the given className will be checked.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> extractProviders(serviceProviders)
-
Extract Map, Routing and Geocoding service providers.
Parameters:
Name Type Description serviceProviders
Array.<string> Array with service provider names.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Object
-
<static> findFeaturesByFilter(layer, filter, featFilter)
-
Returns an array of features that comply with the given filter.
Parameters:
Name Type Description layer
Mapspace.layer.Vector The vector layer to search. If layer is not vector layer, return empty array.
filter
Mapspace.Filter The filter to comply with.
featFilter
function | undefined An optional filter that limits the features in which execute search.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Array.<ol.Feature>
-
<static> findFeaturesByText(layer, text, featFilter)
-
Returns an array of features that has any of the words in text in any of the observable values in the feature. Values in observable properties are converted to string and compared as strings. If value is an Object or an Array, then each owned property of the object, or any item in the array, is used for search.
Parameters:
Name Type Description layer
Mapspace.layer.Vector The vector layer to search. If layer is not vector layer, return empty array.
text
string A string with words, separated by blank spaces. Words can be any text, including an alphanumeric string, a number, or true/false.
featFilter
function | undefined An optional filter that limits the features in which execute search.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Array.<ol.Feature>
-
<static> findLayerGroupOfLayer(layers, layer)
-
Finds the main
ol.layer.Group
to which the layer belongs (not a subgroup if layer belongs to a subgroup but the main group). If no layer inlayers
param is a layer group containing the layer returns null. The layer passed can be also a layer group.Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
layer
ol.layer.Base Layer to find.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.layer.Group
-
<static> findLayerRemovingDuplicates(layers, layerType, sourceType, conditionFunc)
-
Ensures that a
ol.Collection.<ol.layer.Base>
only has one layer that follows certain conditions, mantaining the first that comply with the conditions and removing the rest of them.This function is useful dealing with measurements and annotation layers, for example, that are special layers that only should appear once per viewer.
Parameters:
Name Type Argument Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
layerType
Object The layer type of the layer that should appear once.
sourceType
Object The source type of the layer that should appear once.
conditionFunc
function <nullable>
An optional condition the layer and the source must comply with. Any function that receives a
ol.layer.Base
and returns a boolean.- Source:
- mapspace/util/util.js
Returns:
Returns the first layer found that comply with the conditions or null if no layer was found.
- Type
- ol.layer.Base
-
<static> findLayers(layers, layerType, sourceType [, onlyFirst], conditionFunc)
-
Search inside a
ol.Collection.<ol.layer.Base>
with some filters and return the firstol.layer.Base
found or null (when param onlyFirst is true) or all the layers found in an array (when param onlyFirst is false).Parameters:
Name Type Argument Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
layerType
Object The layer type to search for.
sourceType
Object | null The source type to search for. Can be null when oblique viewer has no image.
onlyFirst
boolean <optional>
If return only first found or all found. By default the value is true.
conditionFunc
function | undefined An optional condition the layer and the source must comply with. Any function that receives a
ol.layer.Base
and returns a boolean.- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.layer.Base | Array.<ol.layer.Base>
-
<static> fixDates(strDate1, strDate2)
-
Fixes dates to a compact format if possible.
Parameters:
Name Type Description strDate1
string First date in string 'yyyy-mm-dd' format.
strDate2
string Second date in string 'yyyy-mm-dd' format.
- Source:
- mapspace/util/util.js
Returns:
The composed and fixed string.
- Type
- string
-
<static> fixFiltersInSelectInteraction(select, layerFilter, viewer)
-
Fixes a
ol.interaction.Select
interaction to use some filters for layers and for features to avoid selection of unwanted features. This fix is only needed for 2D viewers.Parameters:
Name Type Description select
ol.interaction.Select The select interaction.
layerFilter
function A filter for layers.
viewer
Mapspace.Viewer The viewer that will contain the features.
- Source:
- mapspace/util/util.js
-
<static> fixGeoJSONGeometry(geomObj)
-
Fixes in place the coordinates in a GeoJSON object with one geometry. Basically flattens the array of coordinates.
Parameters:
Name Type Description geomObj
Object GeoJSON object with a geometry.
- Source:
- mapspace/util/util.js
-
<static> fixLayerCrossOrigin(layer)
-
Fixes the
crossOrigin
property of the source of a layer for certain layers. This function modifies the passed layer, do not returns a new one. This function must be called before a layer is added to a viewer.Parameters:
Name Type Description layer
ol.layer.Base The layer to fix.
- Source:
- mapspace/util/util.js
-
<static> fixLayerInSelectInteraction(select)
-
Fixes a
ol.interaction.Select
interaction to use aMapspace.layer.Vector
instead of aol.layer.Vector
. This is needed to allow a select interaction to work in Global, Ortho & Oblique viewers.Parameters:
Name Type Description select
ol.interaction.Select The select interaction.
- Source:
- mapspace/util/util.js
-
<static> fixProject(project)
-
Returns the given project metadata object (Street, LiDAR or Mesh 3D project) fixing some values returned by Mapspace services. Triggers an error in case the object is malformed.
Parameters:
Name Type Description project
Mapspace.LiDARProjectMetadata | Mapspace.Mesh3DProjectMetadata | Mapspace.StreetProjectMetadata The project object.
- Source:
- mapspace/util/util.js
Returns:
-
<static> fixWorkspace(workspaceOpt)
-
Modifies the passed workspace options fixing some of them:
- Converts Ortho or Oblique viewers to Global
- Adds a Mapspace WMTS layer if Oblique viewer
Parameters:
Name Type Description workspaceOpt
Mapspace.WorkspaceOptions The workspace definition.
- Source:
- mapspace/util/util.js
Returns:
-
<static> formatDegreesToDMS(degree)
-
Returns a string with longitude or latitude formatted as DMS.
Parameters:
Name Type Description degree
number Lon or Lat degree.
- Source:
- mapspace/util/util.js
-
<static> generateSelectionStyleFunction(baseStyles)
-
Creates a Function that is both a
ol.StyleFunction
and aol.FeatureStyleFunction
to show features as selected.Parameters:
Name Type Description baseStyles
Array.<ol.style.Style> | ol.style.Style The styles to use as reference to generate the selection style.
- Source:
- mapspace/util/util.js
Returns:
- Type
- function
-
<static> getColorDefinitionForFeature(layer, feature)
-
Returns the color definition of the given feature.
Parameters:
Name Type Description layer
Mapspace.layer.Vector The layer that the feature belongs to.
feature
ol.Feature The feature.
- Source:
- mapspace/util/util.js
Returns:
-
<static> getColorDefinitionForLayer(layer)
-
Returns the color definition of the layer, if anyone found, or null.
Parameters:
Name Type Description layer
ol.layer.Layer Layer.
- Source:
- mapspace/util/util.js
Returns:
-
<static> getColorDefinitionForStyle(style)
-
Returns the color definition of the style.
Parameters:
Name Type Description style
ol.style.Style Style.
- Source:
- mapspace/util/util.js
Returns:
-
<static> getComputedSize(element)
-
Gets the computed size of the element using the computed style.
Parameters:
Name Type Description element
Element HTML element.
- Source:
- mapspace/util/util.js
Returns:
The pair of numbers with width and height.
- Type
- Array.<number>
-
<static> getCoordinateFromID(id)
-
Gets the lonlat coordinate of a Terratec image extracting it from the ID of the image. Terratec images follow the pattern: Xs000.000000n00.000000_YYMMDD where: X is a letter representing the type of image; s is '+' or '-', for positive or negative longitudes; 0 are digits for longitude and latitude; n is '_' (meaning positive) or '-' (meaning negative) latitude; _ is a separator; YYMMDD is a date.
Parameters:
Name Type Description id
string Image ID.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Mapspace.Coordinate
-
<static> getDaysInMonth(month, year)
-
Return the number of days of a given month.
Parameters:
Name Type Description month
number The month number 1-indexed so January is 1, February is 2, etc.
year
number The year.
- Source:
- mapspace/util/util.js
Returns:
Number of days of the month.
- Type
- number
-
<static> getDefaultDate(separator)
-
Returns current date as default date in
YYYY-MM-DD
format or with any other separator.Parameters:
Name Type Description separator
string The character or characters to use as separator. If not set then no separator is used and date is returned as
YYYYMMDD
. To obtainYYYY-MM-DD
use-
as separator.- Source:
- mapspace/util/util.js
Returns:
The date.
- Type
- string
-
<static> getDefaultDateAnTime(separator)
-
Returns current date as default date in
YYYY-MM-DD_HH-MM
format or with any other separator.Parameters:
Name Type Description separator
string The character or characters to use as separator. If not set then no separator is used and date is returned as
YYYYMMDD_HHMM
. To obtainYYYY-MM-DD_HH-MM
use-
as separator.- Source:
- mapspace/util/util.js
Returns:
The date.
- Type
- string
-
<static> getDefaultInteractionStyle(lineDash, solid, radius)
-
Returns the default
ol.style.Style
to show in drawing interactions. For multi-segment polygons and lines should use the lineDash param to give the user a visual clue with dashed lines that there is a need for a double click to end the drawing.Parameters:
Name Type Argument Description lineDash
Array.<number> | undefined An optional array of numbers to use as line dash.
solid
boolean <nullable>
An optional boolean. If true the colors used are solid. By default is false.
radius
number <nullable>
An optional size for the radius. By default is 5.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.style.Style
-
<static> getDefaultLayerIndex(layers, layer)
-
Returns the default layer index for a new layer.
Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
layer
ol.layer.Base A new layer to be added.
- Source:
- mapspace/util/util.js
Returns:
- Type
- number
-
<static> getDefaultSelectionStyle()
-
Returns the default
ol.style.Style
to show in selected features.- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.style.Style
-
<static> getDefaultStyleWithRandomColor(key, strokeColor, opacity)
-
Returns a default style with a random color.
Parameters:
Name Type Argument Description key
string Key value to reuse existing style in a cache of styles.
strokeColor
string <nullable>
Optional stroke color. If not passed then same color is used in fillColor and strokeColor.
opacity
number <nullable>
Optional opacity. If not passed then 1 is used for stroke and .42 is used for fill. If passed it is used for fill.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.style.Style
-
<static> getDefaultTime()
-
Returns the default time value. This value is a default value used in viewers to filter dates. For example, if current date is
2018/10/05
then the value returned is from 5 years to current date, and returns20131005-20181005
.- Source:
- mapspace/util/util.js
Returns:
The date.
- Type
- string
-
<static> getDomPath(element)
-
Returns the DOM path for the element
Parameters:
Name Type Description element
Element HTML element.
- Source:
- mapspace/util/util.js
Returns:
Array of elements with the path of the source element
- Type
- Array.<Element>
-
<static> getExtentFromWKT(wkt, source, target)
-
Returns the extent of the wkt geometry. Source and target projection are the projection systems to use to generate the extent.
Parameters:
Name Type Description wkt
string Source geometry to generate extent for.
source
string Source projection system.
target
string Target projection system.
- Source:
- mapspace/util/util.js
Returns:
The extent.
- Type
- Mapspace.Extent
-
<static> getFeatureFilterFunction(filter)
-
Returns a function from a given filter that can be used to filter features. The function returned has a feature as param and returns a boolean.
Parameters:
Name Type Description filter
Mapspace.Filter The filter to use.
- Source:
- mapspace/util/util.js
Returns:
- Type
- function
-
<static> getFileExtension(file)
-
Returns the extension of a file if it is able to find one.
Parameters:
Name Type Description file
File The file.
- Source:
- mapspace/util/util.js
Returns:
The extension or null. The extension is returned upper case.
- Type
- string
-
<static> getFormatReader(file)
-
Returns the correct
reader
for the file.Parameters:
Name Type Description file
File | string A file object or the extension of the file.
- Source:
- mapspace/util/util.js
Returns:
The correct format reader for the file or null if fail.
-
<static> getLayerExtent(layer)
-
Returns the extent of the layer in lonlat WGS84. If the layer has any kind of filter, it is used in the extent returned.
Parameters:
Name Type Description layer
ol.layer.Base The layer.
- Source:
- mapspace/util/util.js
Returns:
The extent or null if no extent was found.
- Type
- Mapspace.Extent
-
<static> getLayerFilterFunction(functionType, viewType)
-
Returns the layer filter for a given
Mapspace.LayerFilterFunctionType
. A layer filter is any function that receives a resolution and aol.layer.Layer
as params and returns a boolean. The function filters which layers will be searched for features.Parameters:
Name Type Description functionType
Mapspace.LayerFilterFunctionType The type of filter.
viewType
Mapspace.ViewType The type of viewer in which the filter function will be used. Some viewers have specific options for certain resolutions.
- Source:
- mapspace/util/util.js
Returns:
- Type
- function
-
<static> getLayerOrderIndex(layers, layer, orderDef)
-
Returns the best index to insert the given layer and comply with the given order definition. Returns -1 if it is not possible.
Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
layer
ol.layer.Base The layer.
orderDef
Mapspace.layer.OrderDefinition The array of layer types to use for the ordering. Each type must contain one
layerType
property with the type of layer and optionally can contain onesourceType
with the type of source. The layer will be ordered so it will be before (below) the first layer that has a lower index in the order definition.- Source:
- mapspace/util/util.js
-
<static> getLayerType(layer)
-
Returns the type of layer for the layer.
Parameters:
Name Type Description layer
ol.layer.Base The layer.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Mapspace.LayerType
-
<static> getModificationDate()
-
Returns the current date & time as a string in the format that som web services as for example NVDB must have in the metadata.
- Source:
- mapspace/util/util.js
Returns:
- Type
- string
-
<static> getNDC(clientX, clientY, target)
-
Gets Normalized Device Coordinates for a given Mouse or Touch event client coords and target.
Parameters:
Name Type Description clientX
Number X.
clientY
Number Y.
target
Element Expected to be a canvas element.
- Source:
- mapspace/util/util.js
Returns:
X and Y coordinates.
- Type
- Array.<Number>
-
<static> getNewLayerName(layerList)
-
Returns a unique layer name for a new layer to be added to the list.
Parameters:
Name Type Description layerList
ol.Collection.<ol.layer.Base> - Source:
- mapspace/util/util.js
Returns:
- Type
- string
-
<static> getOpacity(color)
-
Gets the opacity of any color. Opacity is returned as a float number between 0.0 to 1.0 with one decimal place. If no color is passed or no opacity exists then returns 1.0 by default.
Parameters:
Name Type Description color
ol.Color | ol.ColorLike | undefined Color.
number - Source:
- mapspace/util/util.js
-
<static> getOverlayElementToRender(overlay)
-
Returns the correct HTML element of an overlay to render. The element must exist, must be visible and have a non-zero size. Also the element must have a className with one of these values:
- Mapspace.css.CLASS_GEOCODING_PLACE
- Mapspace.css.CLASS_MEASUREMENT_TOOLTIP_STATIC
- Mapspace.css.CLASS_ANNOTATION_TOOLTIP_STATIC
- Mapspace.css.CLASS_FEATUREINFO_POPUP If not found then returns null.
Parameters:
Name Type Description overlay
ol.Overlay The overlay to render.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Element | null
-
<static> getOverlayPosition(overlay, viewportRect)
-
Returns a coordinate position in pixels [left, top] for an
ol.Overlay
object.Parameters:
Name Type Description overlay
ol.Overlay Overlay object.
viewportRect
DOMRect DOMRect of the viewport.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Mapspace.Coordinate
-
<static> getPointStyleFromStyle(style, fill, stroke, force, radius, radius_force)
-
Gets a new point style from a given style, fill and stroke. IMPORTANT: this function returns a scaled point style if input style is a
ol.style.RegularShape
to allow both circles and and other point icons of the same visual size. This function must not be called to obtain a style to be saved, only to obtain a style to be rendered.Parameters:
Name Type Argument Description style
ol.style.Style Style.
fill
ol.style.Fill Fill.
stroke
ol.style.Stroke Stroke.
force
boolean <nullable>
Optional. If return a default value when no point style exists in given style. By default is false.
radius
number <nullable>
Optional value to apply to radius in output style. By default is the radius in the given style.
radius_force
number <nullable>
Optional value to apply to radius in output style when no point style exists in given style. By default is 5.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.style.Circle | ol.style.RegularShape
-
<static> getPointStyleFromType(type, fill, stroke, radius)
-
Returns a
ol.style.Image
style from a point icon type.Parameters:
Name Type Description type
Mapspace.PointIconType The type of icon for the points.
fill
ol.style.Fill The fill for the style.
stroke
ol.style.Stroke The stroke for the style.
radius
number The radius for the style.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.style.Image
-
<static> getSerializableLayersArray(layers, excludedLayers)
-
Get the array of layers that are serializable.
Parameters:
Name Type Description layers
Array.<ol.layer.Base> Input layers.
excludedLayers
Array.<ol.layer.Base> Layers in this list will be excluded apart from usual excluded ones.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Array.<ol.layer.Base>
-
<static> getStreetTileURL(imageID, tileID, depthmap)
-
Returns the URL for a Street tile.
Parameters:
Name Type Description imageID
string ID of the Street image.
tileID
string Tile ID of the Street image. A f_z_y_x string.
depthmap
boolean If request the depthmap tile or the normal one.
- Source:
- mapspace/util/util.js
Returns:
- Type
- string
-
<static> getTextColor(color)
-
Gets a white or black color that is best for render text on top of given color.
Parameters:
Name Type Description color
ol.Color | ol.ColorLike Color.
- Source:
- mapspace/util/util.js
Returns:
Color in hexadecimal.
- Type
- string
-
<static> getTypeFromPointStyle(style)
-
Returns the point icon type from a
ol.style.Image
, the most aproximated to it or a default SQUARE if conversion failed.Parameters:
Name Type Description style
ol.style.Image The style.
- Source:
- mapspace/util/util.js
Returns:
-
<static> getVectorLayerStyle(layer)
-
Returns the main style settings of the vector layer, if anyone found, or null.
Parameters:
Name Type Description layer
Mapspace.layer.Vector Layer.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.style.Style
-
<static> getWMSLayers(wmsLayer, wmsServiceLayers, wmsAvailableCRS)
-
Checks the available layers & sublayers in a WMS
Parameters:
Name Type Description wmsLayer
Layer WMS Layer.
wmsServiceLayers
Array.<string> An array of vailable WMS Layer.
wmsAvailableCRS
string String with available CRS (EPSG code) from WMS service
- Source:
- mapspace/util/util.js
Returns:
WMS layer without childs
- Type
- Layer
-
<static> getWorldFileData(map)
-
Returns the data of the world file. Each value in the returned array is a line for the world file. The world file is a text file that contains the following content: Line 1: A: pixel size in the x-direction in map units/pixel Line 2: B: rotation about y-axis Line 3: C: rotation about x-axis Line 4: D: pixel size in the y-direction in map units Line 5: E: x-coordinate of the center of the upper left pixel Line 6: F: y-coordinate of the center of the upper left pixel
Parameters:
Name Type Description map
ol.Map The map object for which obtain the world file.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Array.<number>
-
<static> getXMLDoc(xml)
-
Returns the XMLDoc object from a XML text.
Parameters:
Name Type Description xml
string XML text
- Source:
- mapspace/util/util.js
Returns:
XMLDoc object.
- Type
- Object
-
<static> getZoomForResolution(resolution)
-
Return the zoom level for a pixel resolution.
Parameters:
Name Type Description resolution
number Pixel resolution to determine zoom leve.
- Source:
- mapspace/util/util.js
Returns:
Rounded zoom level.
- Type
- number
-
<static> hash(arguments)
-
Jenkins one-at-a-time hash Based in http://www.burtleburtle.net/bob/hash/doobs.html
Parameters:
Name Type Description arguments
Array.<number> An array of integers.
- Source:
- mapspace/util/util.js
Returns:
An integer.
- Type
- number
-
<static> hasNoDegreesCoordinates(geometry)
-
Checks if all coordinates in the geometry are suitable as degrees in
EPSG:4326
WGS84 projection or not. A coordinate is a degree if X is inside the [-360,360] range and if Y is inside the [-90,90] range. The Z value is ignored in the checking.Parameters:
Name Type Description geometry
ol.geom.Geometry The input geometry.
- Source:
- mapspace/util/util.js
Returns:
True if any coordinate is not a WGS84 degree.
- Type
- boolean
-
<static> hasNoZValues(geometry)
-
Checks if the geometry contains Z values. If no Z values exist returns true.
Parameters:
Name Type Description geometry
ol.geom.Geometry The input geometry.
- Source:
- mapspace/util/util.js
Returns:
True if has no Z values.
- Type
- boolean
-
<static> hasPermission(names, type)
-
Returns true if the current user has permission to use a feature.
Parameters:
Name Type Description names
Mapspace.AppFeaturesNames | Array.<Mapspace.AppFeaturesNames> One or several names of features to check. If several names are used the permission is granted if any is true.
type
Mapspace.AppFeaturesTypes | undefined Type of app feature. If undefined it is supposed to be a
Mapspace.AppFeaturesTypes.GENERIC
feature.- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> hasProfile(profiles)
-
Returns true if the current user has a given profile. Profiles give access to groups of functionality.
Parameters:
Name Type Description profiles
Mapspace.ProfileTypes | Array.<Mapspace.ProfileTypes> The profiles to check. If several profiles are used then returns true if the user has any of them.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> hasProfileForViewer(viewerDef)
-
Checks if the user has the needed profiles to see the given viewer.
Parameters:
Name Type Description viewerDef
Object The object with the definition for the viewer.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> hexToRgb(hex)
-
Returns a rgb value for hexadecimal color value.
Parameters:
Name Type Description hex
string Hexadecimal definition for a rgb color.
- Source:
- mapspace/util/util.js
Returns:
A JSON notation object with decimal values for R, G and B color channels.
- Type
- Object
-
<static> initializeCustomStyles(layers)
-
Set styles for features that have custom styles.
Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> | Mapspace.layer.Vector The collection of layers or only one vector layer.
- Source:
- mapspace/util/util.js
-
<static> interpolateColor(fr, fr1, color1, fr2, color2)
-
Interpolates a color between two colors.
Parameters:
Name Type Description fr
number Fraction.
fr1
number Lower fraction of color 1.
color1
ol.Color | ol.ColorLike Color 1.
fr2
number Upper fraction of color 2.
color2
ol.Color | ol.ColorLike Color 2.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.Color | ol.ColorLike
-
<static> invertColor(hex, bw)
-
Returns the inverted version of a color that has better contrast of top of it.
Parameters:
Name Type Description hex
string Color in hexadecimal format, as '#ffffff' or '#fff'.
bw
boolean Optional. If true color is snapped to best black or white color. By default is true.
- Source:
- mapspace/util/util.js
Returns:
Inverted color in hexadecimal.
- Type
- string
-
<static> is3DTilesetLayer(layer)
-
Returns if layer is a 3D tileset layer. These include any
Mapspace.layer.Cesium3DTileset
layer with aMapspace.source.LiDARCesium3DTileset
orMapspace.source.Mesh3DCesium3DTileset
source.Parameters:
Name Type Description layer
ol.layer.Base Layer to check.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isContainedInDistance(geometry, point, distance)
-
Returns if the given geometry (2D or 3D) is contained totally or partially inside an 3D extent defined by a point (in Mercator Spherical or any projection in meters) and a distance (defined in meters). Returns false if the geometry is completely far away from the given distance.
Parameters:
Name Type Description geometry
ol.geom.Geometry The geometry in Mercator Spherical projection or any other projection in meters. It can have 2D or 3D coordinates.
point
ol.geom.Point The point in the center of the 3D extent to check, in the same projection as geometry. It can have 2D or 3D coordinates.
distance
number The distance in meters.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isLayerInViewer(viewer, layer)
-
Returns if a given layer exists in a viewer. It searches inside layer groups.
Parameters:
Name Type Description viewer
Mapspace.Viewer Viewer.
layer
ol.layer.Base Layer.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isLayerOfType(layer, typeDef)
-
Returns true if layer is of type defined in the given definition.
Parameters:
Name Type Description layer
ol.layer.Base The layer.
typeDef
Mapspace.layer.TypeDefinition An object containing one
layerType
property with the type of layer and optionally can contain onesourceType
with the type of source.- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isMapspaceWFSLayer(layer)
-
Returns if layer is a WFS vector layer stored in Mapspace server.
Parameters:
Name Type Description layer
ol.layer.Base Layer.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isMobile()
-
Gets if current device and screen should be considered as mobile. This includes smartphones and tablets.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isOverlaysVisible(overlays, className)
-
Returns true if all overlays inside the given collection that have elements that contain the given className are visible.
Parameters:
Name Type Description overlays
ol.Collection.<ol.Overlay> The collection of overlays.
className
string Only overlays with an HTML that have the given className will be checked.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isProfile3dViewerPresent(workspaceDefinition)
-
It checks if a profile3d viewer is present in the workspace definition
Parameters:
Name Type Description workspaceDefinition
Mapspace.WorkspaceOptions The workspace definition.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isSmallSize()
-
Returns true if the current window browser size is smaller than minimum size. This size is by default 740px width and 540px height. If size is smaller than this the web app only can show the top menu (40px height) and one viewer or panel (FeaturePanel, Dashboard, etc.), but cannot show both a panel and a viewer.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isTileLayer(layer)
-
Returns if layer is a tile layer.
Tile layers include any
ol.layer.Tile
.Parameters:
Name Type Description layer
ol.layer.Base Layer to check.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isValidDate(date)
-
Determine if argument is a valid date
Parameters:
Name Type Description date
string Date to be analized.
- Source:
- mapspace/util/util.js
Returns:
Returns true is date is valid.
- Type
- boolean
-
<static> isValidExtent(extent)
-
Returns true if the extent is not empty and any of its values is not Infinity or -Infinity and not NaN.
Parameters:
Name Type Description extent
Mapspace.Extent The extent.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isValidUrlOld(p)
-
Checks if given param object is valid as old URL of the application.
Parameters:
Name Type Description p
Object Params object.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isVectorLayer(layer)
-
Returns if layer is a vector layer. Only these layers can have selected features, modified styles, modified attributes or can be exported to file.
Vector layers include any
Mapspace.layer.Vector
.Parameters:
Name Type Description layer
ol.layer.Layer Layer to check.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isWGS84ProjectionWKT(wkt)
-
Returns if the given WKT projection taken from a PRJ file is a WGS84 LonLat projection. Different GIS vendors provide alternate WKT for that projection so calling this function consider all them as equal.
Parameters:
Name Type Description wkt
string Projection WKT.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> isXMLTagName(tag)
-
Returns true if meets these conditions from XML standard:
- Element names are case-sensitive
- Element names must start with a letter or underscore
- Element names cannot start with the letters xml (or XML, or Xml, etc)
- Element names can contain letters, digits, hyphens, underscores, and periods
- Element names cannot contain spaces
Parameters:
Name Type Description tag
string Tag name.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> itemBetweenMaxMin(item, maxMin)
-
Checks if a given numeric item (a string with a number or a number) is between the min and max numbers in an array of numeric items.
Parameters:
Name Type Description item
string | number String with a number or number to check.
maxMin
Array.<string> | Array.<number> Array of numeric items.
- Source:
- mapspace/util/util.js
Returns:
- Type
- boolean
-
<static> jsonp(url, key, callback)
-
Executes a JSONP call and calls the callback. Based in Micro JSONP
Parameters:
Name Type Description url
string URL to execute.
key
string Name of the callback parameter.
callback
function The callback function where data will be accepted.
- Source:
- mapspace/util/util.js
-
<static> mergeDateFilters(viewerDateFilter, userLayerDateFilter)
-
Get join daterange from a set of two date.
Parameters:
Name Type Description viewerDateFilter
string Viewer time. Valid time values are any string like
*
,YYYYMMDD
,YYYYMMDD-*
orYYYYMMDD-YYYYMMDD
. Asterisk means that that maximum date is the maximum possible date (the latest date of current year).YYYYMMDD
filters images before the date, and the other patterns filter images between the dates. In the YYYYMMDD pattern both MM and DD can be omitted. If only one date is provided YYYYMM means the last day of given month and YYYY means last day of year. If two dates are provided the fisrt one means the first day of month or year and the second the last day. For example:-
- = 20231231 (if current year is 2023), 20241231 (if is 2024) and so on
- 2016 = 20161231
- 201611 = 20161130
- 2016-* = 20160101-20231231 (if current year is 2023) and so on
- 2016-2017 = 20160101-20171231
- 201605-2017 = 20160501-20171231
userLayerDateFilter
string userLayer date filter in string 'yyyymmdd' format.
- Source:
- mapspace/util/util.js
Returns:
The composed and fixed string.
- Type
- string
-
-
<static> numVisibleViewers(workspace)
-
Gets the current number of viewers that be visible
Parameters:
Name Type Description workspace
object Current workspace
- Source:
- mapspace/util/util.js
Returns:
- Type
- Number
-
<static> overwriteFeature(origin, target)
-
Modifies the target feature overwriting its values with values from origin. Values that are in target feature but not in origin will be removed with the exception of the Mapspace.STREET_GEOMETRY_NAME value, that contains a THREE.Object3D and must be maintained for later use to remove the object from the Street viewer scene. The overwrite is executed in silent mode to avoid feature events on each change except for Mapspace.GEOMETRY_NAME value that no silent mode is used to force Rtree update.
Parameters:
Name Type Description origin
ol.Feature Feature to use as origin of values.
target
ol.Feature Feature to use as target of values.
- Source:
- mapspace/util/util.js
-
<static> parseDate(dateStr, roundUp)
-
Tries to parse a Date using several common patterns used in this API and its web services. This function is not a full date parser and it is here to provide a better way to parse dates than the poor Date.parse of browsers. The function supports four date patterns:
DD/MM/YYYY HH:MM:SS
,DD/MM/YYYY
,YYYY/MM/DD HH:MM:SS
,YYYY/MM/DD
. The function checks against them and the first pattern that input date starts with is used. If none of the patterns pass the test then null is returned.Parameters:
Name Type Description dateStr
string The input string.
roundUp
boolean If the input string must be rounded up or down.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Date
-
<static> parseFileExtension(filename)
-
Returns the extension of a filename.
Parameters:
Name Type Description filename
string The file name.
- Source:
- mapspace/util/util.js
Returns:
The extension or null. The extension is returned upper case.
- Type
- string
-
<static> pixelRatio()
-
Returns the current pixel ratio of the viewport.
- Source:
- mapspace/util/util.js
Returns:
The pixel ratio from 0 to 1.
- Type
- number
-
<static> pointsToCoordinates(coordinates)
-
Get a plain array of numbers and transform them to a coordinates array.
Parameters:
Name Type Description coordinates
Array.<Number> Numbers array.
- Source:
- mapspace/util/util.js
Returns:
Coordinates array.
- Type
- Array.<Mapspace.Coordinates>
-
<static> removeKartverketLayer(layers)
-
Removes Kartverket layer from layer collection.
Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
- Source:
- mapspace/util/util.js
-
<static> removeLayers(layers, layerType, sourceType, conditionFunc)
-
Removes layers from a
ol.Collection.<ol.layer.Base>
that follows certain conditions.Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
layerType
Object The layer type of the layer to remove.
sourceType
Object The source type of the layer to remove.
conditionFunc
function | undefined An optional condition the layer and the source must comply with. Any function that receives a
ol.layer.Base
and returns a boolean.- Source:
- mapspace/util/util.js
-
<static> removeOsmLayer(layers)
-
Removes Open Street Maps layer from layer collection.
Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
- Source:
- mapspace/util/util.js
-
<static> removeOverlays(overlays, className)
-
Removes the overlays inside the given collection that have elements that contain the given className.
Parameters:
Name Type Description overlays
ol.Collection.<ol.Overlay> The collection of overlays to modify.
className
string Only overlays with an HTML that have the given className will be removed.
- Source:
- mapspace/util/util.js
-
<static> removeTopowebbLayer(layers)
-
Removes Topowebb layer from layer collection.
Parameters:
Name Type Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
- Source:
- mapspace/util/util.js
-
<static> reorderLayers(layers, orderDef)
-
Reorder a layer collection so layers are grouped by the given types.
Parameters:
Name Type Argument Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
orderDef
Mapspace.layer.OrderDefinition <nullable>
An optional array of layer types to use for the ordering. Each type must contain one
layerType
property with the type of layer and optionally can contain onesourceType
with the type of source. The layer will be ordered so it will be before (below) the first layer that is any of the types in the list.- Source:
- mapspace/util/util.js
Returns:
The same object reference passed in param layers is returned.
- Type
- ol.Collection.<ol.layer.Base>
-
<static> rgbToHex(r, g, b)
-
Returns a string with hexadecimal definition for a rgb color.
Parameters:
Name Type Description r
number Value from 0 to 255 of the R component.
g
number Value from 0 to 255 of the G component.
b
number Value from 0 to 255 of the B component.
- Source:
- mapspace/util/util.js
Returns:
String with hexadecimal definition for a rgb color.
- Type
- string
-
<static> setFillColor(style, color, overwriteOpacity)
-
Sets the fill color of a style.
Parameters:
Name Type Argument Description style
ol.style.Style Style.
color
ol.Color | ol.ColorLike Color.
overwriteOpacity
boolean <nullable>
If overwrite existing opacity. By default is true.
- Source:
- mapspace/util/util.js
-
<static> setStrokeColor(style, color, overwriteOpacity)
-
Sets the stroke color of a style.
Parameters:
Name Type Argument Description style
ol.style.Style Style.
color
ol.Color | ol.ColorLike Color.
overwriteOpacity
boolean <nullable>
If overwrite existing opacity. By default is true.
- Source:
- mapspace/util/util.js
-
<static> sort_unique(arr, unique)
-
Sort an array descently, removing duplicate elements.
Parameters:
Name Type Description arr
Array The array.
unique
boolean If remove duplications or not.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Array
-
<static> splitLineString(geometry, point, tolerance)
-
If point is close to the LineString split it in a pair of LineStrings. Split fails if point is close to first of last point.
Parameters:
Name Type Argument Description geometry
ol.geom.LineString Geometry to split.
point
Mapspace.Coordinate Point that is supposed to be in the line.
tolerance
number <nullable>
Optional tolerance as max distance. By default is 1.
- Source:
- mapspace/util/util.js
Returns:
Result of the split, or null if split failed.
-
<static> strformat(params)
-
Formats a string using the '{x}' pattern where x is a 0..n number. First argument must be the string to format, and the rest the values.
Parameters:
Name Type Argument Description params
string <repeatable>
Strings.
- Source:
- mapspace/util/util.js
-
<static> strwrap(text, max)
-
Wraps a string, introducing a carriage return after maximum chars.
Parameters:
Name Type Description text
string The string to wrap.
max
number The maximum number of chars to allow in each line.
- Source:
- mapspace/util/util.js
Returns:
The same text as input but with
\n
separating lines at blank spaces.- Type
- string
-
<static> subtractArrays(minuendo, minuendo)
-
Substract one array elements contents in other array.
Parameters:
Name Type Description minuendo
Array Source array.
minuendo
Array Substractable elements array.
- Source:
- mapspace/util/util.js
Returns:
Array with elements from minuendo array without sustraendo elements.
- Type
- Array
-
<static> to2DGeometry(geometry)
-
Returns a new fixed geometry, but removing Z and M values if they exist. This is here because the current lib for reading shapefiles,
shp.js
, has an issue reading polygons with holes that truncates Z values making them unusable.Parameters:
Name Type Description geometry
ol.geom.Geometry The input geometry.
- Source:
- mapspace/util/util.js
Returns:
The returned geometry never have Z or M values.
- Type
- ol.geom.Geometry
-
<static> to3DGeometry(geometry, z)
-
Returns a new fixed geometry with a given Z value if geometry has no Z, or the same geometry object but with a fixed Z if it has Zs.
Parameters:
Name Type Description geometry
ol.geom.Geometry The input geometry.
z
number The Z value to use to fix the input geometry.
- Source:
- mapspace/util/util.js
Returns:
The returned geometry always have Z values.
- Type
- ol.geom.Geometry
-
<static> toBuffer(b)
-
Converts an ArrayBuffer to Node.js Buffer object. This is a function copied here from shpjs for convenience.
Parameters:
Name Type Description b
ArrayBuffer ArrayBuffer.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Buffer
-
<static> toGeometryArray(geometry)
-
Returns an array of
ol.geom.SimpleGeometry
from the given geometry. If the passed geometry is one geometry, returns an array of one item; if is aol.geom.GeometryCollection
then passes an array with all contained geometries, converting them to SimpleGeometry recursively.Parameters:
Name Type Description geometry
ol.geom.Geometry The geometry.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Array.<ol.geom.SimpleGeometry>
-
<static> toGeometryCoordinates(geometry)
-
Returns an array of arrays of
Mapspace.Coordinate
from the given geometry. Each array corresponds to one geometry. If the geometry is only one SimpleGeometry then the array returned only has one array of coordinates. Coordinates are an inflate equivalent to flat coordinates in the geometry.Parameters:
Name Type Description geometry
ol.geom.SimpleGeometry A geometry.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Array.<Array.<Mapspace.Coordinate>>
-
<static> toGeometryLatLon(geometry, projection)
-
Returns a new geometry with coordinates in EPSG:4326 if projection is different or the same passed if not.
Parameters:
Name Type Description geometry
ol.geom.Geometry The geometry.
projection
ol.ProjectionLike The projection.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.geom.Geometry
-
<static> toGeometryWithoutHoles(geometry)
-
Returns a new geometry without holes in case Polygon or return the same otherwise.
Parameters:
Name Type Description geometry
ol.geom.Geometry Geometry.
- Source:
- mapspace/util/util.js
Returns:
- Type
- ol.geom.Geometry
-
<static> toHTMLDateValues(time)
-
Returns the current time value as a pair of values [minDate,maxDate]. Time value follows the pattern required for observable TIME property of viewers. Result values are nullable ones that follow HTML5 date input values.
Parameters:
Name Type Argument Description time
string <nullable>
The time value or null. Valid time values are any string like
*
,YYYYMMDD
,YYYYMMDD-*
orYYYYMMDD-YYYYMMDD
. Asterisk means that that maximum date is the maximum possible date (the latest date of current year).YYYYMMDD
filters images before the date, and the other patterns filter images between the dates. In the YYYYMMDD pattern both MM and DD can be omitted. If only one date is provided YYYYMM means the last day of given month and YYYY means last day of year. If two dates are provided the fisrt one means the first day of month or year and the second the last day. For example:-
- = 20231231 (if current year is 2023), 20241231 (if is 2024) and so on
- 2016 = 20161231
- 201611 = 20161130
- 2016-* = 20160101-20231231 (if current year is 2023) and so on
- 2016-2017 = 20160101-20171231
- 201605-2017 = 20160501-20171231
- Source:
- mapspace/util/util.js
Returns:
An object with three values: minDate and maxDate with a pair of dates in
YYYY-MM-DD
pattern used by HTML5 input or null if date is not set, and isDynamic with boolean that indicates if maxDate is the maximum possible date. If the input value is not correct then returns null.- Type
- Object
-
-
<static> toInteriorCoordinate(geometry)
-
Returns an interior coordinate for the given geometry.
Parameters:
Name Type Description geometry
ol.geom.Geometry Geometry.
- Source:
- mapspace/util/util.js
Returns:
- Type
- Mapspace.Coordinate
-
<static> toQueryString(obj)
-
Creates a URL query string.
Parameters:
Name Type Description obj
Object Object with params.
- Source:
- mapspace/util/util.js
Returns:
- Type
- string
-
<static> toSimplifiedGeometryArray(geometry, opt_array)
-
Returns an array of simplified geometries. The returned array only contains
ol.geom.Point
,ol.geom.LineString
andol.geom.LinearRing
. Any Geometry collection of geometry that is the composition of several geometries, as Multipoint, etc., are reduced to single elements recursively. Polygons are returned only as exterior linear rings.Parameters:
Name Type Argument Description geometry
ol.geom.Geometry The input geometry.
opt_array
Array.<ol.geom.Geometry> <nullable>
The optional array where add the geoemtries. If not provided a new is returned.
- Source:
- mapspace/util/util.js
Returns:
Returned array.
- Type
- Array.<ol.geom.Geometry>
-
<static> toTimeValues(time)
-
Returns the current time value as a pair of values [minDate,maxDate]. If time value has pattern
YYYYMMDD
then minDate = -Infinity and maxDate a number with 8 digits followingYYYYMMDD
pattern. If time value has patternYYYYMMDD-YYYYMMDD
then minDate and maxDate are numbers with 8 digits followingYYYYMMDD
pattern. If time value is not valid pattern then null is returned.Parameters:
Name Type Description time
string The time value.
- Source:
- mapspace/util/util.js
Returns:
The time as a pair of values.
- Type
- Array.<number>
-
<static> urlParser(userToken)
-
Gets the URL parameters.
Parameters:
Name Type Description userToken
string | null The usertoken to be used.
- Source:
- mapspace/util/util.js
Returns:
Object with a parameters and its values.
Parameters allowed as input in the URL are:
-
usertoken - (string) User token. This value is mandatory and if it do not exist then the error property will notify it.
-
workspace - (string) The workspace to be loaded. This is mandatory. If not present then the error property will notify it.
-
x - (number) First coordinate for location. If 'srs' or 'srid' param exists then this coordinate is expected in the projection set there, and if not then is expected to be in 'EPSG:3857'.
-
y - (number) Second coordinate for location. If 'srs' or 'srid' param exists then this coordinate is expected in the projection set there, and if not then is expected to be in 'EPSG:3857'.
-
srs - (string) Projection for the x, y coordinates and projection for the output of the viewers. This is an optional param and if not present then x, y values will be expected as 'EPSG:3857', and a 'EPSG:3857' will be used as projection for the output of the viewers. The string must use the pattern 'EPSG:xxx' where xxx is a valid EPSG ID for the projection.
-
srid - (string) This is the same param as srs, so can be used either one or another. If both present srs takes precedence.
-
orientation - (string) [N, S, W, E] Orientation for a oblique image. This parameter will have effect only in a workspace with one 2D viewer. If both orientation and rotation are used then the error property will notify it.
-
rotation - (number) The initial rotation of the view in decimal degrees, where 0 means looking north, 90 looking west and so on. The range of values is [0, 360). This is an optional value and defaults to zero. If both orientation and rotation are used then the error property will notify it.
-
zoom - (number) Optional zoom level, from 1 (min) to 6 (max). If value is outside then the error property will notify it. This param is convertes to a correct resolution.
-
viewers - (string) Optional string with a list of indexes separated by commas (starting at 1) of visible viewers of the workspace. For example,
1,3
will only show the first and third viewer available in the workspace. If the number of available viewers is below the index, that index will be ignored. -
viewmode - (string) [map, oblique] Optional. Opens a Map & Oblique viewer in an ortho or oblique mode.
-
pin - (boolean) [true, false] Optional. Adds a pin icon in the location.
If current URL params has errors then the error property will store all errors.
If lon, lat params exist they will be converted to x, y and srs='EPSG:4326'.
If view not exists but id exists then view will be infered.
If srs do not exist but srid exist then srs will use that value and srid will be removed. If both exist srid will be removed.
Final parameters in the output are defined in
Mapspace.URLParams
.- Type
- Mapspace.URLParams | undefined