Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaflet.draw #344

Closed
aaronsharper opened this issue Mar 26, 2014 · 6 comments
Closed

Leaflet.draw #344

aaronsharper opened this issue Mar 26, 2014 · 6 comments

Comments

@aaronsharper
Copy link

Trying to get the Leaflet.draw controls to work correctly. I can get the controls to show up on the map, and I can detect when the "draw:created" event is triggered, but when the layer is added to the map, the edit functionality doesn't work. I am guessing this is because I am supposed to add the layer to the "drawnItems" featureGroup, but that doesn't seem available from the directive in my controller. Am I missing something? Is there a way to get the declared "drawnItems" value from the directive from my controller? I am sure this is user error on my part.

Thanks in advance.

@Martijnvl
Copy link

I got that same issue, maybe someone can help use out with a working example. Much tnx

@ninniuz
Copy link

ninniuz commented Apr 3, 2014

As a workaround I had to create a L.Control.Draw in my controller, define options there and add a drawnItems in my scope.

var drawnItems = new L.FeatureGroup();
var options = {  edit: { featureGroup: drawnItems } };
var drawControl = new L.Control.Draw(options);
angular.extend($scope, controls: { custom: [drawControl] });

Then simply add the layer to drawnItems when you get the draw:created event.

@Martijnvl
Copy link

I did they exact same thing but for some reason when I draw a circle for example I don't see it getting painted on the layer...see my ctrl code below. I placed the css files inside my index.html. I can't figure out why this isn't working. I do see that the layer gets added to drawitems but nothing shows on map. Any help would be appreciated.

var drawnItems = new L.FeatureGroup();

var options = {
    edit: { featureGroup: drawnItems
    },
    draw: {
        polygon: {
            shapeOptions: {
                color: 'purple'
            }
        },
        circle: {
            shapeOptions: {
                stroke: true,
                weight: 4,
                color: 'blue',
                opacity: 0.5,
                fill: true,
                fillColor: null, //same as color by default
                fillOpacity: 0.2,
                clickable: true
            }
        }
    },
    showRadius: true
};

var drawControl = new L.Control.Draw(options);

angular.extend($scope, {
    defaults: {
        scrollWheelZoom: false
    },
    london: {
        lat: 51.505,
        lng: -0.09,
        zoom: 8
    },
    controls: {
        custom: [drawControl]
    }
});

leafletData.getMap().then(function (map) {
    map.on('draw:created', function (e) {
        var type = e.layerType,
            layer = e.layer;

        if (type === 'circle') {
            console.log(JSON.stringify(layer.toGeoJSON()));
        }

        drawnItems.addLayer(layer);
    });
});

@muenchdo
Copy link

@Martijnvl Is it possible that you have missed adding the drawnItems to your map? I did it like this:

leafletData.getMap().then(function(map) {
    map.addLayer(drawnItems);
});

Now I can at least add new shapes to the map. But somehow I have some strange issues with the editing functionality. Sometimes I can edit, but after adding a new shape the editing button is suddenly disabled. Then, after adding another shape, editing is suddenly possible again. I haven't been able to track down the reason for this behaviour.

EDIT: I have further investigated my issues and it seems that every time I add a new shape, the editing toolbar is toggled. Does anybody have any ideas what could be causing this?

@nmccready
Copy link
Contributor

This issue was moved to angular-ui/ui-leaflet#17

@nmccready nmccready reopened this Oct 29, 2015
@tombatossals
Copy link
Owner

I'm going to rework&redesign angular-leaflet-directive to be compatible with Leaflet v1.0. It will mantain almost all its functionality, and will be compatible with the current features of the directive, but I must start from a fresh point, so I'm going to close this issue. If you think it must be worked with the new version, please reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants