Giter Site home page Giter Site logo

Comments (9)

jacobtoye avatar jacobtoye commented on August 20, 2024 3

In Leaflet.draw master the toolbar id is a string. So you can do:

drawControl._toolbars[L.DrawToolbar.TYPE]._modes.rectangle.handler.enable()

However if you don't want to toolbar at all you should roll you own. As mentioned in my previous comment, you should use the handlers directly.

from leaflet.draw.

drwelby avatar drwelby commented on August 20, 2024 2

Not sure if it works in your case, but I've done it by adding the Draw control but hiding it with CSS. I just call drawControl.handlers.polygon.enable() from my custom button to turn it on, and listen for the 'draw:poly-created' event to do something with the finished polygon.

from leaflet.draw.

chander avatar chander commented on August 20, 2024 1

Sorry, is there a reason why you can't just do this:

L.DomUtil.addClass(drawControl.getContainer(), 'hide')

To hide the toolbar on the map? Then you can use the control externally (as noted above) without it being map-visible.

from leaflet.draw.

jacobtoye avatar jacobtoye commented on August 20, 2024

At the moment you will need to replace the Draw control with your own version. You will need to pick and choose the appropriate src files to include.

Providing the ability to create custom toolbars is something I think is necessary in Leaflet.draw. I think what would be cool is to have multiple built files which includes a core that is only the handlers. This would make it easier to roll your own toolbar.

Not sure when this will happen but it is definitely on the cards.

from leaflet.draw.

thatjpk avatar thatjpk commented on August 20, 2024

@FunkMonkey33, I do pretty much what you're looking for. In my application I'm using Backbone and Require. What I do is write a require module containing a singleton backbone model that wraps the drawing handlers. The model does the enable/disable of drawing internally, and listens for drawing events and re-emits them so views and things throughout the app can require the drawing model and listen to it for the drawing events. You get a single place where the drawing is managed, and you don't have to worry about passing references to the handlers around.

That may or may not help you, but that's how I approached it.

from leaflet.draw.

jacobtoye avatar jacobtoye commented on August 20, 2024

Hey guys, thanks for the report. When 0.2 lands you will have the option to do a custom build of just the draw and/or edit handlers. This was you can drop the handlers in on your own toolbars.

from leaflet.draw.

paulcpederson avatar paulcpederson commented on August 20, 2024

For anybody who is trying to do this, look at the Jakefile https://github.com/Leaflet/Leaflet.draw/blob/master/Jakefile.js for information on performing a custom build.

@jacobtoye This might be worth adding to the ReadMe under a heading like "Using a Custom Toolbar" perhaps with a brief demo as well.

from leaflet.draw.

jacobtoye avatar jacobtoye commented on August 20, 2024

You should be able to use the https://github.com/Leaflet/Leaflet.draw/blob/master/build/build.html to build the jake command to only build the handlers you need. There is also the edit handlers example which uses only the edit handlers.

I've also added this info to the readme in the Command Tasks section at the bottom.

from leaflet.draw.

jerroydmoore avatar jerroydmoore commented on August 20, 2024

Hey guys,

I want to do the same thing @FunkMonkey33 is doing. The answer @drwelby provided was the closest, however, after a year of development, it looks like the drawControl.handlers has been refactored. This is the best way I've found to access the enable():

drawControl._toolbars[X]._modes.rectangle.handler.enable()
Where X an leafletId, so its value is differs from instance to instance.

It would help if the DrawControl had a method to expose this function with a better nomenclature, e.g. DrawControl.drawRectangle()

from leaflet.draw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.