Skip to content

Commit

Permalink
Handle different icons
Browse files Browse the repository at this point in the history
  • Loading branch information
bagage committed Oct 16, 2019
1 parent b736827 commit 8b52d3c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
Binary file added examples/icon-draw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/icon-end.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/icon-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/icon-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
}
}
}
,icons: {
start: new L.Icon({iconUrl: 'icon-start.png'})
,end: new L.Icon({iconUrl: 'icon-end.png'})
,normal: new L.Icon({iconUrl: 'icon-normal.png'})
,draw: new L.Icon({iconUrl: 'icon-draw.png'})
}
,snapping: {
layers: []
}
Expand Down
20 changes: 20 additions & 0 deletions src/L.Routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ L.Routing = L.Control.extend({
,timeoutID : null
};

var icons = this.options.icons;
if (!prev) {
marker.setIcon(icons.start);
} else if (!next) {
marker.setIcon(icons.end);
} else {
marker.setIcon(icons.normal);
}

console.log(prev,marker,next);
if (this._waypoints._first && next && next._leaflet_id === this._waypoints._first._leaflet_id) {
next.setIcon(icons.normal);
}
if (this._waypoints._last && prev && prev._leaflet_id === this._waypoints._last._leaflet_id && prev._leaflet_id !== this._waypoints._first._leaflet_id) {
prev.setIcon(icons.normal);
}


if (this._waypoints._first === null && this._waypoints._last === null) {
this._waypoints._first = marker;
this._waypoints._last = marker;
Expand Down Expand Up @@ -246,10 +264,12 @@ L.Routing = L.Control.extend({

if (this._waypoints._first && marker._leaflet_id === this._waypoints._first._leaflet_id) {
this._waypoints._first = next;
next.setIcon(this.options.icons.start);
}

if (this._waypoints._last && marker._leaflet_id === this._waypoints._last._leaflet_id) {
this._waypoints._last = prev;
prev.setIcon(this.options.icons.end);
}

if (prev !== null) {
Expand Down

0 comments on commit 8b52d3c

Please sign in to comment.