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

Added option to show as points + show last point #30

Open
wants to merge 4 commits 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
23 changes: 21 additions & 2 deletions src/partials/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ <h5 class="section-heading">Options</h5>
checked="ctrl.panel.autoZoom" on-change="ctrl.zoomToFit()"/>
<gf-form-switch class="gf-form" label="Zoom with scroll wheel" label-class="width-11"
checked="ctrl.panel.scrollWheelZoom" on-change="ctrl.applyScrollZoom()"/>
<gf-form-switch class="gf-form" label="Show as points" label-class="width-11"
checked="ctrl.panel.showAsPoints" on-change="ctrl.changeViewType()"/>
<div class="gf-form">
<label class="gf-form-label width-9">Default layer</label>
<div class="gf-form-select-wrapper max-width-11">
Expand All @@ -22,16 +24,33 @@ <h5 class="section-heading">Options</h5>
<div class="section gf-form-group">
<h5 class="section-heading">Colors</h5>
<div class="gf-form">
<label class="gf-form-label width-9">Line Color</label>
<label class="gf-form-label width-9">Line/Point Color</label>
<span class="max-width-10">
<spectrum-picker class="gf-form-input" ng-model="ctrl.panel.lineColor" ng-change="ctrl.refreshColors()"/>
</span>
</div>
<div class="gf-form">
<label class="gf-form-label width-9">Point Color</label>
<label class="gf-form-label width-9">Hover Point Color</label>
<span class="max-width-10">
<spectrum-picker class="gf-form-input" ng-model="ctrl.panel.pointColor" ng-change="ctrl.refreshColors()"/>
</span>
</div>
<div class="gf-form">
<label class="gf-form-label width-9">Point Outline Color</label>
<span class="max-width-10">
<spectrum-picker class="gf-form-input" ng-model="ctrl.panel.pointOutlineColor" ng-change="ctrl.refreshColors()"/>
</span>
</div>
</div>
<div class="section gf-form-group">
<h5 class="section-heading">Last point highlighting</h5>
<gf-form-switch class="gf-form" label="Enable" label-class="width-7"
checked="ctrl.panel.enableLastPoint" on-change="ctrl.updateLastPoint()" />
<div class="gf-form">
<label class="gf-form-label width-9">Point Color</label>
<span class="max-width-10">
<spectrum-picker class="gf-form-input" ng-model="ctrl.panel.lastPointColor" ng-change="ctrl.refreshColors()"/>
</span>
</div>
</div>
</div>
109 changes: 96 additions & 13 deletions src/trackmap_ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const panelDefaults = {
defaultLayer: 'OpenStreetMap',
lineColor: 'red',
pointColor: 'royalblue',
pointOutlineColor: 'white',
enableLastPoint: true,
lastPointColor: 'lime',
showAsPoints: false,
}

function log(msg) {
Expand Down Expand Up @@ -54,6 +58,8 @@ export class TrackMapCtrl extends MetricsPanelCtrl {
this.coords = [];
this.leafMap = null;
this.polyline = null;
this.marker = [];
this.lastPoint = null;
this.hoverMarker = null;
this.hoverTarget = null;
this.setSizePromise = null;
Expand Down Expand Up @@ -196,6 +202,17 @@ export class TrackMapCtrl extends MetricsPanelCtrl {
if (this.leafMap) {
if (this.polyline) {
this.polyline.removeFrom(this.leafMap);
this.polyline = null;
}
if (this.marker.length > 0) {
this.marker.forEach(point => {
point.removeFrom(this.leafMap);
});
this.marker = [];
}
if (this.lastPoint) {
this.lastPoint.removeFrom(this.leafMap);
this.lastPoint = null;
}
this.onPanelClear();
return;
Expand All @@ -216,10 +233,10 @@ export class TrackMapCtrl extends MetricsPanelCtrl {

// Hover marker
this.hoverMarker = L.circleMarker(L.latLng(0, 0), {
color: 'white',
color: this.panel.pointOutlineColor,
fillColor: this.panel.pointColor,
fillOpacity: 1,
weight: 2,
weight: 3,
radius: 7
});

Expand Down Expand Up @@ -268,23 +285,74 @@ export class TrackMapCtrl extends MetricsPanelCtrl {
}
}

// Add the circles and polyline to the map
// Add the circles, polyline and last point to the map
addDataToMap() {
log("addDataToMap");
this.polyline = L.polyline(
this.coords.map(x => x.position, this), {
color: this.panel.lineColor,
weight: 3,
if (this.panel.showAsPoints) {
for (let i = 0; i < this.coords.length; i++) {
let point = L.circleMarker(
this.coords[i].position, {
color: this.panel.pointOutlineColor,
fillColor: this.panel.lineColor,
fillOpacity: i / this.coords.length,
weight: 3,
radius: 7,
}
).addTo(this.leafMap);
this.marker.push(point);
}
).addTo(this.leafMap);
} else {
this.polyline = L.polyline(
this.coords.map(x => x.position, this), {
color: this.panel.lineColor,
weight: 3,
}
).addTo(this.leafMap);
}

this.updateLastPoint();

this.zoomToFit();
}

zoomToFit(){
updateLastPoint() {
if (this.panel.enableLastPoint) {
this.lastPoint = L.circleMarker(
this.coords[this.coords.length - 1].position, {
color: this.panel.pointOutlineColor,
fillColor: this.panel.lastPointColor,
fillOpacity: 1,
weight: 3,
radius: 7,
}).addTo(this.leafMap);
} else if (this.lastPoint != null) {
this.lastPoint.removeFrom(this.leafMap);
this.lastPoint = null;
}
}

changeViewType() {
if (this.panel.showAsPoints) {
this.polyline.removeFrom(this.leafMap);
this.polyline = null;
} else {
this.marker.forEach(point => {
point.removeFrom(this.leafMap)
});
this.marker = [];
}

this.addDataToMap();
}

zoomToFit() {
log("zoomToFit");
if (this.panel.autoZoom && this.polyline){
this.leafMap.fitBounds(this.polyline.getBounds());
if (this.panel.autoZoom) {
if (this.polyline) {
this.leafMap.fitBounds(this.polyline.getBounds());
} else if (this.marker.length > 0) {
this.leafMap.fitBounds(L.featureGroup(this.marker).getBounds());
}
}
this.render();
}
Expand All @@ -293,11 +361,26 @@ export class TrackMapCtrl extends MetricsPanelCtrl {
log("refreshColors");
if (this.polyline) {
this.polyline.setStyle({
color: this.panel.lineColor
color: this.panel.lineColor,
});
}
if (this.hoverMarker){
if (this.marker.length > 0) {
this.marker.forEach(point => {
point.setStyle({
color: this.panel.pointOutlineColor,
fillColor: this.panel.lineColor,
});
});
}
if (this.lastPoint) {
this.lastPoint.setStyle({
color: this.panel.pointOutlineColor,
fillColor: this.panel.lastPointColor,
});
}
if (this.hoverMarker) {
this.hoverMarker.setStyle({
color: this.panel.pointOutlineColor,
fillColor: this.panel.pointColor,
});
}
Expand Down