Написал скрипт, работает, но не смог найти в документаций как из координаты с помощью яндекс карты получить адрес:
const initMap = async () =>{
await ymaps3.ready;
const center = [37.628056,55.742245];
const zoom = 15;
const {
YMap,
YMapDefaultSchemeLayer,
YMapControls,
YMapDefaultFeaturesLayer,
YMapMarker,
YMapListener
} = ymaps3;
const {
YMapZoomControl,
YMapGeolocationControl
} = await ymaps3.import('@yandex/ymaps3-controls@0.0.1');
const map = new YMap(document.getElementById('map'),{
location: {
center: center,
zoom: zoom
}
});
map.addChild(new YMapDefaultSchemeLayer());
map.addChild(new YMapDefaultFeaturesLayer());
map.addChild(new YMapControls({
position: 'right'
}).addChild(new YMapZoomControl({
})));
map.addChild(new YMapControls({
position: 'top right'
}).addChild(new YMapGeolocationControl({
})));
const icon = document.createElement('img');
icon.className = 'marker';
icon.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 384 512'%3E%3Cpath d='M215.7 499.2C267 435 384 279.4 384 192C384 86 298 0 192 0S0 86 0 192c0 87.4 117 243 168.3 307.2c12.3 15.3 35.1 15.3 47.4 0zM192 256c-35.3 0-64-28.7-64-64s28.7-64 64-64s64 28.7 64 64s-28.7 64-64 64z'/%3E%3C/svg%3E";
const marker = new YMapMarker({
coordinates: center
},icon);
map.addChild(marker);
const click = (object,event) => {
marker.update({
coordinates:event.coordinates
});
console.log(event.coordinates);
/*
*
*Адрес из event.coordinates
*
*/
}
const mapListener = new YMapListener({
layer: 'any',
onFastClick: click,
onClick: click,
});
map.addChild(mapListener);
const mapInputSearch = document.getElementById('map-search');
mapInputSearch.addEventListener("keydown", function(event) {
if(event.keyCode == 13){
ymaps3.search({
'text': mapInputSearch.value
}).then(function (res){
let center_update = res[0].geometry.coordinates;
map.update({
location: {
center: center_update,
zoom: zoom,
duration: 400
}
});
marker.update({
coordinates:center_update
});
})
}
});
};
initMap();