Skip to main content

<layer-> API

In this section we'll learn different API methods on the <layer->. It allows you to interact with the layers through JavaScript.

MethodFunctionality
checkedSetter & getter related to the layer's checked state.
focus()Method to zoom to the layer's extent.
hiddenSetter & getter related to the layer's hidden attribute.
labelSetter & getter related to the layer's label.
opacitySetter & getter to set the opacity of a layer.
srcSetter & getter to a fetched layer's URL.

Setter & Getters#

checked#

To set/update whether the layer is "checked":

<layer->.checked = true; // valid values are true | false

To get the <layer->'s checked value:

let isChecked = <layer->.checked;

hidden#

To set/update whether the layer is "hidden":

<layer->.hidden = true; // valid values are true | false

To get the <layer->'s hidden value:

let isHidden = <layer->.hidden;

label#

To set/update the <layer->'s label:

caution

Needs To Be Implemented, Currently doesn't update the label in layer controls

<layer->.label = "New Title";

To get the <layer->'s label value:

let label = <layer->.label;

opacity#

To set/update the <layer->'s opacity:

<layer->.opacity = 0.5; // valid values from 0 to 1

To get the <layer->'s opacity value:

let opacity = <layer->.opacity;

src#

To set/update the <layer->'s src:

<layer->.src = "https://example.org";

To get the <layer->'s src value (URL):

let url = <layer->.src;

Methods#

focus()#

To fit the layer's extent in the map as much as possible:

<layer->.focus();