Skip to content

Commit

Permalink
provide km marker
Browse files Browse the repository at this point in the history
  • Loading branch information
mg4gh committed Jul 5, 2024
1 parent ef88bf5 commit c57a49a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 19 deletions.
37 changes: 34 additions & 3 deletions mgmap/src/main/java/mg/mgmap/activity/mgmap/FeatureService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.beans.PropertyChangeListener;
import java.lang.invoke.MethodHandles;

import mg.mgmap.generic.model.MultiPointModelImpl;
import mg.mgmap.generic.model.PointModel;
import mg.mgmap.generic.model.PointModelUtil;
import mg.mgmap.generic.util.CC;
import mg.mgmap.activity.mgmap.view.ControlMVLayer;
import mg.mgmap.activity.mgmap.view.MVGroupLayer;
Expand Down Expand Up @@ -73,6 +76,7 @@ public class FeatureService {
protected GroupLayer fsLayers = new GroupLayer();
protected MVGroupLayer fsControlLayers = new MVGroupLayer();
protected String logName;
public static final double ENUMERATION_DISTANCE = 1000;

public FeatureService(MGMapActivity activity){
this.activity = activity;
Expand Down Expand Up @@ -161,16 +165,43 @@ protected void showTrack(TrackLog trackLog, Paint paint, boolean showGL, int poi
showTrack(trackLog,paint,showGL,pointRadius, false);
}

protected void showTrack(TrackLog trackLog, Paint paint, boolean showGL, int pointRadius, boolean showIntermediates){
protected void showTrack(TrackLog trackLog, Paint paint, boolean showGL, int pointRadius, boolean showIntermediates) {
this.showTrack(trackLog,paint, showGL, pointRadius, showIntermediates, false);
}

protected void showTrack(TrackLog trackLog, Paint paint, boolean showGL, int pointRadius, boolean showIntermediates, boolean enumeratePoints){
if (trackLog == null) return;
if (pointRadius < 0 ) pointRadius = MultiPointView.POINT_RADIUS;
MultiPointModelImpl enumeratedPoints = new MultiPointModelImpl();
double totalLength = 0;
for (int idx = 0; idx<trackLog.getNumberOfSegments(); idx++){
TrackLogSegment segment = trackLog.getTrackLogSegment(idx);
MultiPointView layer = (showGL)?new MultiPointGLView(segment, paint):new MultiPointView(segment, paint);
if (showGL) layer.setStrokeIncrease(1.35);
if (enumeratePoints && (segment.size() > 0)){
PointModel lastPM = segment.get(0);
for (PointModel pm : segment){
double length = PointModelUtil.distance(lastPM, pm);
for (int enumarationCnt = (int)(totalLength/ENUMERATION_DISTANCE)+1; enumarationCnt <= (int)((totalLength+length)/ENUMERATION_DISTANCE); enumarationCnt++ ){
enumeratedPoints.addPoint(PointModelUtil.interpolate(lastPM, pm, enumarationCnt*ENUMERATION_DISTANCE - totalLength));
}
lastPM = pm;
totalLength += length;
}
} else {
MultiPointView layer = (showGL)?new MultiPointGLView(segment, paint):new MultiPointView(segment, paint);
if (showGL) layer.setStrokeIncrease(1.35);
layer.setPointRadius(pointRadius);
layer.setShowIntermediates(showIntermediates);
register(layer);
}
}
if (enumeratePoints){
MultiPointView layer = new MultiPointView(enumeratedPoints, paint);
layer.setPointRadius(pointRadius);
layer.setShowIntermediates(showIntermediates);
layer.setEnumeratePoints(true);
register(layer);
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class FSAvailableTrackLogs extends FeatureService {

private final Paint PAINT_STROKE_ATL = CC.getStrokePaint(R.color.CC_GREEN, getMapViewUtility().getTrackWidth());
private final Paint PAINT_STROKE_STL = CC.getStrokePaint(R.color.CC_BLUE, getMapViewUtility().getTrackWidth());
private final Paint PAINT_STROKE_STL2 = CC.getFillPaint(R.color.CC_BLUE);
private final Paint PAINT_STROKE_STL_GL = CC.getStrokePaint(R.color.CC_GRAY100_A100, getMapViewUtility().getTrackWidth()*1.4f);

private final Pref<Boolean> prefStlGl = getPref(R.string.FSATL_pref_stlGl, false);
Expand Down Expand Up @@ -153,6 +154,9 @@ private void showAvailableTrackLogs(){
if (trackLog!= null){
assert (available.getAvailableTrackLogs().contains(trackLog));
showTrack(trackLog,prefStlGl,PAINT_STROKE_STL_GL,PAINT_STROKE_STL, prefAlphaStl.getValue(), -1);
if ((getPref(R.string.FSBeeline_pref_ZoomLevel, 15).getValue() >= 12) && getPref(R.string.preferences_display_show_km_key, false).getValue()){
showTrack(trackLog,CC.getAlphaCloneFill(PAINT_STROKE_STL2, prefAlphaStl.getValue()),false, 3, true, true);
}
getControlView().setDashboardValue(true, dashboardStl ,trackLog.getTrackStatistic());
int segIdx = available.getSelectedTrackLogRef().getSegmentIdx();
getControlView().setDashboardValue(trackLog.getNumberOfSegments()>1, dashboardStls,(segIdx>=0)?trackLog.getTrackLogSegment(segIdx).getStatistic():null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected void doJob() {
}

} catch (InterruptedException e) {
e.printStackTrace();
mgLog.e(e);
}
}
mgLog.d("routeCalcThread terminating");
Expand Down Expand Up @@ -448,7 +448,10 @@ protected void doRefreshResumedUI() {
}
showTrack(rotl,prefRouteGL,PAINT_STROKE_GL,PAINT_ROUTE_STROKE, prefAlphaRotl.getValue(), 0);
if (mtl != null){
showTrack(mtl, CC.getAlphaCloneFill(PAINT_ROUTE_STROKE2, prefAlphaRotl.getValue()) , false, (int)(DisplayModel.getDeviceScaleFactor()*6.0f), true);
showTrack(mtl, CC.getAlphaCloneFill(PAINT_ROUTE_STROKE2, prefAlphaRotl.getValue()) , false, 6, true);
}
if ((prefZoomLevel.getValue() >= 12) && getPref(R.string.preferences_display_show_km_key, false).getValue()){
showTrack(rotl,CC.getAlphaCloneFill(PAINT_ROUTE_STROKE2, prefAlphaRotl.getValue()),false, 3, true, true);
}
getControlView().setDashboardValue(prefMtlVisibility.getValue(), dashboardRoute, calcRemainingStatistic(rotl));

Expand Down Expand Up @@ -540,7 +543,7 @@ public TrackLogRefApproach getBestDistance(WriteableTrackLog mtl, PointModel pm,
public void optimizePosition(WriteablePointModel wpm, double threshold) {
mgLog.d("pos="+wpm+" threshold="+threshold);
TreeSet<ApproachModel> approaches = routingEngine.calcApproaches(wpm, (int)threshold);
if (approaches.size() > 0){
if (!approaches.isEmpty()){
GNode pos = approaches.first().getApproachNode();
mgLog.i("optimize Pos "+wpm+" to "+pos +String.format(Locale.ENGLISH," dist=%.1fm",pos.getNeighbour().getCost()));
wpm.setLat(pos.getLat());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package mg.mgmap.activity.mgmap.view;

import org.mapsforge.core.graphics.Canvas;
import org.mapsforge.core.graphics.FontFamily;
import org.mapsforge.core.graphics.FontStyle;
import org.mapsforge.core.graphics.GraphicFactory;
import org.mapsforge.core.graphics.Paint;
import org.mapsforge.core.graphics.Path;
Expand All @@ -25,8 +27,10 @@
import java.lang.invoke.MethodHandles;
import java.util.Iterator;

import mg.mgmap.R;
import mg.mgmap.generic.model.MultiPointModel;
import mg.mgmap.generic.model.PointModel;
import mg.mgmap.generic.util.CC;
import mg.mgmap.generic.util.basic.MGLog;

/**
Expand All @@ -44,6 +48,9 @@ public class MultiPointView extends MVLayer {
protected boolean showIntermediates = false;
protected boolean showPointsOnly = false;
protected int pointRadius = POINT_RADIUS;
protected boolean enumeratePoints = false;
private Paint paintText;
private Paint paintTextBg;

protected final MultiPointModel model;

Expand Down Expand Up @@ -88,13 +95,15 @@ protected void drawModel(MultiPointModel model, BoundingBox boundingBox, byte zo

Path path = this.graphicFactory.createPath();

int cnt = 1;
PointModel pm = iterator.next();
int x = lon2canvasX(pm.getLon());
int y = lat2canvasY(pm.getLat());
path.moveTo(x, y);
drawPoint(canvas, x,y, zoomLevel);
drawPoint(canvas, x,y, zoomLevel, cnt);

while (iterator.hasNext()) {
cnt++;
pm = iterator.next();
x = lon2canvasX(pm.getLon());
y = lat2canvasY(pm.getLat());
Expand All @@ -104,7 +113,7 @@ protected void drawModel(MultiPointModel model, BoundingBox boundingBox, byte zo
path.moveTo(x, y);
}
if ( (! iterator.hasNext()) || showIntermediates ){
drawPoint(canvas, x,y, zoomLevel);
drawPoint(canvas, x,y, zoomLevel, cnt);
}
}

Expand All @@ -120,9 +129,29 @@ protected void drawModel(MultiPointModel model, BoundingBox boundingBox, byte zo
}
}

private void drawPoint(Canvas canvas, int x, int y, byte zoomLevel){
private void drawPoint(Canvas canvas, int x, int y, byte zoomLevel, int cnt){
if (pointRadius > 0){
canvas.drawCircle(x, y, (int)(pointRadius* getScale(zoomLevel)), this.paintStroke);
canvas.drawCircle(x, y, (int)(displayModel.getScaleFactor() * pointRadius* getScale(zoomLevel)), enumeratePoints?CC.getFillPaint(R.color.CC_WHITE):this.paintStroke);
if (enumeratePoints){
drawEnumeration(canvas, x, y, zoomLevel, cnt);
}
}
}
private void drawEnumeration(Canvas canvas, int x, int y, byte zoomLevel, int enumeration){
if (paintText == null){
paintText = CC.getFillPaint(R.color.CC_WHITE);
paintText.setColor(paintStroke.getColor());
paintText.setTypeface(FontFamily.DEFAULT, FontStyle.BOLD);
paintTextBg = CC.getStrokePaint(R.color.CC_WHITE, 10);
paintTextBg.setTypeface(FontFamily.DEFAULT, FontStyle.BOLD);
int textSize = (int)(displayModel.getScaleFactor() * pointRadius* getScale(zoomLevel) *5);
paintText.setTextSize(textSize);
paintTextBg.setTextSize(textSize);
}
if (pointRadius > 0){
int diff = (int)(0.8 * displayModel.getScaleFactor() * pointRadius* getScale(zoomLevel));
canvas.drawText(""+enumeration, x+diff, y-diff, paintTextBg);
canvas.drawText(""+enumeration, x+diff, y-diff, paintText);
}
}

Expand All @@ -145,7 +174,9 @@ public void setPointRadius(int pointRadius) {
this.pointRadius = pointRadius;
}


public void setEnumeratePoints(boolean enumeratePoints) {
this.enumeratePoints = enumeratePoints;
}

protected float getScale(byte zoomLevel){
return (float) Math.pow(this.strokeIncrease, Math.max(zoomLevel - STROKE_MIN_ZOOM, 0));
Expand Down
3 changes: 3 additions & 0 deletions mgmap/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
<string name="preferences_display_none_fullscreen_offset_title">Vertical none fullscreen offset</string>
<string name="preferences_display_none_fullscreen_offset_desc">Vertical offset in none fullscreen mode - used for dashboard and search text.</string>
<string name="preferences_display_none_fullscreen_offset_desc2">Vertical offset in none fullscreen mode - used for dashboard and search text. Helpful, if dashboard gesture is in conflict with system gesture.</string>
<string name="preferences_display_show_km_key">pref_show_km_marks</string>
<string name="preferences_display_show_km_title">Show km mark</string>
<string name="preferences_display_show_km_desc">Show km marker for selected and route TrackLog.</string>

<string name="preferences_hprof_gl_key">hprof_gl</string>
<string name="preferences_hprof_gl_title">Ascent height profile</string>
Expand Down
13 changes: 5 additions & 8 deletions mgmap/src/main/res/xml/main_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,11 @@
app:title="@string/preferences_display_fullscreen_offset_title"
app:iconSpaceReserved="false"
/>
<EditTextPreference
app:defaultValue="0"
app:key="@string/preferences_display_none_fullscreen_offset_key"
app:dialogTitle="@string/preferences_display_none_fullscreen_offset_title"
app:dialogMessage="@string/preferences_display_none_fullscreen_offset_desc2"
android:inputType="number"
app:summary="@string/preferences_display_none_fullscreen_offset_desc"
app:title="@string/preferences_display_none_fullscreen_offset_title"
<SwitchPreference
app:defaultValue="false"
app:key="@string/preferences_display_show_km_key"
app:title="@string/preferences_display_show_km_title"
app:summary="@string/preferences_display_show_km_desc"
app:iconSpaceReserved="false"
/>
<SwitchPreference
Expand Down

0 comments on commit c57a49a

Please sign in to comment.