Yandex Maps JS API 3.0 example ymaps3-drawer-control
---
Yandex JS API package


The package is located in the dist folder:
- dist/types TypeScript types
- dist/esm es6 modules for direct connection in your project
- dist/index.js Yandex JS Module
Recommended use ymaps3-drawer-control as usual npm package:
``sh`
npm install @yandex/ymaps3-drawer-control
You also need to import css styles into your project:
`css`
/ index.css /
@import '@yandex/ymaps3-drawer-control/dist/esm/index.css';
and dynamic import
`ts
main();
async function main() {
await ymaps3.ready;
const {YMapDrawerControl} = await import('@yandex/ymaps3-drawer-control');
map = new ymaps3.YMap(document.getElementById('app'), {location: LOCATION}, [
/ any map child /
]);
let open = false;
const drawerControl = new YMapDrawerControl({
position: 'left',
width: 300,
open,
onOpenChange: (newOpenValue) => {
open = newOpenValue;
drawerControl.update({open: newOpenValue});
},
content: () => {
const container = document.createElement('div');
const title = document.createElement('h1');
title.textContent = 'Hello world';
container.appendChild(title);
const closeButton = document.createElement('button');
closeButton.textContent = 'Close';
closeButton.addEventListener('click', () => {
open = false;
drawerControl.update({open: false});
});
container.appendChild(closeButton);
return container;
}
});
map.addChild(drawerControl);
}
`
`tsx
main();
async function main() {
const [ymaps3React] = await Promise.all([ymaps3.import('@yandex/ymaps3-reactify'), ymaps3.ready]);
const reactify = ymaps3React.reactify.bindTo(React, ReactDOM);
const {useState, useCallback} = React;
const {YMap} = reactify.module(ymaps3);
const {YMapDrawerControl} = reactify.module(await import('@yandex/ymaps3-drawer-control'));
const App = () => {
const [open, setOpen] = useState(false);
const content = useCallback(
() => (
return (
{/ any map child /}
);
};
}
`
You can use CDN with module loading handler in JS API on your page.
By default ymaps3.import can load self modules.
If you want also load your package, should register cdn:
`js`
ymaps3.import.registerCdn('https://cdn.jsdelivr.net/npm/{package}', '@yandex/ymaps3-drawer-control@latest');
Just use ymaps3.import:
`js`
const {YMapDrawerControl} = await ymaps3.import('@yandex/ymaps3-drawer-control');
| Name | Type | Default | Description |
| :------------------------ | :---------------------------------------- | :--------- | :---------------------------------------------------------------------------------------- |
| position | "left", "right", "top", "bottom" | "left" | Specifies which side of the map the drawer opens from. |number
| transitionDuration | , {open: number; close: number} | 500 | Duration of the open/close animation in milliseconds. |boolean
| open | | | Flag indicating whether the drawer is open. |string \| number
| width | | | Fixed width of the drawer. If not specified, the drawer adjusts to the content's width. |string \| number
| maxWidth | | | Maximum width of the drawer. |string \| number
| minWidth | | | Minimum width of the drawer. |string \| number
| height | | | Fixed height of the drawer. If not specified, the drawer adjusts to the content's height. |string \| number
| maxHeight | | | Maximum height of the drawer. |string \| number
| minHeight | | | Minimum height of the drawer. |(open: boolean) => void
| onOpenChange | | | Drawer open status change handler. |number
| verticalTriggerPosition | | "center" | Vertical position of the button that opens the drawer. |number
| horizontalTriggerPosition | | "center" | Horizontal position of the button that opens the drawer. |() => HTMLElement \| YMapEntity` | | Function that returns the drawer's content as an HTMLElement or an YMapEntity. |
| content |