diff --git a/leaflet.polylineDecorator.js b/leaflet.polylineDecorator.js index aa774aa..f1b506e 100644 --- a/leaflet.polylineDecorator.js +++ b/leaflet.polylineDecorator.js @@ -316,261 +316,264 @@ L.Symbol.marker = function (options) { }; - -L.PolylineDecorator = L.LayerGroup.extend({ - options: { - patterns: [] - }, - - initialize: function(paths, options) { - L.LayerGroup.prototype.initialize.call(this); - L.Util.setOptions(this, options); - this._map = null; - this._initPaths(paths); - this._initPatterns(); - }, - - /** - * Deals with all the different cases. p can be one of these types: - * array of LatLng, array of 2-number arrays, Polyline, Polygon, - * array of one of the previous, MultiPolyline, MultiPolygon. - */ - _initPaths: function(p) { - this._paths = []; - var isPolygon = false; - if(p instanceof L.MultiPolyline || (isPolygon = (p instanceof L.MultiPolygon))) { - var lines = p.getLatLngs(); - for(var i=0; i 0) { - if(p[0] instanceof L.Polyline) { - for(var i=0; i 0 && ( - ll[0] instanceof L.LatLng || - (L.Util.isArray(ll[0]) && ll[0].length == 2 && typeof ll[0][0] === 'number') - )); - }, - - _initPath: function(path, isPolygon) { - var latLngs; - // It may still be an array of array of coordinates - // (ex: polygon with rings) - if(this._isCoordArray(path)) { - latLngs = [path]; - } else { - latLngs = path; - } - for(var i=0; i= v0.6, last polygon vertex (=first) isn't repeated. - // Our algorithm needs it, so we add it back explicitly. - if(isPolygon) { - latLngs[i].push(latLngs[i][0]); - } - this._paths.push(latLngs[i]); - } - }, - - _initPatterns: function() { - this._isZoomDependant = false; - this._patterns = []; - var pattern; - // parse pattern definitions and precompute some values - for(var i=0;i 0); - } - - - if(typeof patternDef.repeat === 'string' && patternDef.repeat.indexOf('%') != -1) { - pattern.repeat = parseFloat(patternDef.repeat) / 100; - } else { - pattern.repeat = parseFloat(patternDef.repeat); - pattern.isRepeatInPixels = (pattern.repeat > 0); - } - - // TODO: 0 => not pixel dependant => 0% - - return(pattern); - }, - - onAdd: function (map) { - this._map = map; - this._draw(); - // listen to zoom changes to redraw pixel-spaced patterns - if(this._isZoomDependant) { - this._map.on('zoomend', this._softRedraw, this); - } - }, - - onRemove: function (map) { - // remove optional map zoom listener - this._map.off('zoomend', this._softRedraw, this); - this._map = null; - L.LayerGroup.prototype.onRemove.call(this, map); - }, - - /** - * Returns an array of ILayers object - */ - _buildSymbols: function(latLngs, symbolFactory, directionPoints) { - var symbols = []; - for(var i=0, l=directionPoints.length; i 0) { + if(p[0] instanceof L.Polyline) { + for(var i=0; i 0 && ( + ll[0] instanceof L.LatLng || + (L.Util.isArray(ll[0]) && ll[0].length == 2 && typeof ll[0][0] === 'number') + )); + }, + + _initPath: function(path, isPolygon) { + var latLngs; + // It may still be an array of array of coordinates + // (ex: polygon with rings) + if(this._isCoordArray(path)) { + latLngs = [path]; + } else { + latLngs = path; + } + for(var i=0; i= v0.6, last polygon vertex (=first) isn't repeated. + // Our algorithm needs it, so we add it back explicitly. + if(isPolygon) { + latLngs[i].push(latLngs[i][0]); + } + this._paths.push(latLngs[i]); + } + }, + + _initPatterns: function() { + this._isZoomDependant = false; + this._patterns = []; + var pattern; + // parse pattern definitions and precompute some values + for(var i=0;i 0); + } + + + if(typeof patternDef.repeat === 'string' && patternDef.repeat.indexOf('%') != -1) { + pattern.repeat = parseFloat(patternDef.repeat) / 100; + } else { + pattern.repeat = parseFloat(patternDef.repeat); + pattern.isRepeatInPixels = (pattern.repeat > 0); + } + + // TODO: 0 => not pixel dependant => 0% + + return(pattern); + }, + + onAdd: function (map) { + this._map = map; + this._draw(); + // listen to zoom changes to redraw pixel-spaced patterns + if(this._isZoomDependant) { + this._map.on('moveend', this._softRedraw, this); + } + }, + + onRemove: function (map) { + // remove optional map zoom listener + this._map.off('moveend', this._softRedraw, this); + this._map = null; + L.LayerGroup.prototype.onRemove.call(this, map); + }, + + /** + * Returns an array of ILayers object + */ + _buildSymbols: function(latLngs, symbolFactory, directionPoints) { + var symbols = []; + for(var i=0, l=directionPoints.length; ib)return 0;for(var c=0,d=a[0],e=1;ed)return 0;for(var e=0,f=b.project(c[0]),g=1;gc)return null;if(0>=b)return{pt:a[0],predecessor:0,heading:this.computeAngle(a[0],a[1])};if(1<=b)return{pt:a[c-1],predecessor:c-1,heading:this.computeAngle(a[c-2],a[c-1])};if(2==c)return{pt:this.interpolateBetweenPoints(a[0],a[1],b),predecessor:0,heading:this.computeAngle(a[0],a[1])};for(var d=this.getPointPathPixelLength(a),e=a[0],f=e,g=0,h=0,k=0,j=1;j=b.pixelSize)return new L.Polyline([a.latLng,a.latLng],b.pathOptions);var d=c.project(a.latLng);a=-(a.heading-90)*L.LatLng.DEG_TO_RAD;a=new L.Point(d.x+b.pixelSize*Math.cos(a+Math.PI)/2,d.y+b.pixelSize*Math.sin(a)/2);d=d.add(d.subtract(a));return new L.Polyline([c.unproject(a),c.unproject(d)], -b.pathOptions)}});L.Symbol.dash=function(a){return new L.Symbol.Dash(a)}; -L.Symbol.ArrowHead=L.Class.extend({isZoomDependant:!0,options:{polygon:!0,pixelSize:10,headAngle:60,pathOptions:{stroke:!1,weight:2}},initialize:function(a){L.Util.setOptions(this,a);this.options.pathOptions.clickable=!1},buildSymbol:function(a,b,c){b=this.options;return b.polygon?new L.Polygon(this._buildArrowPath(a,c),b.pathOptions):new L.Polyline(this._buildArrowPath(a,c),b.pathOptions)},_buildArrowPath:function(a,b){var c=b.project(a.latLng),d=-(a.heading-90)*L.LatLng.DEG_TO_RAD,e=this.options.headAngle/ -2*L.LatLng.DEG_TO_RAD,f=d+e,d=d-e,f=new L.Point(c.x-this.options.pixelSize*Math.cos(f),c.y+this.options.pixelSize*Math.sin(f)),c=new L.Point(c.x-this.options.pixelSize*Math.cos(d),c.y+this.options.pixelSize*Math.sin(d));return[b.unproject(f),a.latLng,b.unproject(c)]}});L.Symbol.arrowHead=function(a){return new L.Symbol.ArrowHead(a)}; -L.Symbol.Marker=L.Class.extend({isZoomDependant:!1,options:{markerOptions:{},rotate:!1},initialize:function(a){L.Util.setOptions(this,a);this.options.markerOptions.clickable=!1;this.options.markerOptions.draggable=!1;this.isZoomDependant=L.Browser.ie&&this.options.rotate},buildSymbol:function(a){return this.options.rotate?(this.options.markerOptions.angle=a.heading,new L.RotatedMarker(a.latLng,this.options.markerOptions)):new L.Marker(a.latLng,this.options.markerOptions)}});L.Symbol.marker=function(a){return new L.Symbol.Marker(a)};L.PolylineDecorator=L.LayerGroup.extend({options:{patterns:[]},initialize:function(a,b){L.LayerGroup.prototype.initialize.call(this);L.Util.setOptions(this,b);this._map=null;this._initPaths(a);this._initPatterns()},_initPaths:function(a){this._paths=[];var b=!1;if(a instanceof L.MultiPolyline||(b=a instanceof L.MultiPolygon)){a=a.getLatLngs();for(var c=0;c0){var remainingPath=pts;remainingPath=remainingPath.slice(previous.predecessor);remainingPath[0]=previous.pt;var remainingLength=this.getPointPathPixelLength(remainingPath);while(repeatIntervalLength<=remainingLength){previous=this.interpolateOnPointPath(remainingPath,repeatIntervalLength/remainingLength);positions.push(previous);remainingPath=remainingPath.slice(previous.predecessor);remainingPath[0]=previous.pt;remainingLength=this.getPointPathPixelLength(remainingPath)}}return positions},interpolateOnPointPath:function(pts,ratio){var nbVertices=pts.length;if(nbVertices<2){return null}if(ratio<=0){return{pt:pts[0],predecessor:0,heading:this.computeAngle(pts[0],pts[1])}}if(ratio>=1){return{pt:pts[nbVertices-1],predecessor:nbVertices-1,heading:this.computeAngle(pts[nbVertices-2],pts[nbVertices-1])}}if(nbVertices==2){return{pt:this.interpolateBetweenPoints(pts[0],pts[1],ratio),predecessor:0,heading:this.computeAngle(pts[0],pts[1])}}var pathLength=this.getPointPathPixelLength(pts);var a=pts[0],b=a,ratioA=0,ratioB=0,distB=0;var i=1;for(;i0){if(p[0]instanceof L.Polyline){for(var i=0;i0&&(ll[0]instanceof L.LatLng||L.Util.isArray(ll[0])&&ll[0].length==2&&typeof ll[0][0]==="number")},_initPath:function(path,isPolygon){var latLngs;if(this._isCoordArray(path)){latLngs=[path]}else{latLngs=path}for(var i=0;i0}if(typeof patternDef.repeat==="string"&&patternDef.repeat.indexOf("%")!=-1){pattern.repeat=parseFloat(patternDef.repeat)/100}else{pattern.repeat=parseFloat(patternDef.repeat);pattern.isRepeatInPixels=pattern.repeat>0}return pattern},onAdd:function(map){this._map=map;this._draw();if(this._isZoomDependant){this._map.on("moveend",this._softRedraw,this)}},onRemove:function(map){this._map.off("moveend",this._softRedraw,this);this._map=null;L.LayerGroup.prototype.onRemove.call(this,map)},_buildSymbols:function(latLngs,symbolFactory,directionPoints){var symbols=[];for(var i=0,l=directionPoints.length;i