Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't paint lines for the first and last points properly. #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions Leaflet.MultiOptionsPolyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,34 @@ var MultiOptionsPolyline = L.FeatureGroup.extend({
multiOptions = this._options.multiOptions,
optionIdxFn = multiOptions.optionIdxFn,
fnContext = multiOptions.fnContext || this,
prevOptionIdx, optionIdx,
segmentLatlngs;
nextOptionsIdx, optionIdx,
segmentLatlngs = [];

this._originalLatlngs = latlngs;

this.eachLayer(function (layer) {
this.removeLayer(layer);
}, this);

for (i = 1; i < len; ++i) {
optionIdx = optionIdxFn.call(
fnContext, latlngs[i], latlngs[i - 1], i, latlngs);
for (i = 0; i < len; ++i) {

if (i === 1) {
segmentLatlngs = [latlngs[0]];
prevOptionIdx = optionIdxFn.call(fnContext, latlngs[0], latlngs[0], 0, latlngs);
// If there is next point
if (latlngs[i + 1]) {
nextOptionsIdx = optionIdxFn.call(fnContext, latlngs[i + 1], latlngs[i], i + 1, latlngs);
}
optionIdx = optionIdxFn.call(fnContext, latlngs[i], latlngs[i - 1] || latlngs[i], i, latlngs);

segmentLatlngs.push(latlngs[i]);

// is there a change in options or is it the last point?
if (prevOptionIdx !== optionIdx || i === len - 1) {
if (optionIdx !== nextOptionsIdx || i === len - 1) {
// Check if options is a function or an array
if (typeof multiOptions.options === "function") {
this.addLayer(L.polyline(segmentLatlngs, multiOptions.options(prevOptionIdx)));
this.addLayer(L.polyline(segmentLatlngs, multiOptions.options(optionIdx)));
} else {
this.addLayer(L.polyline(segmentLatlngs, multiOptions.options[prevOptionIdx]));
this.addLayer(L.polyline(segmentLatlngs, multiOptions.options[optionIdx]));
}

prevOptionIdx = optionIdx;
segmentLatlngs = [latlngs[i]];
}
}
Expand Down
5 changes: 3 additions & 2 deletions Leaflet.MultiOptionsPolyline.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<meta charset="UTF-8">
<title>Leaflet.MultiOptionsPolyline Demo</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.1/leaflet.css" />
<style>
@media (min-width: 768px) {
Expand Down