Open mosscoder opened 6 years ago
I'll take a look.
I've tried adding a z_index
argument to the KML layer but it's not obeying it.
And a note about your code if I may:
I've written the geojsonsf
package, which is quicker at parsing GeoJSON than geojsonio
.
Also, plotting GeoJSON through add_geojson()
is slower than using an sf
object in add_polygon()
method, so I would recommend adding polygons rather than geojson if you can
library(googleway)
library(geojsonsf)
library(sf) ## load this library if you want to 'print' the sf object to console
geo <- geojsonsf::geojson_sf("http://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_040_00_500k.json")
## sf::st_read("http://eric.clst.org/...") is just as quick.
## geo is now an `sf` object
cali <- geo[geo$NAME == "California", ]
set_key("GOOGLE_MAP_KEY")
google_map() %>%
add_polygons(data = cali, z_index = 1, fill_opacity = 1) %>%
add_kml(kml_url = 'http://www.energy.ca.gov/maps/renewable/BuildingClimateZonesMap.kmz',
update_map_view = T, z_index = 2)
Reference: There is a zIndex property
But it doesn't appear to work, even when layering KMLs
google_map() %>%
add_kml(kml_url = 'http://www.energy.ca.gov/maps/renewable/BuildingClimateZonesMap.kmz',
update_map_view = T, z_index = 2, layer_id = "building") %>%
add_kml(kml_url = 'http://www.energy.ca.gov/maps/renewable/renewable_development.kmz',
update_map_view = T, z_index = 1, layer_id = "renewable")
Have asked this question on SO. Apparently it should work...
I can confirm the z_index
value does work with this example
google_map() %>%
add_kml(
kml_url = "http://www.geocodezip.com/geoxml3_test/kml/TopMarker.kml"
, z_index = 2
) %>%
add_kml(
kml_url = "http://www.geocodezip.com/geoxml3_test/kml/MiddleSquare.kml"
, z_index = 1
) %>%
add_kml(
kml_url = "http://www.geocodezip.com/geoxml3_test/kml/BottomParallelogram.kml"
, z_index = 3
)
as per one of the comments to the question. Maybe it has to do with the KML layers themselves?
Here's a screenshot of clicking the 'marker', but displaying the info window for the parallelogram (the highest z_index
I'm going to merge this into master (because the z_index
is working), but keep the issue open
@mosscoder I don't suppose you have any extra insight as to why your KML layers aren't obeying the z_index
property?
Greetings, I would like to display a KML layer on top of a GeoJSON layer, however, my KML layer is drawn first (below) the GeoJSON layer, no matter which is added first.