1. 48
    Add a Shaded React Leaflet Circle to the Map Based on GeoJSON Data
    55s

Add a Shaded React Leaflet Circle to the Map Based on GeoJSON Data

Colby Fayock
InstructorColby Fayock
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 4 years ago

Now that we're setting our delivery radius, let's use it! We'll use that value to create a new Circle shape on the map.

Click here for exercise instructions

Colby Fayock: [0:00] Now that we have our delivery-radius's, we want to actually see them on the map. We're going to add a shaded circle, but we only want to add it if they actually deliver. I'm going to create a new let variable called deliveries-on-circle. If they can deliver, we're going to set that value equal to a new Leaflet circle. The Leaflet circle takes coordinates.

[0:14] We're going to de-structure our geometry with an empty object by default. Next, we want to also de-structure these coordinates from that geometry. We can take those coordinates and pass it into our circle. Similar to markers, we're going to take that deliveries-on-circle, and we're going to add it to our map.

[0:28] If we look at our map, we don't actually see that circle. If you zoom all the way out, you can actually see that our circle is down in Antarctica. The coordinates are stored in GeoJSON backwards to what Leaflet actually expects.

[0:37] Because that's a simple array, we can run the reverse method right on that array. While the circles are small, we can see them on the map at their default size. Next, to actually set the radius, we can pass a new configuration object where we're going to specify our radius property and set it to our delivery-radius.

[0:51] Now, if we look at a map, we can see all of our markers with the delivery zone with the circle around it.