This class provides a simple interface for adding, moving and removing components from a view's user interface (UI). In most cases, you will work with the view's DefaultUI which places default widgets, such as Zoom and Attribution in the View.
The UI class provides the API for easily placing HTML elements and widgets within the view. See DefaultUI for details on working with this class.
- See also
Constructors
-
new UI(properties)
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
HTMLElement | The HTML Element that contains the view. more details | UI | |
String | The name of the class. more details | Accessor | |
Number | The height of the UI container. more details | UI | |
Object|Number | Defines the padding for the UI from the top, left, right, and bottom sides of the container or View. more details | UI | |
MapView|SceneView | The view associated with the UI components. more details | UI | |
Number | The width of the UI container. more details | UI |
Property Details
-
container HTMLElement
-
The HTML Element that contains the view.
- See also
-
Since: ArcGIS Maps SDK for JavaScript 4.7
-
The name of the class. The declared class name is formatted as
esri.folder.className
.
-
height Numberreadonly
-
The height of the UI container.
-
Defines the padding for the UI from the top, left, right, and bottom sides of the container or View. If the value is a number, it will be used to pad all sides of the container.
- Default Value:{ left: 15, top: 15, right: 15, bottom: 15 }
Example// Setting a single number to this property ui.padding = 0; // is the same as setting it on all properties of the object ui.padding = { top: 0, left: 0, right: 0, bottom: 0 };
-
The view associated with the UI components.
-
width Numberreadonly
-
The width of the UI container.
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more HTML component(s) or widgets to the UI. more details | UI | ||
Adds one or more handles which are to be tied to the lifecycle of the object. more details | Accessor | ||
Removes all components from a given position. more details | UI | ||
HTMLElement|Widget | Find a component by widget or DOM ID. more details | UI | |
Boolean | Returns true if a named group of handles exist. more details | Accessor | |
Moves one or more UI component(s) to the specified position. more details | UI | ||
Removes one or more HTML component(s) or widgets from the UI. more details | UI | ||
Removes a group of handles owned by the object. more details | Accessor |
Method Details
-
add(component, position)
-
Adds one or more HTML component(s) or widgets to the UI.
ParametersSpecificationcomponent Widget|HTMLElement|String|Object|ArrayThe component(s) to add to the UI. This can be a widget instance, HTML element, a string value representing a DOM node ID, or an array containing a combination of any of those types. See the example snippets below for code examples. Alternatively, you can pass an array of objects with the following specification.
Specificationcomponent Widget|HTMLElement|StringThe component to add to the UI. This can be a widget instance, HTML element, a string value representing a DOM node ID.
position StringoptionalThe position in the view at which to add the component. If not specified,
manual
is used by default. Usingmanual
allows you to place the component in a container where you can position it anywhere using CSS. For the other possible values, "top", "bottom", "left", and "right" are consistent placements. The "leading" and "trailing" values depend on whether the browser is using right-to-left (RTL) or left-to-right (LTR). For LTR, "leading" is left and "trailing" is right. For RTL, "leading" is right and "trailing" is left.Possible Values:"bottom-leading"|"bottom-left"|"bottom-right"|"bottom-trailing"|"top-leading"|"top-left"|"top-right"|"top-trailing"|"manual"
index NumberoptionalThe placement index of the component. This index shows where to place the component relative to other components. For example a value of
0
would place it topmost when position is top-*, leftmost for bottom-left and right most for bottom-right.optional The position in the view at which to add the component. If not specified,
manual
is used by default. Usingmanual
allows you to place the component in a container where you can position it anywhere using CSS. For the other possible values, "top", "bottom", "left", and "right" are consistent placements. The "leading" and "trailing" values depend on whether the browser is using right-to-left (RTL) or left-to-right (LTR). For LTR, "leading" is left and "trailing" is right. For RTL, "leading" is right and "trailing" is left.Specificationposition StringoptionalThe position in the view at which to add the component. If not specified,
manual
is used by default. Usingmanual
allows you to place the component in a container where you can position it anywhere using CSS. For the other possible values, "top", "bottom", "left", and "right" are consistent placements. The "leading" and "trailing" values depend on whether the browser is using right-to-left (RTL) or left-to-right (LTR). For LTR, "leading" is left and "trailing" is right. For RTL, "leading" is right and "trailing" is left.Possible Values:"bottom-leading"|"bottom-left"|"bottom-right"|"bottom-trailing"|"top-leading"|"top-left"|"top-right"|"top-trailing"|"manual"
index NumberoptionalThe placement index of the component(s). This index shows where to place the component relative to other components. For example a value of
0
would place it topmost when position is top-*, leftmost for bottom-left and right most for bottom-right.Exampleslet toggle = new BasemapToggle({ view: view, nextBasemap: "hybrid" }); // Adds an instance of BasemapToggle widget to the // top right of the view's container. view.ui.add(toggle, "top-right");
// Adds multiple widgets to the top right of the view view.ui.add([ compass, toggle ], "top-leading");
// Adds multiple components of different types to the bottom left of the view view.ui.add([ searchWidget, "infoDiv" ], "bottom-left");
// Adds multiple components of various types to different view positions view.ui.add([ { component: compassWidget, position: "top-left", index: 0 }, { component: "infoDiv", position: "bottom-trailing" }, { component: searchWidget, position: "top-right", index: 0 }, { component: legendWidgetDomNode, position: "top-right", index: 1 } ]);
-
addHandles(handleOrHandles, groupKey)inheritedSince: ArcGIS Maps SDK for JavaScript 4.25
-
Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); this.addHandles(handle); // Destroy the object this.destroy();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.
-
empty(position)
-
Removes all components from a given position.
Parameterposition StringoptionalThe position in the view at which to add the component. If not specified,
manual
is used by default. Usingmanual
allows you to place the component in a container where you can position it anywhere using CSS. For the other possible values, "top", "bottom", "left", and "right" are consistent placements. The "leading" and "trailing" values depend on whether the browser is using right-to-left (RTL) or left-to-right (LTR). For LTR, "leading" is left and "trailing" is right. For RTL, "leading" is right and "trailing" is left.Possible Values:"bottom-leading"|"bottom-left"|"bottom-right"|"bottom-trailing"|"top-leading"|"top-left"|"top-right"|"top-trailing"|"manual"
Example// Removes all of the elements in the top-left of the view's container // including the default widgets zoom and compass (if working in SceneView) view.ui.empty("top-left");
-
find(id){HTMLElement|Widget}
-
Find a component by widget or DOM ID.
Parameterid StringThe component's ID.
ReturnsType Description HTMLElement | Widget Returns the Widget or HTMLElement if the id is found, otherwise returns null
.Examplelet compassWidget = new Compass({ view: view, id: "myCompassWidget" // set an id to get the widget with find }); // Add the Compass widget to the top left corner of the view view.ui.add(compassWidget, "top-left"); // Find the Widget with the specified ID let compassWidgetFind = view.ui.find("myCompassWidget"))
-
Since: ArcGIS Maps SDK for JavaScript 4.25
-
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType Description Boolean Returns true
if a named group of handles exist.Example// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
move(component, position)
-
Moves one or more UI component(s) to the specified position.
ParametersSpecificationcomponent Widget|HTMLElement|String|Object|ArrayThe component(s) to move. This value can be a widget instance, HTML element, a string value representing a DOM node ID, or an array containing a combination of any of those types. See the example snippets below for code examples. Alternatively, you can pass an array of objects with the following specification.
Specificationcomponent Widget|HTMLElement|StringThe component to move. This can be a widget instance, HTML element, a string value representing a DOM node ID.
position StringoptionalThe destination position. The component will be placed in the UI container when not provided. If not specified,
manual
is used by default. Usingmanual
allows you to place the component in a container where you can position it anywhere using CSS.Possible Values:"bottom-leading"|"bottom-left"|"bottom-right"|"bottom-trailing"|"top-leading"|"top-left"|"top-right"|"top-trailing"|"manual"
index NumberoptionalThe placement index of the component. This index shows where to place the component relative to other components. For example a value of 0 would place it topmost when position is top-*, leftmost for bottom-left and right most for bottom-right.
optional The destination position. The component will be placed in the UI container when not provided.
Specificationposition StringoptionalThe position in the view at which to add the component. If not specified,
manual
is used by default. Usingmanual
allows you to place the component in a container where you can position it anywhere using CSS.Possible Values:"bottom-leading"|"bottom-left"|"bottom-right"|"bottom-trailing"|"top-leading"|"top-left"|"top-right"|"top-trailing"|"manual"
index NumberoptionalThe placement index of the component(s). This index shows where to place the component relative to other components. For example a value of
0
would place it topmost when position is top-*, leftmost for bottom-left and right most for bottom-right.Examples// Moves the BasemapToggle widget from the view if added. // See the example for add() for more context view.ui.move(toggle, "bottom-leading");
// Moves the default zoom widget to the bottom left corner of the view's container view.ui.move("zoom", "bottom-left");
// Moves multiple widgets to the bottom right of the view's UI view.ui.move([ compass, toggle, "zoom" ], "bottom-right");
// Moves the legend to the topmost position in the top-right corner of the view's UI. view.ui.move({component: legend, position: "top-right", index: 0});
-
remove(component)
-
Removes one or more HTML component(s) or widgets from the UI.
Parametercomponent Widget|HTMLElement|String|ArrayThe component(s) to remove from the UI. This can be a widget instance, HTML element, a string value representing a DOM node ID, or an array containing a combination of any of those types. See the example snippets below for code examples.
Examples// Removes the BasemapToggle widget from the view if added. // See the example for add() for more context view.ui.remove(toggle);
// Removes the default zoom widget from the view's container view.ui.remove("zoom");
// Removes multiple widgets from the view's UI view.ui.remove([ compass, toggle, "zoom" ]);
-
removeHandles(groupKey)inheritedSince: ArcGIS Maps SDK for JavaScript 4.25
-
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");