Change the React Leaflet Map ZoomControl Location and Icons

Colby Fayock
InstructorColby Fayock

Share this video with your friends

Send Tweet
Published 2 years ago
Updated a year ago

In this lesson, you learn how to use the React Leaflet ZoomControl component to add a custom zoom control to your map. We'll walk through removing the default control to avoid duplicates, using the ZoomControl position prop to change its location, and setting custom icons with the zoomInText and zoomOutText props.

Colby Fayock: [0:00] We're going to start off with the basic map of San Francisco. We're importing a Map and a TileLayer from 'react-leaflet'. With those imported components, we're adding a Map and a TileLayer to our App.

[0:10] The first thing we want to do to customize our ZoomControl is import ZoomControl component. With that ZoomControl imported, we can add it to our map. If you look at our map, you'll notice we have two ZoomControls, which isn't what we want. The first thing we want to do is set the ZoomControl to false, to remove it from the map. Now we're back to one ZoomControl.

[0:29] To set the position of the ZoomControl, we can set the position to bottomright. If you look at the map, it's now on the bottom right. With the ZoomControl, we can also set the text, so let's set the zoomInText to this monocle emoji and how about the zoomOutText to a map emoji? Once we hit Save and look at our map, we can see our new emoji on the ZoomControl.

[0:51] In review, in addition to our Map and TileLayer, we imported a ZoomControl. To avoid getting duplicates, we set the ZoomControl on the map to false. Then we added our ZoomControl, set the position to bottomright, set the zoomInText to a monocle emoji and the zoomOutText to a map. That gave us our custom ZoomControl on the map.