BasemapToggleViewModel

require(["esri/widgets/BasemapToggle/BasemapToggleViewModel"], function(BasemapToggleVM) { /* code goes here */ });
Class: esri/widgets/BasemapToggle/BasemapToggleViewModel
Inheritance: BasemapToggleViewModel Accessor
Since: ArcGIS API for JavaScript 4.0

Provides the logic for the BasemapToggle widget. Use the nextBasemap property to determining the secondary basemap to toggle to.

See also:
Example:
var basemapToggle = new BasemapToggle({
  viewModel: {  // autocasts as new BasemapToggleViewModel()
    view: view,  // view with map that uses "streets" basemap
    nextBasemap: "hybrid"  // Allows for toggling to "hybrid" basemap
  }
});

Constructors

new BasemapToggleViewModel(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
Basemap

The map's basemap.

more details
more detailsBasemapToggleViewModel
String

The name of the class.

more details
more detailsAccessor
Basemap

The next basemap for toggling.

more details
more detailsBasemapToggleViewModel
String

The view model's state.

more details
more detailsBasemapToggleViewModel
MapView | SceneView

The view from which the widget will operate.

more details
more detailsBasemapToggleViewModel

Property Details

activeBasemapBasemapreadonly

The map's basemap.

declaredClassStringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

nextBasemapBasemapautocast
Autocasts from String|Object

The next basemap for toggling. One of the following values may be set to this property:

  • The string ID of any Esri basemap.
  • A custom Basemap object. Since this property may be autocast, the Basemap module does not need to be included in the require() function in most applications.
stateStringreadonly

The view model's state.

Possible Values: ready | disabled

Default Value:disabled

The view from which the widget will operate. This view provides access to the initial basemap to toggle from via the view's map property.

Method Overview

NameReturn TypeSummaryClass

Emits an event on the instance.

more details
more detailsBasemapToggleViewModel
String

Helper method to find a basemap's thumbnail URL.

more details
more detailsBasemapToggleViewModel
Boolean

Indicates whether there is an event listener on the instance that matches the provided event name.

more details
more detailsBasemapToggleViewModel
Object

Registers an event handler on the instance.

more details
more detailsBasemapToggleViewModel

Toggles to the next basemap.

more details
more detailsBasemapToggleViewModel

Method Details

emit(type, event)
Since: ArcGIS API for JavaScript 4.5

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters:
type String

The name of the event.

event Object

The event payload.

getThumbnailUrl(basemap){String}static
Since: ArcGIS API for JavaScript 4.4

Helper method to find a basemap's thumbnail URL.

If the basemap does not have a thumbnail URL defined, this utility will try to find a thumbnail URL from the best matching well-known basemap. If no match is found, a thumbnail URL from the basemap's base layers will be used.

Parameter:
basemap Basemap

The basemap used to retrieve the thumbnail URL.

Returns:
TypeDescription
StringThe basemap's thumbnail URL.
hasEventListener(type){Boolean}

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameter:
type String

The name of the event.

Returns:
TypeDescription
BooleanReturns true if the class supports the input event.
on(type, listener){Object}

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters:
type String

The name of event to listen for.

listener Function

The function to call when the event is fired.

Returns:
TypeDescription
ObjectReturns an event handler with a remove() method that can be called to stop listening for the event.
PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
See also:
Example:
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});
toggle()

Toggles to the next basemap.

API Reference search results

NameTypeModule
Loading...