folium custom map tiles - leaflet

I want to add this map tile layer to my map – Stamen toner-background.
As I read in documentation I need to simply give custom url in the tiles attribute of map
mapa = folium.Map(width=1000, height=700, zoom_start=5.5,
location=[52.5, 19], tiles='http://maps.stamen.com/toner-background/embed#6/{x}/{z}', attr="toner-bcg")
It loads but nothing is displayed.
I don't really know how this attribution thing works like and what should I do. I like the tile because it's like stamen toner but without country names and that makes my map a lot more beautiful.

This is your lucky day, Stamen designs are built-in in Folium. You should run the following code:
mapa = folium.Map(width=1000, height=700, zoom_start=5.5,
location=[52.5, 19], tiles='Stamen Toner')
This should solve the issue.
The reason your code was not working is because you were not using the correct URL templates. The format is one specified here:
http://tile.stamen.com/toner/{z}/{x}/{y}.png
http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg
http://tile.stamen.com/watercolor/{z}/{x}/{y}.jpg
The code would look like this:
mapa = folium.Map(width=1000, height=700, zoom_start=5.5,
location=[52.5, 19], tiles='http://tile.stamen.com/toner/{z}/{x}/{y}.png ')

To improve Fernando's answer, the below code works for me:
mapa = folium.Map(width=1000, height=700, zoom_start=5.5,
location=[52.5, 19],
tiles='http://tile.stamen.com/toner/{z}/{x}/{y}.png ',
attr="toner-bcg") # <-- note this

Related

Is there a way to have the layer checkboxes checked from the beginning on my leaflet map?

Im currently creating a map with leaflet and as the page loads all the checkboxes of my created layers are unchecked and im looking for a possibility to have them checked from the beginning, is there any way to do so?
Im a beginner when it comes to coding, did some research online and on the leaflet website but couldn't find any answer to my problem.
in the following code, the s0001 are my markers.
var BE = L.layerGroup([s0001]);
var GE = L.layerGroup([s0002]);
var ZH = L.layerGroup([s0003]);
var kantone = {
"Bern": BE,
"Genf": GE,
"Zürich": ZH,
};
L.control.layers(null, kantone).addTo(map);
Is this part of the code enough or do i need to put more of the code in my question?
Do i need to add/remove code or change up the code to make it work to have the checkboxes already checked as i load the page?
Many thanks in advance for your help and comprehension of me being a beginner !!
If you add some/all of the layerGroups to the map before you add the layers control, they will show up checked.
eg
var BE = L.layerGroup([s0001]).addTo(map);
var GE = L.layerGroup([s0002]).addTo(map);
var ZH = L.layerGroup([s0003]).addTo(map);
var kantone = {
"Bern": BE,
"Genf": GE,
"Zürich": ZH,
};
L.control.layers(null, kantone).addTo(map);

How to extract GeoJSON/WKT from drawn layer in Leaflet?

I would like to extract coordinates in GeoJSON/WKT format from user drawn polygon. I found next code:
drawnItems = new L.FeatureGroup();
drawnItems.addLayer(layer);
myjson = drawnItems.toGeoJSON();
console.log(myjson)
But in console I see only Object {__ob__: Observer} like this
I used example from here
What I am doing wrong?
If you were expecting to get a string, then you just missed the JSON.stringify(myjson) on the next line of the example you refer to.

I am using leaflet on Rstudio but the map doesn't show up

I started a few days ago to learn about shiny and leaflet pakages, this question is maybe irrelevant but I looked for an answer to my problem and didn't found any.
Well, I am trying to create an interactive map, with a base map that I've got from internet. I would like to represent on this map the evolution of an index across the country.
stypof <- readOGR(dsn = "C:/Users/N4XW6M/Desktop/nouvelle map/fonds typo propre.TAB", layer = "fonds typo propre", stringsAsFactors = FALSE)
names(stypof#data)<-c("typo")
fond<-data.frame(stypof#data$typo)
names(fond)<-c("typo")
new_indice_mois <- sqldf("SELECT indice_mois.*
FROM indice_mois, fond
WHERE indice_mois.typo = fond.typo")
stypof$indice_fevrier <- new_indice_mois$indice_fevrier
leaflet(stypof) %>%
addPolygons(
stroke = FALSE, fillOpacity = 0.5, smoothFactor = 0.5,
color = ~colorQuantile("YlOrRd", stypof#data$indice_fevrier)(indice_fevrier)
)
In a first step I import the base map using readOGR.
Some areas are not represented in the base map that's why I use the sqldf function, then I add the index (indice_fevrier) to the map and try to use the leaflet function.
I get no error message only an empty map.
I tryed some other examples that I found on internet and I always have the same issue the map doesn't appear.
According to this post, you have to click on "Show in new Window" for the map to show.

Mapbox Directions API addWaypoint

I am working on a application and I want to get directions for more than 2 points
Which I assume other than origin and destination other locations are waypoints.
So I am trying to use directions.setWaypoint() to add waypoints to the map but it doesn't work
please help for me to understand what I do wrong.
I have created a JsFiddle https://jsfiddle.net/3uzm1nh0/1/
and this is the documentation I am referring to https://github.com/mapbox/mapbox-directions.js/blob/mb-pages/API.md
Thanks in advance.
You need someting like this
// = L.mapbox.directions({profile: 'mapbox.driving'})
var directions = L.mapbox.directions();
var directionsLayer = L.mapbox.directions.layer(directions).addTo(map);
var directionsRoutesControl = L.mapbox.directions.routesControl('routes', directions).addTo(map);
directions.setOrigin(L.latLng(14.6059596413528, -90.49169592683657));
directions.addWaypoint(0,L.latLng(14.60026436463006, -90.49669902226937));
directions.addWaypoint(1,L.latLng(14.59689160135752, -90.49520561914318));
directions.addWaypoint(2,L.latLng(14.60036292858185, -90.49586222238077));
directions.setDestination(L.latLng(14.6059596413528, -90.49169592683657));
directions.query();

How to transform a GWT OpenLayers VectorFeature?

I am using OpenLayers GWT. I want to put an GeoJSON shape on top of a Google Maps layer. I have done as follows:
String gson = "{here I put a valid GeoJSON string}";
GeoJSON geoJSON = new GeoJSON();
VectorFeature[] vf = geoJSON.read(gson);
myShapeLayer.addFeature(vf[0]);
The shape is showing on the map, but not a the right position. I think I have to transform the Vector to EPSG:900913 but I don't know how to do that with the VectorFeature. There is no transform function to use.
How can I apply the transformation to a GWT VectorFeature?
This question is not getting responses. I would like to explain better what I want to know:
In javascript Openlayers you can do:
var projWGS84 = new OpenLayers.Projection("EPSG:4326");
var proj900913 = new OpenLayers.Projection("EPSG:900913");
feature.geometry.transform(projWGS84, proj900913);
How can I do the same in the GWT version of OpenLayers?
Thanks in advance.
OpenLayers-GWT is missing the GeoJSON constructor that will take an options parameter, this has to be added in the OpenLayers-GWT source. In the mean time this has been added to the KML Vector class. So now you can do like this:
String kmlString = "{<string with KML>}";
FormatOptions formatOptions = new FormatOptions();
formatOptions.setInternalProjection(new Projection("EPSG:900913"));
formatOptions.setExternalProjection(new Projection("EPSG:4326"));
KML kml = new KML(formatOptions);
VectorFeature[] vf = KML.read(kmlString);
myShapeLayer.addFeature(vf[0]);
In the same way it should be added to the GeoJSON class to make the tranformation work.