Integration of the taxi order widget
The example uses the Yandex Taxi widget.
vanilla.html
react.html
vue.html
variables.ts
common.ts
<!DOCTYPE html>
<html>
<head>
<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
type="text/javascript"
src="https://yastatic.net/taxi-widget/ya-taxi-widget.js"
charset="utf-8"
></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 {LOCATION} from '../variables';
import {YMapControlTaxiButton} from './common';
window.map = null;
main();
async function main() {
// Waiting for all api elements to be loaded
await ymaps3.ready;
const {YMap, YMapDefaultSchemeLayer, YMapControl} = ymaps3;
// Initialize the map
map = new YMap(
// Pass the link to the HTMLElement of the container
document.getElementById('app'),
// Pass the map initialization parameters
{location: LOCATION, showScaleInCopyrights: true},
// Add a map scheme layer
[new YMapDefaultSchemeLayer({})]
);
map.addChild(
new ymaps3.YMapControls({position: 'bottom left'}).addChild(
new YMapControl().addChild(
new YMapControlTaxiButton({
html: `<div class="ya-taxi-widget" data-ref="Lenina%2034" data-proxy-url="https://{app}.redirect.appmetrica.yandex.com/route?start-lat={start-lat}&start-lon={start-lon}&end-lat={end-lat}&end-lon={end-lon}&tariffClass={tariff}&ref={ref}&appmetrica_tracking_id={redirect}&lang={lang}" data-tariff="econom" data-app="3" data-lang="en" data-redirect="1178268795219780156" data-description="Moscow, Russian Federation, Lva Tolstogo Street, 16" data-size="s" data-theme="normal" data-title="Call a taxi" data-use-location="true" data-point-a="" data-point-b="37.588144,55.733842"></div>`
})
)
)
);
}
</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="./common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<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
type="text/javascript"
src="https://yastatic.net/taxi-widget/ya-taxi-widget.js"
charset="utf-8"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="react, typescript"
type="text/babel"
src="../variables.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="react, typescript"
type="text/babel"
src="./common.ts"
></script>
<script data-plugins="transform-modules-umd" data-presets="react, typescript" type="text/babel">
import {LOCATION} from '../variables';
import {YMapControlTaxiButton} from './common';
main();
async function main() {
// For each object in the JS API, there is a React counterpart
// To use the React version of the API, include the module @yandex/ymaps3-reactify
const [ymaps3React] = await Promise.all([ymaps3.import('@yandex/ymaps3-reactify'), ymaps3.ready]);
const reactify = ymaps3React.reactify.bindTo(React, ReactDOM);
const {YMap, YMapControls, YMapControl, YMapDefaultSchemeLayer} = reactify.module(ymaps3);
const {YMapControlTaxiButtonR} = reactify.module({YMapControlTaxiButtonR: YMapControlTaxiButton});
function App() {
return (
// Initialize the map and pass initialization parameters
<YMap location={LOCATION} showScaleInCopyrights={true}>
{/* Add a map scheme layer */}
<YMapDefaultSchemeLayer />
<YMapControls position="bottom left">
<YMapControl>
<YMapControlTaxiButtonR
html={`<div class="ya-taxi-widget" data-ref="Lenina%2034" data-proxy-url="https://{app}.redirect.appmetrica.yandex.com/route?start-lat={start-lat}&start-lon={start-lon}&end-lat={end-lat}&end-lon={end-lon}&tariffClass={tariff}&ref={ref}&appmetrica_tracking_id={redirect}&lang={lang}" data-tariff="econom" data-app="3" data-lang="en" data-redirect="1178268795219780156" data-description="Moscow, Russian Federation, Lva Tolstogo Street, 16" data-size="s" data-theme="normal" data-title="Call a taxi" data-use-location="true" data-point-a="" data-point-b="37.588144,55.733842"></div>`}
/>
</YMapControl>
</YMapControls>
</YMap>
);
}
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('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="./common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<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
type="text/javascript"
src="https://yastatic.net/taxi-widget/ya-taxi-widget.js"
charset="utf-8"
></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"></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="./common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
import type {YMapLocationRequest} from '@yandex/ymaps3-types';
export const LOCATION: YMapLocationRequest = {
center: [37.623082, 55.75254], // starting position [lng, lat]
zoom: 9 // starting zoom
};
import type {DomDetach} from '@yandex/ymaps3-types';
// Create a custom control to change the customization of the map
export let YMapControlTaxiButton = null;
ymaps3.ready.then(() => {
class YMapControlTaxiButtonClass extends ymaps3.YMapComplexEntity<{html: string}> {
__element = document.createElement('ymaps3');
private _detachDom: DomDetach;
constructor(options) {
super(options);
this.__element.innerHTML = this._props.html;
}
_onAttach() {
this._detachDom = ymaps3.useDomContext(this, this.__element, null);
// API из виджета такси https://yastatic.net/taxi-widget/ya-taxi-widget.js
window.YaTaxiWidget.init(this.__element.querySelector('.ya-taxi-widget'));
}
_onDetach() {
this._detachDom();
this._detachDom = null;
}
}
YMapControlTaxiButton = YMapControlTaxiButtonClass;
});