Map
YMap is the root element in the hierarchy. To initialize it, pass to the object constructor:
- A link to the
HTMLElementof the container, the map will be displayed there. - Map initialization parameters.
<!-- Create a map container -->
<div id="root"></div>
const {YMap} = ymaps3;
// Initialize the map
const map = new YMap(
// Pass the link to the HTMLElement of the container
document.getElementById('root'),
// Pass the map initialization parameters
{
location: {
zoom: 10,
center: [37.588144, 55.733842]
}
}
);
All JS API objects are initialized according to their own rules, but are added to the map using the addChild() method called from the map instance. You can remove objects using the symmetric removeChild() method:
const {YMap, YMapLayer} = ymaps3;
// Initialize the map
const map = new YMap(...);
// Initialize a layer
const layer = new YMapLayer(...);
// Add this layer to the map
map.addChild(layer);
Initialization parameters
Some parameters passed to objects during initialization are required, others are optional. For example, the location field of the YMap component is required, whereas the behaviors field is optional.
const {YMap} = ymaps3;
const map = new YMap(document.getElementById('root'), {
location: {
zoom: 10,
center: [37.588144, 55.733842]
},
behaviors: ['drag', 'scrollZoom', 'pinchZoom', 'dblClick']
});
Learn more about initialization parameters of each component.