0

I'm using addgeoJson function for the india map. I have data that I got it from here https://gadm.org/download_country.html

for example I'm using this data

This is a json file and I read that json file and pass it to addGeoJson function.

library(jsonlite) 
library(leaflet)  
url <- "https://raw.githubusercontent.com/openseattle/seattle-boundaries/master/data/zip-codes.geojson"
geojson <- fromJSON(url, simplifyVector = FALSE) 
leaflet() %>% 
  addTiles() %>% 
  addGeoJSON(geojson) %>% 
  setView(lng = -122.2, lat = 47.6, zoom = 10)

So I need to popup the names when I click on a particular state or city here. It should give some information when we click on it.

Is this possible to do it? and how?

1 Answer 1

0

The information you are looking for is stored deep in the structure of a geojson file (list). See for instance the first object of your dataset

geojson$features[[1]]$properties

Luckily there is a easier way to deal with it.

Use the package leaflet.extra, function addGeoJSONv2 specifying your label under argument popupProperty

 library(leaflet.extras)
 library(jsonlite) 
 library(leaflet)  
 
 url <- "https://raw.githubusercontent.com/openseattle/seattle- 
 boundaries/master/data/zip-codes.geojson"
 geojson_fil <- fromJSON(url, simplifyVector = FALSE) 
  
 leaflet() %>% 
 addTiles() %>% 
 setView(lng = -122.2, lat = 47.6, zoom = 10)  %>% 
 addGeoJSONv2(geojson_fil, 
              popupProperty = 'ZCTA5CE10')  

Not the answer you're looking for? Browse other questions tagged or ask your own question.