Добавление контрола мини-карты
vanilla.html
react.html
vue.html
variables.ts
variables.css
common.ts
common.css
<!DOCTYPE html>
<html>
<head>
<title>Vanilla example ymaps3-minimap</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
<!-- To make the map appear, you must add your apikey -->
<script src="https://api-maps.yandex.ru/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="../variables.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="./common.ts"
></script>
<script data-plugins="transform-modules-umd" data-presets="typescript" type="text/babel">
import {MINIMAP_PROPS} from './common';
import {LOCATION} from '../variables';
window.map = null;
main();
async function main() {
await ymaps3.ready;
const {YMap, YMapDefaultSchemeLayer, YMapDefaultFeaturesLayer, YMapControls} = ymaps3;
const {YMapMiniMap} = await ymaps3.import('@yandex/ymaps3-minimap');
map = new YMap(document.getElementById('app'), {location: LOCATION}, [
new YMapDefaultSchemeLayer({}),
new YMapDefaultFeaturesLayer({})
]);
const minimap = new YMapMiniMap({...MINIMAP_PROPS});
map.addChild(new YMapControls({position: 'right bottom'}).addChild(minimap));
}
</script>
<style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; } </style>
<link rel="stylesheet" href="../variables.css" />
<link rel="stylesheet" href="./common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>React example ymaps3-minimap</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<script crossorigin src="https://cdn.jsdelivr.net/npm/react@17/umd/react.production.min.js"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/react-dom@17/umd/react-dom.production.min.js"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
<!-- To make the map appear, you must add your apikey -->
<script src="https://api-maps.yandex.ru/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="../variables.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="./common.ts"
></script>
<script data-plugins="transform-modules-umd" data-presets="react, typescript" type="text/babel">
import {MINIMAP_PROPS} from './common';
import {LOCATION} from '../variables';
window.map = null;
main();
async function main() {
const [ymaps3React] = await Promise.all([ymaps3.import('@yandex/ymaps3-reactify'), ymaps3.ready]);
const reactify = ymaps3React.reactify.bindTo(React, ReactDOM);
const {YMap, YMapDefaultSchemeLayer, YMapDefaultFeaturesLayer, YMapControls} = reactify.module(ymaps3);
const {useState} = React;
const {YMapMiniMap} = reactify.module(await ymaps3.import('@yandex/ymaps3-minimap'));
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('app')
);
function App() {
const [showBounds, setShowBounds] = useState(MINIMAP_PROPS.showBounds);
const onChangeSyncZoom = (value: boolean) => {};
const onChangePrevLocation = (value: boolean) => {};
const onChangeSegment = (value: string) => {
setShowBounds(value === 'Area moves');
};
return (
<YMap location={LOCATION} ref={(x) => (map = x)}>
<YMapDefaultSchemeLayer />
<YMapDefaultFeaturesLayer />
<YMapControls position="right bottom">
<YMapMiniMap {...MINIMAP_PROPS} showBounds={showBounds} />
</YMapControls>
</YMap>
);
}
}
</script>
<style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; } </style>
<link rel="stylesheet" href="../variables.css" />
<link rel="stylesheet" href="./common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Vue example ymaps3-minimap</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<script crossorigin src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
<!-- To make the map appear, you must add your apikey -->
<script src="https://api-maps.yandex.ru/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="../variables.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="./common.ts"
></script>
<script data-plugins="transform-modules-umd" data-presets="typescript" type="text/babel">
import {MINIMAP_PROPS} from './common';
import {LOCATION} from '../variables';
window.map = null;
main();
async function main() {
const [ymaps3Vue] = await Promise.all([ymaps3.import('@yandex/ymaps3-vuefy'), ymaps3.ready]);
const vuefy = ymaps3Vue.vuefy.bindTo(Vue);
const {YMap, YMapDefaultSchemeLayer, YMapDefaultFeaturesLayer, YMapControls} = vuefy.module(ymaps3);
const {YMapMiniMap} = vuefy.module(await ymaps3.import('@yandex/ymaps3-minimap'));
const app = Vue.createApp({
components: {
YMap,
YMapDefaultSchemeLayer,
YMapDefaultFeaturesLayer,
YMapControls,
YMapMiniMap
},
setup() {
const refMap = (ref) => {
window.map = ref?.entity;
};
return {MINIMAP_PROPS, LOCATION, refMap};
},
template: `
<YMap :location="LOCATION" :ref="refMap">
<YMapDefaultSchemeLayer />
<YMapDefaultFeaturesLayer />
<YMapControls position="right bottom">
<YMapMiniMap v-bind="MINIMAP_PROPS" />
</YMapControls>
</YMap>`
});
app.mount('#app');
}
</script>
<style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; } </style>
<link rel="stylesheet" href="../variables.css" />
<link rel="stylesheet" href="./common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
import type {DrawingStyle, YMapLocationRequest} from '@yandex/ymaps3-types';
export const LOCATION: YMapLocationRequest = {
center: [37.623082, 55.75254], // starting position [lng, lat]
zoom: 9 // starting zoom
};
export const MINIMAP_BOUNDS_STYLE: DrawingStyle = {
fill: 'rgb(25, 109, 255)',
fillOpacity: 0.08,
stroke: [{width: 1, color: '#313133'}]
};
:root {
--slider-active: #313133;
}
import {YMapMiniMapProps} from '@yandex/ymaps3-minimap';
import {YMapControl} from '@yandex/ymaps3-types';
import {MINIMAP_BOUNDS_STYLE} from './variables';
ymaps3.import.registerCdn('https://cdn.jsdelivr.net/npm/{package}', ['@yandex/ymaps3-minimap@0.0.3']);
export const MINIMAP_PROPS: YMapMiniMapProps = {
size: [260, 170],
showCollapsedControl: false,
zoomOffset: 3,
showBounds: true,
boundsDrawingStyle: MINIMAP_BOUNDS_STYLE
};
.minimap-props-control {
display: flex;
flex-direction: column;
width: 260px;
padding: 16px 16px 8px;
border-radius: 12px;
background: #fff;
box-shadow: 0 4px 12px 0 rgba(95, 105, 131, 0.1), 0 4px 24px 0 rgba(95, 105, 131, 0.04);
}
.segment-control {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
padding: 2px;
border-radius: 8px;
background: rgba(92, 94, 102, 0.06);
gap: 5px;
}
.segment-control button {
width: 100%;
padding: 6px 8px;
font-size: 14px;
font-style: normal;
line-height: 16px;
cursor: pointer;
text-align: center;
color: #7b7d85;
border: none;
border-radius: 8px;
background-color: transparent;
}
.segment-control button.active {
color: #050d33;
background: #fff;
box-shadow: 0 4px 12px 0 rgba(95, 105, 131, 0.1), 0 4px 24px 0 rgba(95, 105, 131, 0.04);
}
.toggle-control {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: start;
padding: 0 2px;
}
.toggle-control .text {
display: flex;
flex: 1 0 0;
flex-direction: column;
gap: 2px;
font-style: normal;
line-height: 16px;
}
.toggle-control .text .title {
font-size: 14px;
color: #050d33;
}
.toggle-control .text .description {
font-size: 12px;
color: #7b7d85;
}
.toggle-control .toggle {
position: relative;
display: inline-block;
width: 26px;
height: 16px;
}
.toggle-control .toggle input {
display: none;
}
.toggle-control .slider {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
cursor: pointer;
border-radius: 34px;
background-color: #808080;
transition: 0.4s;
}
.toggle-control .slider::before {
position: absolute;
bottom: 2px;
left: 2px;
width: 12px;
height: 12px;
content: '';
border-radius: 50%;
background-color: #fff;
transition: 0.4s;
}
.toggle-control .toggle input:checked + .slider {
background-color: var(--slider-active);
}
.toggle-control .toggle input:checked + .slider::before {
transform: translateX(10px);
}
.divider {
width: 100%;
height: 1px;
margin: 12px 0;
background: rgba(92, 94, 102, 0.14);
}