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.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!