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 6, 2019
1 parent b736827 commit 8c41d9c
Show file tree
Hide file tree
Showing 6 changed files with 25 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
19 changes: 19 additions & 0 deletions src/L.Routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ 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);
}

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.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 +263,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 8c41d9c

Please sign in to comment.