invert polygons and set opacity and color of outside
I am using tiles with addProviderTiles and to display a city map below my polygon map.
I would like to mask off the part of the map outside of the city border.
I have a polygon for the city border.
So a solution to my problem would be to either set the color and/or opacity of the outside of the polygon, or to invert the polygon and then set the color and/or opacity of the outside polygon.
Can this be done already?
I'd like to know if this is possible as well! Anyone?
I'm not familiar with R, but for leaflet js there's a plugin called leaflet.snogylop that does exactly that. Maybe you can source the code for an implementation in R.
Hi Guys,
There is a way to apply the same approach used leaflet.snoglop in R leaflet?
Thanks
Restarting this thread. I've got a shapefile of Texas with a basemap underneath. Is it possible to hide or clip the basemap that falls outside of the state's borders?
We solved this via inverting the polygon (in your case, the Texas shapefile) in QGIS. For this, you need a second layer that surrounds your polygon. For example, you could draw a bounding box around it in QGIS (Toggle editing > Add polygon feature and then draw freehand). Then, running Vector > Geoprocessing Tools > Difference with the bounding box as Input Layer and the Texas shapefile as Overlay layer yields a new layer: the bounding box with a hole at the place of Texas.
Another possibility is to merge these two layers (the bounding box and the Texas shapefile) via Vector > Geoprocessing Tools > Union. This leaves the possibility to still color both parts of the layer, for example with different levels of opacity.
snogylop seems to do exactly the same, inverting a polygon, directly on a running leaflet map. As in our case, it would always be the very same polygons to invert, we decided to compute it once beforehand instead of computing it over and over again.