colored-gpx-and-fixed-points
This commit is contained in:
parent
6b717b48ec
commit
faa6cae4c8
6 changed files with 182 additions and 48 deletions
|
@ -1260,6 +1260,8 @@
|
|||
<string name="osmodroid_mode_on">Остановить OsMoDroid</string>
|
||||
<string name="osmodroid_mode_off">Запустить OsMoDroid</string>
|
||||
<string name="osmodroid_refresh">Обновить каналы</string>
|
||||
<string name="osmodroid_seek">Следить за</string>
|
||||
<string name="osmodroid_unseek">Не следить</string>
|
||||
<string name="osb_author_or_password_not_specified">Пожалуйста, укажите в настройках пароль и имя пользователя OSM</string>
|
||||
<string name="route_descr_map_location">Карта: </string>
|
||||
<string name="osb_author_dialog_password">Пароль OSM (опционально)</string>
|
||||
|
|
|
@ -85,6 +85,8 @@
|
|||
<string name="osmodroid_mode_on">Stop OsMoDroid</string>
|
||||
<string name="osmodroid_mode_off">Start OsMoDroid</string>
|
||||
<string name="osmodroid_refresh">Refresh channels</string>
|
||||
<string name="osmodroid_seek">Seek object</string>
|
||||
<string name="osmodroid_unseek">Unseek object</string>
|
||||
<string name="announce_gpx_waypoints">Announce GPX waypoints</string>
|
||||
<string name="speak_title">Announce…</string>
|
||||
<string name="speak_descr">Configure to announce street names, traffic warnings (forced stops, speed bumps), speed camera warnings, speed limits</string>
|
||||
|
|
|
@ -45,6 +45,22 @@ String getObjectColor(int layerId, int objectId);
|
|||
int getNumberOfGpx(int layerId);
|
||||
|
||||
String getGpxFile (int layerId, int pos);
|
||||
|
||||
int getGpxColor (int layerId, int pos);
|
||||
|
||||
int getNumberOfPoints(int layerId);
|
||||
|
||||
int getPointId(int layerId, int pos);
|
||||
|
||||
float getPointLat(int layerId, int pointId);
|
||||
|
||||
float getPointLon(int layerId, int pointId);
|
||||
|
||||
String getPointName(int layerId, int pointId);
|
||||
|
||||
String getPointDescription(int layerId, int pointId);
|
||||
|
||||
String getPointColor(int layerId, int pointId);
|
||||
|
||||
void refreshChannels();
|
||||
}
|
8
OsmAnd/src/net/osmand/plus/osmodroid/ColoredGPX.java
Normal file
8
OsmAnd/src/net/osmand/plus/osmodroid/ColoredGPX.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package net.osmand.plus.osmodroid;
|
||||
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
|
||||
public class ColoredGPX {
|
||||
int color;
|
||||
GPXFile gpxFile;
|
||||
}
|
|
@ -27,6 +27,7 @@ import android.graphics.Color;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.Paint.Cap;
|
||||
import android.graphics.Paint.Join;
|
||||
|
@ -49,7 +50,7 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
|
|||
* magic number so far
|
||||
*/
|
||||
private static final int radius = 10;
|
||||
|
||||
OsMoDroidPoint seekOsMoDroidPoint;
|
||||
OsMoDroidPlugin myOsMoDroidPlugin;
|
||||
|
||||
private DisplayMetrics dm;
|
||||
|
@ -59,8 +60,9 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
|
|||
|
||||
private Paint textPaint;
|
||||
|
||||
ArrayList<OsMoDroidPoint> OsMoDroidPointArrayList;
|
||||
ArrayList<GPXFile> gpxArrayList;
|
||||
ArrayList<OsMoDroidPoint> osMoDroidPointArrayList;
|
||||
ArrayList<OsMoDroidPoint> osMoDroidFixedPointArrayList;
|
||||
ArrayList<ColoredGPX> gpxArrayList = new ArrayList<ColoredGPX>() ;
|
||||
int layerId;
|
||||
String layerName;
|
||||
String layerDescription;
|
||||
|
@ -120,17 +122,25 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
|
|||
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
textPaint.setTextAlign(Paint.Align.CENTER);
|
||||
opIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.bicycle_location);
|
||||
OsMoDroidPointArrayList = myOsMoDroidPlugin.getOsMoDroidPointArrayList(layerId);
|
||||
gpxArrayList = myOsMoDroidPlugin.getGpxArrayList(layerId);
|
||||
osMoDroidPointArrayList = myOsMoDroidPlugin.getOsMoDroidPointArrayList(layerId);
|
||||
osMoDroidFixedPointArrayList = myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId);
|
||||
myOsMoDroidPlugin.getGpxArrayList(layerId);
|
||||
initUI();
|
||||
}
|
||||
|
||||
|
||||
public void inGPXFilelist(ArrayList<ColoredGPX> in){
|
||||
gpxArrayList=in;
|
||||
map.refreshMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
|
||||
|
||||
for (OsMoDroidPoint op : OsMoDroidPointArrayList) {
|
||||
|
||||
for (OsMoDroidPoint op : osMoDroidPointArrayList) {
|
||||
if(seekOsMoDroidPoint!=null&&seekOsMoDroidPoint.equals(op)){
|
||||
map.setMapLocation(op.latlon.getLatitude(), op.latlon.getLongitude());
|
||||
}
|
||||
LatLon newLatlon;
|
||||
try {
|
||||
|
||||
|
@ -178,11 +188,23 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
|
|||
|
||||
}
|
||||
|
||||
for (GPXFile gpxFile : gpxArrayList){
|
||||
gpxFile.proccessPoints();
|
||||
List<List<WptPt>> points = gpxFile.processedPointsToDisplay;
|
||||
for (OsMoDroidPoint point : osMoDroidFixedPointArrayList ){
|
||||
double latitude = point.latlon.getLatitude();
|
||||
double longitude = point.latlon.getLongitude();
|
||||
int locationX = (int) tileBox.getPixXFromLatLon(latitude, longitude);
|
||||
int locationY = (int) tileBox.getPixYFromLatLon(latitude, longitude);
|
||||
textPaint.setColor(Color.parseColor("#013220"));
|
||||
canvas.drawText(point.name, locationX, locationY - radius, textPaint);
|
||||
textPaint.setColor(Color.parseColor("#" + point.color));
|
||||
textPaint.setShadowLayer(radius, 0, 0, Color.GRAY);
|
||||
canvas.drawRect(new Rect(locationX-radius, locationY-radius, locationX+radius, locationY+radius), textPaint);
|
||||
}
|
||||
|
||||
for (ColoredGPX cg : gpxArrayList){
|
||||
cg.gpxFile.proccessPoints();
|
||||
List<List<WptPt>> points = cg.gpxFile.processedPointsToDisplay;
|
||||
|
||||
paint.setColor(getColor(settings));
|
||||
paint.setColor(cg.color);
|
||||
|
||||
final QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||
for (List<WptPt> l : points) {
|
||||
|
@ -211,37 +233,18 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
|
|||
|
||||
}
|
||||
private void drawSegment(Canvas canvas, RotatedTileBox tb, List<WptPt> l, int startIndex, int endIndex) {
|
||||
int px = tb.getPixXFromLonNoRot(l.get(startIndex).lon);
|
||||
int py = tb.getPixYFromLatNoRot(l.get(startIndex).lat);
|
||||
int px = (int) tb.getPixXFromLatLon(l.get(startIndex).lat, l.get(startIndex).lon);
|
||||
int py = (int) tb.getPixYFromLatLon(l.get(startIndex).lat, l.get(startIndex).lon);
|
||||
path.moveTo(px, py);
|
||||
for (int i = startIndex + 1; i <= endIndex; i++) {
|
||||
WptPt p = l.get(i);
|
||||
int x = tb.getPixXFromLonNoRot(p.lon);
|
||||
int y = tb.getPixYFromLatNoRot(p.lat);
|
||||
int x = (int) tb.getPixXFromLatLon(p.lat,p.lon);
|
||||
int y = (int) tb.getPixYFromLatLon(p.lat,p.lon);
|
||||
path.lineTo(x, y);
|
||||
}
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
|
||||
private int getColor(DrawSettings nightMode){
|
||||
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
|
||||
boolean n = nightMode != null && nightMode.isNightMode();
|
||||
if (rrs != cachedRrs || cachedNightMode != n) {
|
||||
cachedRrs = rrs;
|
||||
cachedNightMode = n;
|
||||
cachedColor = view.getResources().getColor(R.color.gpx_track);
|
||||
if (cachedRrs != null) {
|
||||
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
|
||||
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, cachedNightMode);
|
||||
if (req.searchRenderingAttribute("gpxColor")) {
|
||||
cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cachedColor;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {}
|
||||
|
||||
|
@ -266,6 +269,26 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
|
|||
// synchronized block
|
||||
}
|
||||
}
|
||||
if (myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId) != null) {
|
||||
int ex = (int) point.x;
|
||||
int ey = (int) point.y;
|
||||
|
||||
try {
|
||||
for (int i = 0; i < myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId).size(); i++) {
|
||||
OsMoDroidPoint n = myOsMoDroidPlugin.getOsMoDroidFixedPointArrayList(layerId).get(i);
|
||||
if (!om.contains(n)) {
|
||||
int x = (int) tb.getPixXFromLatLon(n.latlon.getLatitude(), n.latlon.getLongitude());
|
||||
int y = (int) tb.getPixYFromLatLon(n.latlon.getLatitude(), n.latlon.getLongitude());
|
||||
if (Math.abs(x - ex) <= opIcon.getWidth() && Math.abs(y - ey) <= opIcon.getHeight()) {
|
||||
om.add(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// that's really rare case, but is much efficient than introduce
|
||||
// synchronized block
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -275,11 +298,28 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
|
|||
OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
|
||||
@Override
|
||||
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||
|
||||
map.getMyApplication().getTargetPointsHelper().navigateToPoint(a.latlon, true, -1);
|
||||
}
|
||||
};
|
||||
|
||||
OnContextMenuClick seeklistener = new ContextMenuAdapter.OnContextMenuClick() {
|
||||
|
||||
@Override
|
||||
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||
if(seekOsMoDroidPoint!=null&&a.equals(seekOsMoDroidPoint))
|
||||
{
|
||||
seekOsMoDroidPoint=null;
|
||||
isChecked=false;
|
||||
} else
|
||||
{
|
||||
seekOsMoDroidPoint=a;
|
||||
isChecked=true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
adapter.item(map.getString(R.string.get_directions)).listen(listener).reg();
|
||||
adapter.item(map.getString(R.string.osmodroid_seek)).listen(seeklistener).reg();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.osmodroid;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ConcurrentModificationException;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -14,6 +15,7 @@ import net.osmand.plus.OsmandPlugin;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
||||
import net.osmand.plus.views.MonitoringInfoControl;
|
||||
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
@ -25,6 +27,7 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
|
||||
|
@ -107,6 +110,7 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr
|
|||
private OsMoDroidLayer osmoDroidLayer;
|
||||
protected boolean connected = false;
|
||||
ArrayList<OsMoDroidLayer> osmoDroidLayerList = new ArrayList<OsMoDroidLayer>();
|
||||
private AsyncTask<Void, Void, ArrayList<ColoredGPX>> task;
|
||||
|
||||
public ArrayList<OsMoDroidPoint> getOsMoDroidPointArrayList(int id) {
|
||||
ArrayList<OsMoDroidPoint> result = new ArrayList<OsMoDroidPoint>();
|
||||
|
@ -126,6 +130,25 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr
|
|||
return result;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<OsMoDroidPoint> getOsMoDroidFixedPointArrayList(int id) {
|
||||
ArrayList<OsMoDroidPoint> result = new ArrayList<OsMoDroidPoint>();
|
||||
try {
|
||||
for (int i = 0; i < mIRemoteService.getNumberOfPoints(id); i++) {
|
||||
result.add(new OsMoDroidPoint(mIRemoteService.getPointLat(id, mIRemoteService.getPointId(id, i)), mIRemoteService
|
||||
.getPointLon(id, mIRemoteService.getPointId(id, i)), mIRemoteService.getPointName(id,
|
||||
mIRemoteService.getPointId(id, i)), mIRemoteService.getPointDescription(id, mIRemoteService.getPointId(id, i)),
|
||||
mIRemoteService.getPointId(id, i), id, null,
|
||||
mIRemoteService.getPointColor(id, mIRemoteService.getPointId(id, i))));
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
|
@ -278,23 +301,66 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr
|
|||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}).reg();
|
||||
qa.item(R.string.osmodroid_unseek).icons(R.drawable.abs__ic_commit_search_api_holo_dark, R.drawable.abs__ic_commit_search_api_holo_light).listen(new OnContextMenuClick() {
|
||||
|
||||
@Override
|
||||
public void onContextMenuClick(int itemId, int pos, boolean isChecked,
|
||||
DialogInterface dialog) {
|
||||
for (OsMoDroidLayer l: osmoDroidLayerList){
|
||||
l.seekOsMoDroidPoint=null;
|
||||
}
|
||||
|
||||
}
|
||||
}).reg();
|
||||
}
|
||||
|
||||
public ArrayList<GPXFile> getGpxArrayList(int id) {
|
||||
ArrayList<GPXFile> result = new ArrayList<GPXFile>();
|
||||
|
||||
|
||||
try {
|
||||
for (int i = 0; i < mIRemoteService.getNumberOfGpx(id); i++) {
|
||||
result.add( GPXUtilities.loadGPXFile(app, new File(mIRemoteService.getGpxFile(id, i)), false));
|
||||
}
|
||||
return result;
|
||||
} catch (RemoteException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
public void getGpxArrayList(final int id) {
|
||||
final ArrayList<ColoredGPX> result = new ArrayList<ColoredGPX>();
|
||||
if(task!=null){
|
||||
task.cancel(true);
|
||||
}
|
||||
return result;
|
||||
task = new AsyncTask<Void, Void, ArrayList<ColoredGPX>>() {
|
||||
@Override
|
||||
protected ArrayList<ColoredGPX> doInBackground(Void... params) {
|
||||
ArrayList<ColoredGPX> temp = new ArrayList<ColoredGPX>();
|
||||
try {
|
||||
for (int i = 0; i < mIRemoteService.getNumberOfGpx(id); i++) {
|
||||
ColoredGPX cg = new ColoredGPX();
|
||||
cg.gpxFile = GPXUtilities.loadGPXFile(app, new File(mIRemoteService.getGpxFile(id, i)), false);
|
||||
cg.color = mIRemoteService.getGpxColor(id, i);
|
||||
temp.add(cg);
|
||||
}
|
||||
return temp;
|
||||
} catch (RemoteException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayList<ColoredGPX> backgroundresult) {
|
||||
if(backgroundresult!=null){
|
||||
try {
|
||||
for (OsMoDroidLayer l : osmoDroidLayerList){
|
||||
if (l.layerId==id){
|
||||
l.inGPXFilelist(backgroundresult);
|
||||
}
|
||||
}
|
||||
} catch (ConcurrentModificationException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue