BasemapToggleViewModel
require(["esri/widgets/BasemapToggle/BasemapToggleViewModel"], function(BasemapToggleVM) { /* code goes here */ });esri/widgets/BasemapToggle/BasemapToggleViewModelProvides the logic for the BasemapToggle widget. Use the nextBasemap property to determining the secondary basemap to toggle to.
var basemapToggle = new BasemapToggle({
viewModel: { // autocasts as new BasemapToggleViewModel()
view: view, // view with map that uses "streets-vector" basemap
nextBasemap: "hybrid" // Allows for toggling to "hybrid" basemap
}
});Constructors
- new BasemapToggleViewModel(properties)
- Parameter:properties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
| Name | Type | Summary | Class | |
|---|---|---|---|---|
| Basemap | The map's basemap. more details | more details | BasemapToggleViewModel | |
| String | The name of the class. more details | more details | Accessor | |
| Basemap | The next basemap for toggling. more details | more details | BasemapToggleViewModel | |
| String | The view model's state. more details | more details | BasemapToggleViewModel | |
| MapView|SceneView | The view from which the widget will operate. more details | more details | BasemapToggleViewModel |
Property Details
- Since: ArcGIS API for JavaScript 4.7
The name of the class. The declared class name is formatted as
esri.folder.className.
The next basemap for toggling. One of the following values may be set to this property:
- state Stringreadonly
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
| Name | Return Type | Summary | Class | |
|---|---|---|---|---|
| Boolean | Emits an event on the instance. more details | more details | BasemapToggleViewModel | |
| String | Helper method to find a basemap's thumbnail URL. more details | more details | BasemapToggleViewModel | |
| Boolean | Indicates whether there is an event listener on the instance that matches the provided event name. more details | more details | BasemapToggleViewModel | |
| Object | Registers an event handler on the instance. more details | more details | BasemapToggleViewModel | |
Toggles to the next basemap. more details | more details | BasemapToggleViewModel |
Method Details
- emit(type, event){Boolean}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 StringThe name of the event.
event ObjectoptionalThe event payload.
Returns:Type Description Boolean trueif a listener was notified
- 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 BasemapThe basemap used to retrieve the thumbnail URL.
Returns:Type Description String The 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 StringThe name of the event.
Returns:Type Description Boolean Returns 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:A event type, or an array of event types, to listen for.
listener FunctionThe function to call when the event is fired.
Returns:Type Description Object Returns an event handler with a remove()method that can be called to stop listening for the event(s).Property Type Description remove Function When called, removes the listener from the event. 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.