From 9c703b50aa4f382a882a5d142bb11d313188833f Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sun, 19 Apr 2020 22:47:35 +0200 Subject: Import L.LabelTextCollision.js and ctxtextpath.js into repo --- htdocs/leafletjs/ctxtextpath.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 htdocs/leafletjs/ctxtextpath.js (limited to 'htdocs/leafletjs/ctxtextpath.js') diff --git a/htdocs/leafletjs/ctxtextpath.js b/htdocs/leafletjs/ctxtextpath.js new file mode 100644 index 0000000..c9389cb --- /dev/null +++ b/htdocs/leafletjs/ctxtextpath.js @@ -0,0 +1,35 @@ +(function() +{function dist2D(x1,y1,x2,y2) +{var dx=x2-x1;var dy=y2-y1;return Math.sqrt(dx*dx+dy*dy);} +CanvasRenderingContext2D.prototype.textOverflow="";CanvasRenderingContext2D.prototype.textJustify=false;CanvasRenderingContext2D.prototype.textStrokeMin=0;var state=[];var save=CanvasRenderingContext2D.prototype.save;CanvasRenderingContext2D.prototype.save=function() +{state.push({textOverflow:this.textOverflow,textJustify:this.textJustify,textStrokeMin:this.textStrokeMin,});save.call(this);} +var restore=CanvasRenderingContext2D.prototype.restore;CanvasRenderingContext2D.prototype.restore=function() +{restore.call(this);var s=state.pop();this.textOverflow=s.textOverflow;this.textJustify=s.textJustify;this.textStrokeMin=s.textStrokeMin;} +CanvasRenderingContext2D.prototype.textPath=function(text,path) +{var di,dpos=0;var pos=2;function pointAt(dl) +{if(!di||dpos+didl)break;pos+=2;if(pos>=path.length)break;dpos+=di;}} +var x,y,dt=dl-dpos;if(pos>=path.length) +{pos=path.length-2;} +if(!dt) +{x=path[pos-2];y=path[pos-1];} +else +{x=path[pos-2]+(path[pos]-path[pos-2])*dt/di;y=path[pos-1]+(path[pos+1]-path[pos-1])*dt/di;} +return[x,y,Math.atan2(path[pos+1]-path[pos-1],path[pos]-path[pos-2])];} +var letterPadding=this.measureText(" ").width*0.25;var d=0;for(var i=2;i0.1)this.strokeText(letter,0,0);this.fillText(letter,0,0);this.restore();start+=wl+letterPadding*(letter==" "?2:1);}};})(); \ No newline at end of file -- cgit v1.2.3