@aassdds
Люблю борщ и PHP

Как отследить клик по только что созданному polygon в leaflet?

Добрый день!
Есть лефлет на котором можно рисовать полигоны
нужно отлавливать событие клика по только что созданному полигону
сейчас на сайте вот такой код:
$(document).ready(function () {
    cityId = $('#save').data('city');
    mainLayer = new Array();
    function showMapEditor(container, lat, lon) {
        map = new L.Map(container, {center: new L.LatLng(lat, lon), zoom: 13, zoomAnimation: false});
        map.scrollWheelZoom.disable();
        //Подключаем тайлы
        var osm = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
        var yndx = new L.Yandex();
        var googleLayer = new L.Google('ROADMAP');
        //Добавляем слой osm
        map.addLayer(osm);
        //Добавляем control для переключения карт
        map.addControl(new L.Control.Layers({'OSM': osm, "Yandex": yndx, "Google": googleLayer}));
        //Добавляем cintrol для рисования карт
        drawnItems = new L.FeatureGroup();
        map.addLayer(drawnItems);
        var options = {
            position: 'topright',
            draw: {
                polygon: {
                    allowIntersection: false, // Restricts shapes to simple polygons
                    drawError: {
                        color: '#e1e100', // Color the shape will turn when intersects
                        message: '<Strong>Error! <Strong> Can not describe the polygon!' // Message that will show when intersect
                    },
                    shapeOptions: {
                        color: '#1b3834',
                        weight: 1,
                        opacity: 0.9,
                        stroke: true,
                        fill: true,
                        clickable: true
                    }
                }
            },
            edit: {
                featureGroup: drawnItems, //REQUIRED!!
                remove: true,
                polyline: {
                    shapeOptions: {
                        color: '#1b3834',
                        weight: 1,
                        opacity: 0.9
                    }
                },
                polygon: {
                    allowIntersection: false, // Restricts shapes to simple polygons
                    drawError: {
                        color: '#e1e100', // Color the shape will turn when intersects
                        message: '<Strong>Error! <Strong> Can not describe the polygon!' // Message that will show when intersect
                    },
                    shapeOptions: {
                        color: '#1b3834',
                        weight: 1,
                        opacity: 0.9,
                        stroke: true,
                        fill: true,
                        clickable: true
                    }
                }
            }
        };
        var drawControl = new L.Control.Draw(options);
        map.addControl(drawControl);
        map.on('draw:created', function (e) {
            var type = e.layerType,
                    layer = e.layer;
            drawnItems.addLayer(layer);
        });
    }

    var cityLat = $('#cityLat').val();
    var cityLon = $('#cityLon').val();
    showMapEditor('editMap', cityLat, cityLon);

});


никак не могу разобраться где объект нового полигона и как к нему привязаться ?
  • Вопрос задан
  • 1039 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы