1

I am building a ReactJs application with react-leaflet. Problem is that there are a lot of Leaflet plugins that has no support for react-leaflet.

I try to use this plugin
http://kartena.github.io/Leaflet.zoomslider/

Can somebody suggest a solution in this case?

2 Answers 2

3

Most Leaflet plugins don't have a React component. You can create custom components for React-Leaflet from the Leaflet plugin.

Sign up to request clarification or add additional context in comments.

Comments

1

I was going to say you do it by getting a reference to the map object, but I don't think that's needed. But I have left that in at the base of this response as it a very helpful thing to know.

try the following:

var map = L.map('map', {
          zoomsliderControl: true,
          zoomControl: false,
          layers: [layer]
      }).setView([57.7, 11.9], 8);

Where 'map' is the id of the Map element.

=========================================== On your Map element get a reference to the map object.

<Map ref={(m) => this.leaf = m} etc...>

then in your react component. where you have componentDidMount= () =>{

use the map object to add in the slider

var map = this.leaf.leafletElement;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.