R
R
run1822017-05-08 22:11:25
JavaScript
run182, 2017-05-08 22:11:25

How to delete a given route in the yandex maps script?

Here is the code of the entire script (the route is set by clicking on the button, with each click a new route is applied to the map, but you also need to delete other routes):
Thank you in advance!

ymaps.ready(init<?echo $pid;?>);
    var myMap<?echo $pid;?>,
    myPlacemark;
    function init<?echo $pid;?>(){
        myMap<?echo $pid;?> = new ymaps.Map("map<?echo $pid;?>", {
            center: [<?echo $centermap;?>],
            zoom: <?echo $zoom;?>
        }, {
            searchControlProvider: 'yandex#search'
        });
        myPlacemark<?echo $map['id'];?> = new ymaps.Placemark([<?echo $map['coords'];?>], {
            hintContent: '<?echo $map['name'];?>',
            balloonContent: '<div class="baloon"><?echo $info;?></div>'
        }, {
            iconLayout: 'default#image',
            iconImageHref: '/img/placemark.png',
            iconImageSize: [29, 39],
            iconImageOffset: [-14, -39]
        });
        myMap<?echo $pid;?>.geoObjects.add(myPlacemark<?echo $map['id'];?>);
    }
    $(function() {
        $(".marshrut .get").click(function(e) {
            e.preventDefault();
            ymaps.route([
                "Калининградская область, "+$(".marshrut .from").val(),
                $(".marshrut .to").val()
            ], {
                mapStateAutoApply: true
            }).then(function (route) {
                route.getPaths().options.set({
                    balloonContentBodyLayout: ymaps.templateLayoutFactory.createClass('$[properties.humanJamsTime]'),
                    strokeColor: '0000ffff',
                    opacity: 0.9
                });
                //myMap<?echo $pid;?>.removeAll();
                myMap<?echo $pid;?>.geoObjects.add(route);
            });
        });
    });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question