D
D
DeniSidorenko2019-12-11 07:51:12
Yandex maps
DeniSidorenko, 2019-12-11 07:51:12

Will add or remove points on the Yandex map when clicking?

Good afternoon, there is such a structure

<div id="button">click-me</div>

<div class="all-adress">
  <div class="address">
    <span>55.773702</span>
    <span>37.599220</span>
  </div>
  <div class="address">
    <span>55.773732102</span>
    <span>37.599220</span>
  </div>
  <div class="address">
    <span>55.773123702</span>
    <span>37.599212320</span>
  </div>
  <div class="address">
    <span>535.773702</span>
    <span>37.5939220</span>
  </div>
  <div class="address">
    <span>525.773702</span>
    <span>37.3</span>
  </div>
</div>

When I click on the button, I get all the divs with the address class into a variable.
How to add them to the map.
Go through the cycle, and pull out the Longitude and latitude from each item, I know how, the only question is, which function of the Yandex map will add them to the map + with its own icon?
And is there an analogue to remove them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-12-11
@DeniSidorenko

https://tech.yandex.ru/maps/jsbox/2.1?from=jsapi
as you noticed, first a label object is created, and then it is added

//Глобальный контекст
var myMap,myPlacemark;
// контекст создания карты
myMap = new ymaps.Map(...);
//контекст нажатия кнопки 1
myPlacemark = new ymaps.Placemark([lat, lon],{...});
myMap.geoObjects.add(myPlacemark);
//контекст нажатия кнопки 2
myMap.geoObjects.remove(myPlacemark);

in order to execute code at an arbitrary moment in an arbitrary context, the myMap variable must be available globally. And if the removal occurs from an arbitrary context, then myPlacemark should also be available globally.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question