use of net.osmand.data.LatLon in project OsmAnd-tools by osmandapp.
the class MapRouterLayer method createSegmentVisitor.
private RouteSegmentVisitor createSegmentVisitor(final boolean animateRoutingCalculation, final DataTileManager<Entity> points) {
return new RouteSegmentVisitor() {
private List<RouteSegment> cache = new ArrayList<RouteSegment>();
private List<RouteSegment> pollCache = new ArrayList<RouteSegment>();
private List<Integer> cacheInt = new ArrayList<Integer>();
@Override
public void visitSegment(RouteSegment s, int endSegment, boolean poll) {
if (stop) {
throw new RuntimeException("Interrupted");
}
if (!animateRoutingCalculation) {
return;
}
if (!poll && pause) {
pollCache.add(s);
return;
}
cache.add(s);
cacheInt.add(endSegment);
if (cache.size() < steps) {
return;
}
if (pause) {
registerObjects(points, poll, pollCache, null);
pollCache.clear();
}
registerObjects(points, !poll, cache, cacheInt);
cache.clear();
cacheInt.clear();
redraw();
if (pause) {
waitNextPress();
}
}
private void registerObjects(final DataTileManager<Entity> points, boolean white, List<RouteSegment> registerCache, List<Integer> cacheInt) {
for (int l = 0; l < registerCache.size(); l++) {
RouteSegment segment = registerCache.get(l);
Way way = new Way(-1);
way.putTag(OSMTagKey.NAME.getValue(), segment.getTestName());
if (white) {
way.putTag("color", "white");
}
int from = cacheInt != null ? segment.getSegmentStart() : segment.getSegmentStart() - 2;
int to = cacheInt != null ? cacheInt.get(l) : segment.getSegmentStart() + 2;
if (from > to) {
int x = from;
from = to;
to = x;
}
for (int i = from; i <= to; i++) {
if (i >= 0 && i < segment.getRoad().getPointsLength()) {
net.osmand.osm.edit.Node n = createNode(segment, i);
way.addNode(n);
}
}
LatLon n = way.getLatLon();
points.registerObject(n.getLatitude(), n.getLongitude(), way);
}
}
};
}
use of net.osmand.data.LatLon in project OsmAnd-tools by osmandapp.
the class OsmExtractionUI method updateStatusField.
private void updateStatusField(final JTextField statusField) {
popup = new JScrollPopupMenu();
popup.setMaximumVisibleRows(25);
popup.setFocusable(false);
searchUICore.setOnResultsComplete(new Runnable() {
@Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateSearchResult(statusField, searchUICore.getCurrentSearchResult(), true);
}
});
}
});
statusField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
// if(e.getOppositeComponent() != popup) {
// popup.setVisible(false);
// }
}
@Override
public void focusGained(FocusEvent e) {
popup.setFocusable(false);
SearchSettings settings = searchUICore.getPhrase().getSettings().setOriginalLocation(new LatLon(mapPanel.getLatitude(), mapPanel.getLongitude()));
settings = settings.setLang(DataExtractionSettings.getSettings().getSearchLocale(), false);
searchUICore.updateSettings(settings);
}
});
statusField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
mapPanel.setStatusField(null);
if (e.getKeyCode() == KeyEvent.VK_DOWN && popup.getComponentCount() > 0) {
popup.setVisible(false);
popup.setFocusable(true);
Point p = statusField.getLocation();
popup.show(e.getComponent(), p.x, p.y - 4);
// popup.show();
popup.requestFocus();
return;
}
}
@Override
public void keyTyped(KeyEvent e) {
mapPanel.setStatusField(null);
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
return;
}
String text = statusField.getText();
int ps = statusField.getCaretPosition();
if (e.getKeyChar() == '\b') {
// nothing
} else if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
if (ps >= text.length()) {
text += e.getKeyChar();
} else {
text = text.substring(0, ps) + e.getKeyChar() + text.substring(ps);
}
}
SearchSettings settings = searchUICore.getPhrase().getSettings();
if (settings.getRadiusLevel() != 1) {
searchUICore.updateSettings(settings.setRadiusLevel(1));
}
SearchResultCollection c = null;
if (!text.contains("#map")) {
c = searchUICore.search(text, true, null);
}
if (c != null) {
updateSearchResult(statusField, c, false);
}
}
});
statusField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
mapPanel.setStatusField(statusField);
String txt = statusField.getText();
int i = txt.indexOf("#map=");
if (i != -1) {
String[] vs = txt.substring(i + "#map=".length()).split("/");
mapPanel.setLatLon(Float.parseFloat(vs[1]), Float.parseFloat(vs[2]));
mapPanel.setZoom(Integer.parseInt(vs[0]));
}
mapPanel.refresh();
}
});
}
use of net.osmand.data.LatLon in project OsmAnd-tools by osmandapp.
the class OsmExtractionUI method updateSearchResult.
private void updateSearchResult(final JTextField statusField, SearchResultCollection res, boolean addMore) {
popup.setVisible(false);
popup.removeAll();
if (res.getCurrentSearchResults().size() > 0 || addMore) {
int count = 30;
if (addMore) {
JMenuItem mi = new JMenuItem();
mi.setText("Results " + res.getCurrentSearchResults().size() + ", radius " + res.getPhrase().getRadiusLevel() + " (show more...)");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SearchSettings settings = searchUICore.getPhrase().getSettings();
searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
SearchResultCollection collection = searchUICore.search(statusField.getText(), true, null);
updateSearchResult(statusField, collection, false);
}
});
popup.add(mi);
}
for (final SearchResult sr : res.getCurrentSearchResults()) {
count--;
if (count == 0) {
// break;
}
JMenuItem mi = new JMenuItem();
LatLon location = res.getPhrase().getLastTokenLocation();
String locationString = "";
if (sr.location != null) {
locationString = ((int) MapUtils.getDistance(location, sr.location)) / 1000.f + " km";
}
if (!Algorithms.isEmpty(sr.localeRelatedObjectName)) {
locationString += " " + sr.localeRelatedObjectName;
if (sr.distRelatedObjectName != 0) {
locationString += " " + (int) (sr.distRelatedObjectName / 1000.f) + " km";
}
}
if (sr.objectType == ObjectType.HOUSE) {
if (sr.relatedObject instanceof Street) {
locationString += " " + ((Street) sr.relatedObject).getCity().getName();
}
}
if (sr.objectType == ObjectType.LOCATION) {
locationString += " " + osmandRegions.getCountryName(sr.location);
}
if (sr.object instanceof Amenity) {
locationString += " " + ((Amenity) sr.object).getSubType();
if (((Amenity) sr.object).isClosed()) {
locationString += " (CLOSED)";
}
}
mi.setText(sr.localeName + " [" + sr.getFoundWordCount() + ", " + sr.objectType + "] " + locationString);
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mapPanel.setStatusField(null);
if (sr.location != null) {
mapPanel.setLatLon(sr.location.getLatitude(), sr.location.getLongitude());
mapPanel.setZoom(sr.preferredZoom);
}
searchUICore.selectSearchResult(sr);
String txt = searchUICore.getPhrase().getText(true);
statusField.setText(txt);
searchUICore.search(txt, false, null);
statusField.requestFocus();
// statusField.setCaretPosition(statusField.getText().length());
}
});
popup.add(mi);
}
// .getCaret().getMagicCaretPosition();
Point p = statusField.getLocation();
if (popup.isVisible()) {
popup.setVisible(true);
} else {
popup.show(statusField.getParent(), p.x, p.y + statusField.getHeight() + 4);
// popup.show();
}
}
}
use of net.osmand.data.LatLon in project OsmAnd-tools by osmandapp.
the class IndexHeightData method testFileSmoothness.
private static void testFileSmoothness() throws XmlPullParserException, IOException {
// File fl = new File("/Users/victorshcherb/osmand/maps/route_laspi.gpx");
File fl = new File("/Users/victorshcherb/osmand/route.gpx");
XmlPullParser parser = PlatformUtil.newXMLPullParser();
parser.setInput(new FileReader(fl));
int next;
List<LatLon> l = new ArrayList<>();
List<Float> h = new ArrayList<>();
double ele = 0;
double SPECIAL_VALUE = -18000;
double ROUTE_PRECISION = 0.2;
String name = null;
IndexHeightData hd = new IndexHeightData();
hd.setSrtmData(new File("/Users/victorshcherb/osmand/maps/srtm/"));
while ((next = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (next == XmlPullParser.START_TAG) {
if (parser.getName().equals("trkpt")) {
ele = SPECIAL_VALUE;
LatLon ls = new LatLon(Float.parseFloat(parser.getAttributeValue("", "lat")), Float.parseFloat(parser.getAttributeValue("", "lon")));
l.add(ls);
}
name = parser.getName();
} else if (next == XmlPullParser.TEXT) {
if (name.equals("ele") && ele == SPECIAL_VALUE) {
ele = Double.parseDouble(parser.getText());
h.add((float) ele);
}
} else if (next == XmlPullParser.END_TAG) {
if (parser.getName().equals("trkpt") && ele == SPECIAL_VALUE) {
h.add(0f);
}
}
}
float d = 0;
for (int i = 0; i < l.size(); i++) {
if (i == 0) {
System.out.println(0 + " " + h.get(0) + " ");
} else {
LatLon nxt = l.get(i);
LatLon prv = l.get(i - 1);
double dist = MapUtils.getDistance(prv, nxt);
int cf = 1;
while (dist / cf > ROUTE_PRECISION) {
cf *= 2;
}
float ph = h.get(i - 1);
double plat = prv.getLatitude();
double plon = prv.getLongitude();
for (int j = 0; j < cf; j++) {
double nlat = (nxt.getLatitude() - prv.getLatitude()) / cf + plat;
double nlon = (nxt.getLongitude() - prv.getLongitude()) / cf + plon;
float ch = (h.get(i) - h.get(i - 1)) / cf + ph;
d += MapUtils.getDistance(plat, plon, nlat, nlon);
USE_BILINEAR_INTERPOLATION = true;
double blh = hd.getPointHeight(nlat, nlon, null);
USE_BILINEAR_INTERPOLATION = false;
double bch = hd.getPointHeight(nlat, nlon, null);
plat = nlat;
plon = nlon;
ph = ch;
System.out.println(d + "\t" + ch + "\t" + bch + "\t" + blh);
}
}
}
}
use of net.osmand.data.LatLon in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method writeAddressNameIndex.
public void writeAddressNameIndex(Map<String, List<MapObject>> namesIndex) throws IOException {
checkPeekState(ADDRESS_INDEX_INIT);
codedOutStream.writeTag(OsmAndAddressIndex.NAMEINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
preserveInt32Size();
Map<String, BinaryFileReference> res = writeIndexedTable(OsmAndAddressNameIndexData.TABLE_FIELD_NUMBER, namesIndex.keySet());
for (Entry<String, List<MapObject>> entry : namesIndex.entrySet()) {
BinaryFileReference ref = res.get(entry.getKey());
codedOutStream.writeTag(OsmAndAddressNameIndexData.ATOM_FIELD_NUMBER, FieldType.MESSAGE.getWireType());
codedOutStream.flush();
long pointer = getFilePointer();
if (ref != null) {
ref.writeReference(raf, getFilePointer());
}
AddressNameIndexData.Builder builder = AddressNameIndexData.newBuilder();
// collapse same name ?
for (MapObject o : entry.getValue()) {
AddressNameIndexDataAtom.Builder atom = AddressNameIndexDataAtom.newBuilder();
// this is optional
// atom.setName(o.getName());
// if(checkEnNameToWrite(o)){
// atom.setNameEn(o.getEnName());
// }
int type = 1;
if (o instanceof City) {
if (((City) o).isPostcode()) {
type = 2;
} else {
CityType ct = ((City) o).getType();
if (ct != CityType.CITY && ct != CityType.TOWN) {
type = 3;
}
}
} else if (o instanceof Street) {
type = 4;
}
atom.setType(type);
LatLon ll = o.getLocation();
int x = (int) MapUtils.getTileNumberX(16, ll.getLongitude());
int y = (int) MapUtils.getTileNumberY(16, ll.getLatitude());
atom.addXy16((x << 16) + y);
atom.addShiftToIndex((int) (pointer - o.getFileOffset()));
if (o instanceof Street) {
atom.addShiftToCityIndex((int) (pointer - ((Street) o).getCity().getFileOffset()));
}
builder.addAtom(atom.build());
}
codedOutStream.writeMessageNoTag(builder.build());
}
int len = writeInt32Size();
log.info("ADDRESS NAME INDEX SIZE : " + len);
}
Aggregations