This is very special. I have some pathes (imagine them as rivers on a map) and want them to give a name.
This code is working properly. It is creating pathes and after that writing the text on thos lines:
function draw_rivertext(){
var featureCollection = topojson.feature(currentMap, currentMap.objects.text);
svgmap.append("g")
.selectAll("path")
.data(featureCollection.features)
.enter().append("path")
.attr("d", path)
.attr("class", "helperline")
.attr("id", function(d) {return "path"+d.properties.id});
svgmap.append("text")
.selectAll("text")
.data(featureCollection.features)
.enter()
.append("textPath")
.attr("class", "helperline-text")
.attr("xlink:href", function(d) {return "#path"+d.properties.id})
.text(function(d) {return d.properties.name});
}
But the issue is that the text has just one font-size. So let's say I have a long river and a short. So the short river should be super small instead of the exact same huhge size.
So my idea was to set on the text:
.attr("font-size", "10")
and here the value 10 needs to be that current size from the path id. I really don't have an idea how to do that.
Here some links concerning this topic:
- https://www.safaribooksonline.com/library/view/svg-essentials/0596002238/ch08s05.html
- SVG textpath, determine when text goes beyond the path
- how to set font size based on container size?
- http://eyeseast.github.io/visible-data/2013/08/26/responsive-d3/
- https://milkator.wordpress.com/2013/02/25/making-a-map-of-germany-with-topojson/
I also found some that are resampling the font-size and so on after creating it with jQuery. Well that would be for sure a solution. Getting the path sizes; resampling the text attributes on that values. But I don't think that's a proper solution.
Another idea could also be to specify the font-size in the topojson as an own parameter. But ohh lord this would be try and error as there is no real measuring in QGIS for this.