@mappr/client-api

0.6.0

Client

The main entry point for all other API elements

new Client(options: Object)

Extends WithLang, WithDumpRestore, Base

Parameters
options (Object) configuration object
Name Description
options.projectId String unique id of the project
options.dao Object optional Data Access Object providing all DAOs for managed classes (IconSet, DataSets, Dictionaries, MediaSets); if this parameter defined then it is used to build instead of default ClientDao
options.uri String URI of the GraphQL endpoint; this parameter is used only if the options.dao parameter is not defined
options.credentials (Object | String) client credentials; used only if the options.dao is not defined
options.hoverTimeout Integer timeout used to cancel hovered elements
options.enableHoverSelected Boolean enables hovering effects for already selected features; by default false
Instance Members
dataSets
dataSetGroup
iconSets
mediaSets
dicts
dao
daoProps
_newClientDao()
projectId
credentials
destroy()
setLang(lang)
newDataSet(options)
getDataSet(dataSetId)
deleteDataSet(dataSetId)
newIconSet(options)
getIconSet(iconSetId)
deleteIconSet(iconSetId)
newMediaSet(options)
getMediaSet(mediaSetId)
deleteMediaSet(mediaSetId)
newDictionary(options)
getDictionary(dictionaryId)
deleteDictionary(dictionaryId)
resolveUrl(path)
dump(obj)
restore(obj)

mappr.api

The global namespace for this package.

mappr.api

DataSets

Classes defining main functionality of DataSets (like search, results loading, query building, autocompletion, statistics loading etc)

DataSets

Classes defining main functionality of DataSets (like search, results loading, query building, autocompletion, statistics loading etc)

DataSet

This class is main entry point to work with Data Sets. It manages search queries, statistics for search results, loaded search results and currently selected items.

new DataSet(options: Object)

Extends WithFields, WithReload, WithDao, Base

Parameters
options (Object) configuration object
Name Description
options.dataSetId String unique identifier of this DataSet
options.enabled Boolean this flag shows if this DataSet is enabled
options.dao Object mandatory Data Access Object providing required methods to load data
Example
// Create a new DataSet instance. Note that the Data Access Object (the "dao"
// field) provides all required methods to call the server.
const dataSet = new DataSet({
  dao : new DataSetDao({ ... }),
  daoProps : { projectId: 'myproject' },
  lang : 'fr',
  fields : { guid : 'guid', name : 'properties.name', city : 'properties....'}
})
// Launch the search request
const data = await dataSet.request
  // Set the language to "fr"
  .setLang('fr')
  // We want to search by the "3d" keyword in the "q" index.
  // Currently applyed language is "fr", so the query will be bulid for the
  // "q__fr" index.
  .addFulltext('q', '3d');
  // Add also filtering by enumerated fields: we want to search only in
  // companies.
  .addFilter('type', 'company');
  // Suggest full-text terms for the text mask "eng"
  // (like "engine", "engineer"...).
  .addMask('q', 'eng');

// Now we can explore the results of the search operation:
console.log('Results: ', data);

// The same values are available using individual DataSet fields:
```
* dataSet.stats (SearchResultsStats) - contains information about
  all results matching to the applied search criteria
* dataSet.results (SearchResults) - contains paginated search results
  visible in the currently applied geographical bounding box.
  It has the following useful fields: items, pageIdx, pageNumber, etc
* dataSet.selected (SelectedItem) - contains information about the currently
  selected item:
  - guid: ID of the selected item
  - item: the selected object itself; this field is null if the selected
    item do not match the applied search criteria
  - position: absolute position of the selected item in the results list (
    it takes into account the currently applied orders)
* dataSet.suggestions (Suggestions) - contains suggestions for
  text tokens; it is used to get correct tokens for full-text searches.
  The returned suggestions are contained in items matching to the currently
  applied search criteria
* dataSet.filters (FilterStats) - contains statistics about filter terms
  with the corresponding number of matching results
```
Instance Members
stats
results
selected
suggestions
mapTiles
filters
promise
daoProps
data
request
load(options)
dataSetId
enabled
setEnabled(enabled)

SearchResults

This class manages paginated search results. It loads subset of items matching to the currently applied search criteria using the specified page index, page size and orderBy parameter.

new SearchResults(options: Object)

Extends WithOrderBy, SearchResultsStats

Parameters
options (Object) configuration object
Name Description
options.dao Object mandatory Data Access Object providing required methods to load data
options.dao.loadResultsStats Function mandatory function loading stats about results matching to the query and bounding box
options.dao.loadResults Function mandatory function loading the specified sub-set of items corresponding to the query within the specified bounding box
options.pageSize Number size of the result pages (number of items loaded at once)
Instance Members
daoMethods
daoProps
items
offset
limit
pageNumber
pageIdx
setPageIdx(pageIdx)
pageSize
setPageSize(pageSize)
selectPageInPosition(position, force)
load(options)
data

SearchResultsStats

This class manages statistics for DataSet search results

new SearchResultsStats(options: Object)

Extends WithSearchQueryAndBbox, WithDao, WithReload, Base

Parameters
options (Object) configuration object
Name Description
options.dao Object mandatory Data Access Object providing required methods to load data
options.dao.loadResultsStats Function mandatory function loading stats
Instance Members
daoMethods
daoProps
load(options)
count
bbox
data

SelectedItem

This class manages selected items and their loading

new SelectedItem(options: Object)

Extends WithSearchQueryAndBbox, WithOrderBy, WithDao, WithReload, Base

Parameters
options (Object) configuration object
Name Description
options.dao Object mandatory Data Access Object providing required methods to load data
options.dao.loadSelectedItem Function mandatory function loading selected items
Instance Members
daoMethods
daoProps
guid
_setGuid(value)
setGuid(guid, origin)
origin
item
position
load(options)
_reload()
data

MapTiles

This class manages information related to Vector Tiles for a specific DataSet (like tilesUrls).

new MapTiles(options: Object)

Extends WithSearchQuery, WithFields, WithDao, WithReload, Base

Parameters
options (Object) configuration object
Name Description
options.cluster Boolean optional flag defining if points should be clustered in the returned vector tiles
options.lang String mandatory language; used to define vector tile properties
options.fields Object mandatory fields mapping; used to define vector tile properties
options.dao Object mandatory Data Access Object providing required methods to load data
options.dao.loadTilesUrl Function mandatory function loading MapTiles
options.dao.loadClusterInfo Function mandatory function loading information about the currently selected clusters
Instance Members
daoMethods
daoProps
setSearchQuery(query, force)
cluster
setCluster(cluster)
tilesUrl
toMapFeature(feature)
load(options, cluster, selectedCluster)
clusterId
clusterInfo
clusterChildren
selectCluster(cluster)
data

Suggestions

This class manages full-text token suggestions matching to the specified queries and suggestion masks

new Suggestions(options: Object)

Extends WithSuggestionMasks, WithSearchQuery, WithReload, WithDao, Base

Parameters
options (Object) configuration object
Name Description
options.dao Object mandatory Data Access Object providing required methods to load data
options.dao.loadSuggestions Function mandatory function loading suggestions
Instance Members
daoMethods
daoProps
loadSuggestions(masks, force)
setSearchQuery(query, force, masks)
tokens
load(options)
data

SuggestionMasks

SuggestionMasks is an object containing field names with the corresponding text masks.

SuggestionMasks

Type: Object

SearchQuery

SearchQuery is defined as an array of operations.

SearchQuery

Type: Array

Bbox

Bounding box is an array of [south, west, north, east] geographical coordinates.

Bbox

Type: Array

Static Members
DEFAULT_BBOX

DataSetGroup

This class synchronizes interactions between DataSets. It allows to have just one hovered / selected feature between DataSets from the same group. To set a feature hovered on the map the DataSetGroup#setHovered method should be used. Hovered features from lists should be defined using the DataSetGroup#setFullHovered method - this method selects only some property fields and transforms the initial object to the same format as data coming from map vector tiles. To manage selected features the DataSetGroup#setSelected method should be used.

new DataSetGroup(options: Object)

Extends Base

Parameters
options (Object) configuration object
Name Description
options.keyPrefix String prefix used to generate unique feature keys
options.enableHoverSelected Boolean enables hovering effects for already selected features; by default false
options.hoverTimeout Integer timeout defining how long hover effects (like popup or style changes) should last when the mouse moved out of a layer feature
Instance Members
hoverTimeout
enableHoverSelected
hovered
cancelHovering(immediate)
selected
setSelection(dataSetId, feature, GeoJSON)
clearSelection()
getDataSet(dataSetId)
addDataSet(dataSet)
removeDataSet(dataSetId)
_getFeatureKey(dataSetId, feature)
_isCluster(feature)
_getFeatureGuid(feature)
_getClusterId(feature)

FilterStats

This class manages statistics for DataSet filters. The results represents filter keys with the corresponding number of features matching to these fiters.

new FilterStats(options: Object)

Extends WithSearchQuery, WithDao, WithReload, Base

Parameters
options (Object) configuration object
Name Description
options.dao Object mandatory Data Access Object providing required methods to load data
options.dao.loadIndexes Function mandatory function loading list of all indexes
options.dao.loadFitersStats Function mandatory function loading stats about filters (about terms used in simple indexes)
Instance Members
daoMethods
daoProps
filterNames
filterStats
getStats(filterName)
load(options)
data

DataSet Mixins

DataSet Mixins

Mixin

Mixins are functions extending the provided type and returning a new class with additional methods and fields.

Mixin(Type: (Base | Function)): Base

Type: Function

Parameters
Type ((Base | Function)) the parent type to subclass; the resulting class extends this type and inject additional methods and fields
Returns
Base: a new class extending the specified type with additional methods and fields
Example
// Mixin definition:
function HelloMixin(Type = class{}) {
  return class extends Type {
    sayHello(name) {
      console.log(`Hello '${name}'!`);
    }
  }
}

// Mixin usage

// Define the first type using this mixin: simple use case without explicit parents.
class FirstTypeWithHello extends HelloMixin() {
 ...
}

class ParentBase { ... }
// Second type using this mixin. This class extends the `ParentBase` and
// inject additional methods provided by the `HelloMixin`.
class SecondTypeWithHello extends HelloMixin(ParentBase) {
 ...
}

// Here both types, the `FirstTypeWithHello` and `SecondTypeWithHello`
// have their own `sayHello(name)` methods:
const a = new FirstTypeWithHello();
const b = new SecondTypeWithHello();
a.sayHello('A'); // prints "Hello 'A'!"
b.sayHello('B'); // prints "Hello 'B'!"

WithDao

This mixin adds usage of Data Access Object (DAO) to the underlying types.

WithDao

Type: Mixin

Parameters
options (Object) configuration object
Name Description
options.dao Object mandatory Data Access Object providing required methods to load data
Instance Members
daoMethods
dao
daoProps

WithFields

This mixin provides access to object fields taking into account the currently applied language. It gives a simplified "view" of objects.

WithFields

Type: Mixin

Extends WithLang

Parameters
options (Object) configuration object
Name Description
options.fields Object contains mapping between new (simplified) field names and their original pathes
options.lang String currently applied language; it will be used as the default language
Example
```
 const FieldsSelector = WithFields(class {})
 const selector = new FieldsSelector({
   lang : "fr",
   fields : {
     "name" : "properties.name", // the "properties.name" is mapped to "name"
     "city" : "properties.address.city"
   }
 });
 const object = {
   'guid':  "...",
   'properties' : {
     ...
     'address' : {
       'city::fr' : 'Londres',
       'city::en' : 'London'
     }
     'name::fr' : 'Foo Bar (French Name)',
     'name' : 'Foo Bar (Default Name)',
   }
 };
 let result = selector.selectFields(object);
```

For the currently applied language ("fr") the resulting object would be:
 `{ 'city' : 'Londres', 'name' : 'Foo Bar (French Name)' }`

To get the english version of the simplified object:
```
 selector._setLang('en');
 result = selector.selectFields(object);
```
The resulting object is:
```{ 'city' : 'London', 'name' : 'Foo Bar (Default Name)' }```
Note that the 'name' field contains the default name because there is no
english-specic version of this field in the original object.
Instance Members
fields
_setFields(fields)

WithLang

This mixin defines language-specific fields for the main class.

WithLang

Type: Mixin

Parameters
options (Object) configuration object
Name Description
options.lang String currently applied language; it will be used as the default language
Example
```
 const MyType = WithLang(class {})
 const obj = new MyType({ lang : "fr" });
 assert(obj.lang, 'fr');
 assert(obj.defaultLang, 'fr');
```
Instance Members
defaultLang
lang
selectFields(object, fields)
selectField(object, field)
_setLang(value)

WithOrderBy

This mixin defines fields used to order search results

WithOrderBy

Type: Mixin

Parameters
options (Object) configuration object
Name Description
options.orderBy String currently applied order
Instance Members
orderBy
orderByWithLanguage
_setOrderBy(value)

WithSearchQueryAndBbox

This mixin manages geographical bounding boxes.

WithSearchQueryAndBbox

Type: Mixin

Extends WithSearchQuery

Instance Members
queryBbox
_setQueryBbox(bbox)

WithSearchQuery

This mixin provides access to search queries fields.

WithSearchQuery

Type: Mixin

Instance Members
query
_setQuery(query)

WithSuggestionMasks

This mixin provides access to suggestion masks.

WithSuggestionMasks

Type: Mixin

Instance Members
masks
_setSuggestionMasks(value)

DataSet Utilities

DataSet Utilities

DataSetEvents

Contains keys of events used by DataSet-related classes.

DataSetEvents
Events
EV_UPDATE_REQUEST
EV_APPLY_REQUEST
EV_ENABLE
EV_DESTROY
EV_LOAD
EV_LOAD_STATS
EV_LOAD_SELECTED_ITEM
EV_LOAD_SUGGESTIONS
EV_LOAD_MAP_TILES
EV_LOAD_CLUSTER_INFO
EV_LOAD_RESULTS
EV_GROUP_ADD_DATASET
EV_GROUP_REMOVE_DATASET
EV_GROUP_HOVER
EV_GROUP_SELECTED

DataSetRequest

This is an utility class containing methods for building various search criteria such as query, geographical bounding boxes used to filter search results and for fulltext suggestion masks.

  • fulltext: fulltext index names with the currently applied query tokens;
  • filters: basic index names with applied values
  • lang: currently applied language; this language is used to build names of full-text indexes in queries and for suggestion masks
  • masks: contains names of logical fulltext indexes with the corresponding tokens used to return suggestions

The fulltext and filters fields are used to build the query in the resulting request. Full-text search requests are produced for language-specific indexes. To deduce the full name of a full-text index the basic index name is combined with the currently applied language. For example for the index q and the language fr the real complete index name is q__fr. So if we have the full text search criteria { q : ['dev'] } and the current language is fr then the build search query is ['match', 'q__fr', 'dev'].

new DataSetRequest(options: Object)

Extends WithDumpRestore, Base

Parameters
options (Object) configuration object
Name Description
options.fulltext Object names of full text indexes with associated search tokens
options.filters Object names filter indexes with associated values used to search results
options.masks Object currently applied suggestions masks; keys correspond to index names and values are lists of tokens; these tokens are used to return suggestions
options.bbox Bbox currently geographical bounding box; this value is used to get features only from this geographical area
options.lang String currently applied language; this value is used to re-define exact name of indexes
options.pageSize String size of result pages
options.pageIdx String current result page
options.orderBy Array<String> ordering fields
options.selectedGuid String GUID of the item to select
Example
```
 options = {
   textIndexes : ['q', 'tags'], // Name of full-text indexes used in the DataSet
   fulltext : { q : ['artificial', 'intelligence'] },
   filters : { type : ['laboratory'] },
   masks : { q : ['dev'] },  // Used to produce suggestions for these tokens
   lang : 'fr',
   orderBy: ['properties.title'],
   pageSize : 10,
   pageIdx : 1,
 }
```
 will generate the following request object:
```
{
  query : ['all',
    ['match', 'q__fr', 'artificial', 'intelligence'],
    ['match', 'type', 'laboratory'],
  ],
  masks : {
    'q__fr' : ['dev']
  },
  lang : 'fr'
}
```
Instance Members
apply(options)
doApply
then(resolve, reject)
catch(onError)
orderBy
setOrderBy(value)
pageIdx
setPageIdx(value)
pageSize
setPageSize(value)
lang
setLang(value)
textIndexes
bbox
setBbox(bbox)
selectedGuid
setSelectedGuid(guid)
clearSelectedGuid()
toJson()
request
filters
setFilters(indexKey, values)
addFilters(indexKey, values)
toggleFilters(indexKey, values)
masks
setMask(indexKey, values)
addMask(indexKey, values)
toggleMask(indexKey, values)
fulltext
setFulltext(indexKey, values)
addFulltext(indexKey, values)
toggleFulltext(indexKey, values)
clone()
dump(obj)
restore(obj)

IconSets

Icons management

IconSets

Icons management

IconSet

Icons, glyphs and css class management.

new IconSet(options: Object)

Extends Base

Parameters
options (Object) configuration object
Name Description
options.iconSetId String unique identifier of this IconSet
options.dao Object mandatory Data Access Object providing required methods to load data
options.dao.loadIconSet Function mandatory function loading translation messages
Instance Members
dao
daoProps
iconSetId
info
glyphs
css
getIconInfo(iconName)
getIconChar(iconName)
glyphFontName
reload()

IconSetEvents

Contains keys of events used by IconSet-related classes.

IconSetEvents
Events
EV_DESTROY
EV_LOAD_ICONSET

MediaSets

Media management

MediaSets

Media management

MediaSet

Manages various media items and associated metadata

new MediaSet(options: Object)

Extends Base

Parameters
options (Object) configuration object
Name Description
options.mediaSetId String unique identifier of this MediaSet
options.dao Object mandatory Data Access Object providing required methods to load data
options.dao.loadMediaSet Function mandatory function loading translation messages
Instance Members
dao
daoProps
mediaSetId
info
reload()
resolutions
types
getResolution(type)
loadMedias(key, type)
_loadMediasByKey(key)
_buildPathRegexp(prefix, delimiter)

MediaSetEvents

Contains keys of events used by MediaSet-related classes.

MediaSetEvents
Events
EV_DESTROY
EV_LOAD

Dictionaries

Management of enumerted values (dictionaries)

Dictionaries

Management of enumerted values (dictionaries)

Dictionary

Dictionaries management.

new Dictionary(options: Object)

Extends Base

Parameters
options (Object) configuration object
Name Description
options.dictionaryId String unique identifier of this Dictionary
options.dao Object mandatory Data Access Object providing required methods to load data
options.dao.loadDictionary Function mandatory function loading dictionary entries
Instance Members
dao
daoProps
dictionaryId
values
keys
getItem(key)
getLabel(key, lang)
_normalizeKey(key)
_checkIndexes()
reload()

DictionaryEvents

Contains keys of events used by Dictionary-related classes.

DictionaryEvents
Events
EV_DESTROY
EV_LOAD

Common Classes

Commonly used classes

Common Classes

Commonly used classes

Base

Common super-class for all API types.

new Base(options: Object)

Extends WithEvents()

Parameters
options (Object = {}) contains parameters for this class.
Static Members
withMixins(mixins)
Instance Members
register(registration)
unregisterAll()
initialize()
destroy()
_getOption(key, params)
_assert(value, errorMessage)
_assertObject(obj, errorMessage)
_assertMethod(f, errorMessage)
_delegateErrorsFrom(children)

Intent

Intents are Promises used as events. It allows to notify about begin and ends of asynchronous processes.

Intent

Type: deferred

Intents

This object contains a set of methods to use as Mixins for other classes working with intents.

Intents
Static Members
is(obj)
_emitIntent(intent)
_newIntent(key, payload)
run(key, options, action)

newDeferred

Creates and returns a "deferred" object - a newly created Promise instance with exposed "resolve", "reject", "end" and "done" methods. It also has the "handled" flag showing if the intent was already resolved or not. After promise resolving its results are available in the "result" and "error" fields.

newDeferred(onError: Function)
Parameters
onError (Function = ()=>{}) method to invoke if the registered handlers rises errors

deferred

Deferred objects are newly created Promise instances with exposed "resolve", "reject" methods. The deferred object created and returned by the newDeferred method.

deferred
Example
// A basic deferred object can be created in the following way:
 let yes, no, deferred = new Promise((y, n) => (yes=y,no=n));
 defered.resolve = yes; deferred.reject = no;
 ...
Static Members
handled
error
result
resolve(result)
reject(err)
done(h)
end(e, r)

WithEvents

Mixin function adding events handling to the specified type.

new WithEvents(Type: any)
Parameters
Type (any) to this type all event-specific functionalities will be added

Others

Others

ClientEvents

Contains keys of events used by the Client

ClientEvents
Events
EV_UPDATE_LANG

DataSetEvents.EV_GROUP_HOVER

Sets the specified feature as a hovered feature. This method accepts full GeoJSON features and transforms them to reduced (hovered) format with properties mapped to key/value pairs as it is defined by MapBox VectoTiles. Information about the currently hovered feature can be retrieved using the DataSetGroup.hovered field.

DataSetEvents.EV_GROUP_HOVER
Parameters
dataSetId (String) identifier of the DataSet
feature (Object) the hovered feature to set; if this value is null then the hovering effect will be removed

DataSetEvents.EV_GROUP_HOVER

Sets the specified map feature as a hovered feature. This method don't transforms the given feature and use it "as is" to defined as hovered. To select "full" GeoJSON features (for example - coming from search results) the DataSetGroup.setHovered method should be used instead. Information about the currently hovered feature can be retrieved using the DataSetGroup.hovered field.

DataSetEvents.EV_GROUP_HOVER
Parameters
dataSetId (String) identifier of the DataSet
feature (Object) the hovered feature to set; if this value is null then the hovering effect will be removed

DataSetEvents.EV_GROUP_SELECTED

Selects the specified feature. To remove the selected feature the null could be used. Information about the currently selected feature can be retrieved using the DataSetGroup.selected field.

DataSetEvents.EV_GROUP_SELECTED
Parameters
options (Object) parameters of this method
Name Description
options.dataSetId String identifier of the DataSet
options.feature Object the selected feature to set; if this value is null then selection will be removed
Returns
Intent:

WithDumpRestore

This mixin defines common methods used to dump and restore the internal state of the current object.

WithDumpRestore

Type: Mixin

Parameters
options (Object) configuration object
Instance Members
dump(obj)
restore(obj)

WithReload

This mixin defines common methods used to reloadable classes.

WithReload

Type: Mixin

Parameters
options (Object) configuration object
Instance Members
_doReload(options, action)