Mapbox Bright wont render: Did I leave a command out? - dictionary

Using Folium but cant render a map with a "Mapbox Bright" tiling. However I can render a "Stamen Toner" tiling. Am I leaving out a command?
Ran code on both windows and linux platforms,
in the cloud and local,
in both firefox and chrome.
libraries installed via pip install folium or conda install
Code should execute:
import webbrowser
import folium
world_map_stamen = folium.Map(location=[56.130, -106.35], tiles="Stamen Toner",zoom_start=4,height=500, width=1000)
world_map_mapbox = folium.Map(location=[56.130, -106.35], tiles="Mapbox Bright",zoom_start=4,height=500, width=1000)
world_map_stamen.save("mymap_stamen.html")
world_map_mapbox.save("mymap_mapbox.html")
webbrowser.open("mymap_stamen.html")
webbrowser.open("mymap_mapbox.html")
I expected both to work. Only one did. I must be forgetting something?

Found my own answer and this question has been answered elsewhere in various forms....
But it seem like there are two answers:
(1) Mapbox maps are no longer supported in folium 0.9 so Mapbox maps must be called using an attribution and custom tile call:
mymap = folium.Map(location=[30,-83], zoom_start=2,tiles= tileset_id,
attr="any text here")
where tileset_id = "http://api.mapbox.com/v4/mapbox.light/{z}/{x}/{y}.png?access_token=pk.xxx" (where pk.xxx is your API token from mapbox (go sign up))
see https://gis.stackexchange.com/questions/203062/how-do-i-use-mapbox-tiles-with-folium
(2) the tilesets that are free are listed in another post and no longer include mapbox bright. see
https://gis.stackexchange.com/questions/244788/map-ids-to-add-mapbox-basemaps-to-leaflet-or-openlayers

Related

leaflet tiles with protomaps pmtiles are not visibles (seems to be transparent)

i'm using our own pmtiles tileset server, the test url is : https://tilesets.urbanease.io/cadastre/64/64102/without_protobuf.pmtiles
the location for seeing it is :bayonne, france latlng=[43.492949,-1.474841]
on the viewer, all seems to be ok bit leaflet preview don't work viewer
i'm using react and leaflet with the npm protomaps package version 1.19.0
my code is simple
const map = useMap();
const url =
'https://tilesets.urbanease.io/cadastre/64/64102/without_protobuf.pmtiles';
const layer = protomaps.leafletLayer({
url: url,
id: 'cadastral',
});
layer.addTo(map);
canvas are created but seems to be transparent, colors in paint_rules layer are good and opacity ok
i don't understand where is the pb bad pmtiles file? no compatibility with leaflet?
thx for help
it was our custom layer name who don't mach to default paint_rules of protomaps package,
with custom paint_rules it works fine

How to add ArcGIS server layer using leaflet.esri package?

I am trying to add a layer from a published ArcGIS service feature into a leaflet map in R using the leaflet.esri package.
I've read the documentations here https://rdrr.io/cran/leaflet.esri/man/addEsriTiledMapLayer.html and here https://cran.r-project.org/web/packages/leaflet.esri/leaflet.esri.pdf and have tested the examples
My code looks like this:
library(leaflet)
library(leaflet.esri)
leaflet() %>% setView(lng = 55.0876632, lat = 25.0755935, zoom = 10) %>%
addEsriTiledMapLayer(
url = "https://smart.gis.gov.ae/dmgis104/rest/services/Misc/Env_Imagery/MapServer")
Update: Note that no username or password is required.
I've confirmed that url works by adding it as an ArcGIS server in ArcCatalog, but when I try to run the above in R I just get a blank leaflet map.
How do I specify which layer from the above url to load? There are a number of layers available at that url, such as "Misc/IMAGE2018" and I would like to load these into leaflet.
I am a bit confused as well because when I inspect the url in ArcCatlog it shortens it to "Server URL: https://smart.gis.gov.ae/dmgis104/services" instead of the above, but I am not sure if that matters. See screen shot below as example of ArcCatlog.
Thanks in advance
the issue is that your map service doesn't use the typical web mercator projection and tiling scheme.
you can find an example which includes extra code to explicitly define a custom projection here: http://esri.github.io/esri-leaflet/examples/non-mercator-projection.html

Bokeh EditTools callback to server

I am trying to understand how to use callbacks for the new Bokeh EditTools (e.g. BoxEditTool or similar).
Specifically, I would like to see on the server side the coordinates of the newly added rectangles, but I am not sure how to do this.
I am running the following server app
def app( curdoc ):
TOOLS = "tap"
p = figure(title="Some Figure", tools=TOOLS)
source = ColumnDataSource( {'xs':[1], 'ys':[1], 'width':[.1],'height':[.1]})
r = p.rect('xs','ys','width','height', source=source)
p.add_tools(BoxEditTool( renderers = [r]))
def cb( attr, old, new ):
print(r.data_source.data)
r.data_source.on_change("selected", cb)
curdoc.add_root(column(p))
I do get printout from the cb when I select different rectangles, but the r.data_source.data does not change
Thanks for the help!
The behaviour you're describing is actually a bug in the current distribution of Bokeh (0.13.0). You can read more in the google groups discussion. To summarize, there was a problem with the synchronization of the data at the server, it has been resolved and merged.
Note that the on_change method for the Rect glyph ColumnDataSource should watch the 'data' attribute and not 'selected'.
Other than that your snippet looks good, but if you want a working example you can look here. This code is under development but at this stage it reads images and allows drawing ROIs, as well as a simple mechanism for serializing and loading them.
Hope this helps!

LeafletR map not showing in browser

I'm looking for guidance on getting a basic example of leafletR package to show a map in the browser. Working with the most basic example, the map doesn't show up in the browser. I've checked the .html and .json files, which are present and appear to properly formatted. Javascript inspector shows this error:
XMLHttpRequest cannot load file:///var/folders/_0/tdgf_k7x77qdn64_gk9ynljm0000gp/T/Rtmp6O4QZM/Fiji_Earthquakes/quakes.geojson. Received an invalid response. Origin 'null' is therefore not allowed access.
I'm on a Mac: OSX 10.7.5
RStudio Version: 0.98.857
Code
library(leafletR)
data(quakes)
# store data in GeoJSON file (just a subset here)
q.dat <- toGeoJSON(data=quakes[1:99,], dest=tempdir(), name="quakes")
# make style based on quake magnitude
q.style <- styleGrad(prop="mag", breaks=seq(4, 6.5, by=0.5), style.val=rev(heat.colors(5)), leg="Richter Magnitude", fill.alpha=0.7, rad=8)
# create map
q.map <- leaflet(data=q.dat, dest=tempdir(), title="Fiji Earthquakes", base.map="osm", style=q.style, popup="mag")
# view map in browser
browseURL(q.map)
Thank you in advance for any advise.
A quick solution to open the map using a local web server is to take advantage of RStudio's HTML viewer.
rstudio::viewer(qmap)
The trick is to include incl.data=TRUE in the leaflet function. For example,
map<-leaflet(data=leafdat, dest=downloaddir, style=sty,
title="index", base.map="osm",
incl.data=TRUE, popup=popup)
Check out this post that shows how to do this in detail.

Can't display Leaflet HTML through R-Shiny (404 error). How to integrate KML file with rMaps or leaflet-shiny?

I'm having some issues displaying an interactive map in R-Shiny that incorporates a KML file. I installed leaflet-plugins and was able to create an HTML file that displays properly by itself in the browser but not within Shiny. This attempt followed an example here - the code is available if you view source.
Because this initial version does not require the HTML itself to change, I attempted to follow the samples here to include the raw HTML in my page but I receive a 404 error with these as well as when I attempted to include it as an iframe within R-Shiny (following this discussion). I then set up an external facing server for both the KML file and the HTML file and got the same result.
I was able to get a map working without the KML file with leaflet-shiny but I'm frankly not sure how to add the KML file and don't see this in the documentation.
Finally, I tried rMaps which does have a "addKML" method, but I can't get it working with various locations of files on my server (
map1 = Leaflet$new()
map1$setView(c(45.5236, -122.675), 13)
map1$tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
map1$addKML('http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml')
map1
It works without the $addKML line. It might be worth noting that the tilelayer line on example 1 here also resulted in a blank map.
I actually have some possibly similar issues hosting derived title layers that are still unresolved which is one reason I opted for uses KML layers for this demo version of the application, which is why I tagged networking on here as well. I'm using Digital Ocean.
Thank you for any thoughts or pointers you may have.
I think there may be a small issue in the rMaps library. If you inspect the config.yml file
https://github.com/ramnathv/rCharts/blob/master/inst/libraries/leaflet/config.yml you will see that for
content delevery network (cdn) there is reference to
"http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js". This KML reader is a plugin for leaflet from https://github.com/shramov/leaflet-plugins/blob/master/layer/vector/KML.js. When content is delivered locally:
css: [external/leaflet.css, external/leaflet-rCharts.css, external/legend.css]
jshead:
- external/leaflet.js
- external/leaflet-providers.js
- external/Control.FullScreen.js
there is no reference to this javascript file. We can fix this:
require(yaml)
leafletLib <- file.path(find.package("rMaps"), "libraries", "leaflet")
rMapsConfig <- yaml.load_file(file.path(leafletLib, "config.yml"))
# add a kml library
kmlLib <- readLines("http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js")
write(kmlLib, file.path(leafletLib, "external", "leaflet-kml.js"))
# add the library to config.yml
rMapsConfig$leaflet$jshead <- union(rMapsConfig$leaflet$jshead , "external/leaflet-kml.js")
write(as.yaml(rMapsConfig), file.path(leafletLib, "config.yml"))
Now the config.yml will contain the necessary link to the KML reader and there is a local copy stored now in external/leaflet-kml.js. Our example still wont work however as we will get a Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml. This can be fixed by moving the resource to the same domain or enabling CORS.
We will need to have this file served locally. We can place it as a temporary measure in the leaflet folder in the rMaps package. When a map is created this folder gets copied to a temporary file:
require(rMaps)
map1 = Leaflet$new()
map1$setView(c(45.5236, -122.675), 13)
map1$tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
map1$addKML('leaflet/placemark.kml')
# temp copy http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml
# to rMaps
sampleKml <- readLines('http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml')
write(sampleKml, file.path(leafletLib, 'placemark.kml'))
# finally try the map
map1
# remove the temp file
file.remove(file.path(leafletLib, 'placemark.kml'))
UPDATE:
There is an addAssets method in rCharts which allows you to add .js files. This allows us to simpilfy things and doesnt require us to write a copy of the js file nor edit the config.yml file.
require(rMaps)
map1 = Leaflet$new()
map1$setView(c(45.5236, -122.675), 13)
map1$tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
map1$addAssets(css = NULL, jshead = 'http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js')
map1$addKML('leaflet/placemark.kml')
leafletLib <- file.path(find.package("rMaps"), "libraries", "leaflet")
sampleKml <- readLines('http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml')
write(sampleKml, file.path(leafletLib, 'placemark.kml'))
# finally try the map
map1
# remove the temp file
file.remove(file.path(leafletLib, 'placemark.kml'))

Resources