import React, { useEffect, useState } from "react"; import Map, {Source, Layer, Marker, Popup} from 'react-map-gl'; import axios from 'axios' import { Checkbox } from '@yandex/ui/Checkbox/desktop/bundle' import path from "path"; import { configureRootTheme } from '@yandex/ui/Theme' import { theme } from '@yandex/ui/Theme/presets/default' configureRootTheme({ theme }) export interface MapIE{ points: { cords:number[], title:string, description:string }[] remapedPoints?:{ cords:number[], title:string, description:string }[] } export const MyMap: React.FC = (props) =>{ let pathString = '' props.points.forEach((point, index) => { pathString = pathString + point.cords[0] + ',' + point.cords[1] + (index == (props.points.length-1)? '':';') }); const [route, setRoute] = useState() useEffect(()=>{ setTimeout(()=> axios.get('https://api.mapbox.com/directions/v5/mapbox/walking/'+pathString+'?alternatives=true&continue_straight=true&geometries=geojson&language=en&overview=simplified&steps=true&access_token=pk.eyJ1IjoiZmlyZXNpZWh0IiwiYSI6ImNrdW9kemYzbTB4ZGkycHAxbXN2YnIzaGMifQ.G0fl-qVbecucfOvn8OtU4Q').then( (data:any) => setRoute(data.data.routes[0].geometry) ).catch((err)=>console.log('ERRRRRRRR')), 1000) }) const geojson = { type: 'FeatureCollection', features: props.points.map((point, index)=>{ return { type: 'Feature', geometry: { type: 'Point', coordinates: point.cords, }, properties: { 'title': point.title }} } ) }; const layerWayStyle ={ id: 'route', type: 'line', source: { type: 'geojson', data: route }, layout: { 'line-join': 'round', 'line-cap': 'round' }, paint: { 'line-color': '#FFCF08', 'line-width': 5, 'line-opacity': 0.75 } } const layerStyle = { id: 'point', type: 'symbol', iconImage: 'custom-marker', layout: { 'text-field': ['get', 'title'], 'text-font': [ 'Open Sans Semibold', 'Arial Unicode MS Bold' ], 'text-size': 8, 'text-offset': [0, 0], 'text-anchor': 'top' } }; return (
{ props.points.map((point, index)=>{ return }) } { props.remapedPoints != undefined? props.remapedPoints.map((point, index)=>{ return }) : null }
); }