public void getAmenityFromPoint(PointF point, List<? super Amenity> am) { if (objects != null) { int ex = (int) point.x; int ey = (int) point.y; int compare = getRadiusPoi(view.getZoom()); int radius = getRadiusPoi(view.getZoom()) * 3 / 2; try { for (int i = 0; i < objects.size(); i++) { Amenity n = objects.get(i); int x = view.getRotatedMapXForPoint( n.getLocation().getLatitude(), n.getLocation().getLongitude()); int y = view.getRotatedMapYForPoint( n.getLocation().getLatitude(), n.getLocation().getLongitude()); if (Math.abs(x - ex) <= compare && Math.abs(y - ey) <= compare) { compare = radius; am.add(n); } } } catch (IndexOutOfBoundsException e) { // that's really rare case, but is much efficient than introduce synchronized block } } }
@Override public Node loadNode(Amenity n) { if (n.getId() % 2 == 1) { // that's way id return null; } long nodeId = n.getId() >> 1; // EntityId id = new Entity.EntityId(EntityType.NODE, nodeId); Node entity = new Node(n.getLocation().getLatitude(), n.getLocation().getLongitude(), nodeId); Map<AmenityType, Map<String, String>> typeNameToTagVal = MapRenderingTypes.getDefault().getAmenityTypeNameToTagVal(); AmenityType type = n.getType(); String tag = type.getDefaultTag(); String subType = n.getSubType(); String val = subType; if (typeNameToTagVal.containsKey(type)) { Map<String, String> map = typeNameToTagVal.get(type); if (map.containsKey(subType)) { String res = map.get(subType); if (res != null) { int i = res.indexOf(' '); if (i != -1) { tag = res.substring(0, i); val = res.substring(i + 1); } else { tag = res; } } } } entity.putTag(tag, val); entity.putTag(OSMTagKey.NAME.getValue(), n.getName()); entity.putTag(OSMTagKey.OPENING_HOURS.getValue(), n.getOpeningHours()); // check whether this is node (because id of node could be the same as relation) if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) { return entity; } return null; }
@Override public Node loadNode(Amenity n) { if (n.getId() % 2 == 1) { // that's way id return null; } long nodeId = n.getId() >> 1; try { String res = sendRequest( SITE_API + "api/0.6/node/" + nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$ if (res != null) { OsmBaseStorage st = new OsmBaseStorage(); st.parseOSM( new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); // $NON-NLS-1$ EntityId id = new Entity.EntityId(EntityType.NODE, nodeId); Node entity = (Node) st.getRegisteredEntities().get(id); entityInfo = st.getRegisteredEntityInfo().get(id); // check whether this is node (because id of node could be the same as relation) if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) { return entity; } return null; } } catch (IOException e) { log.error("Loading node failed " + nodeId, e); // $NON-NLS-1$ AccessibleToast.makeText( ctx, ctx.getResources().getString(R.string.error_io_error), Toast.LENGTH_LONG) .show(); } catch (SAXException e) { log.error("Loading node failed " + nodeId, e); // $NON-NLS-1$ AccessibleToast.makeText( ctx, ctx.getResources().getString(R.string.error_io_error), Toast.LENGTH_LONG) .show(); } return null; }
@Override public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, DrawSettings nightMode) { if (view.getZoom() >= startZoom) { objects.clear(); resourceManager.searchAmenitiesAsync( latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, view.getZoom(), filter, objects); int r = getRadiusPoi(view.getZoom()); for (Amenity o : objects) { int x = view.getRotatedMapXForPoint( o.getLocation().getLatitude(), o.getLocation().getLongitude()); int y = view.getRotatedMapYForPoint( o.getLocation().getLatitude(), o.getLocation().getLongitude()); canvas.drawCircle(x, y, r, pointAltUI); canvas.drawCircle(x, y, r, point); String id = null; if (RenderingIcons.containsIcon(o.getSubType())) { id = o.getSubType(); } else if (RenderingIcons.containsIcon( o.getType().getDefaultTag() + "_" + o.getSubType())) { id = o.getType().getDefaultTag() + "_" + o.getSubType(); } if (id != null) { Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id); if (bmp != null) { canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon); } } } if (view.getSettings().SHOW_POI_LABEL.get()) { TIntHashSet set = new TIntHashSet(); for (Amenity o : objects) { int x = view.getRotatedMapXForPoint( o.getLocation().getLatitude(), o.getLocation().getLongitude()); int y = view.getRotatedMapYForPoint( o.getLocation().getLatitude(), o.getLocation().getLongitude()); int tx = view.getMapXForPoint(o.getLocation().getLongitude()); int ty = view.getMapYForPoint(o.getLocation().getLatitude()); String name = o.getName(view.getSettings().USE_ENGLISH_NAMES.get()); if (name != null && name.length() > 0) { int lines = 0; while (lines < TEXT_LINES) { if (set.contains(division(tx, ty, 0, lines)) || set.contains(division(tx, ty, -1, lines)) || set.contains(division(tx, ty, +1, lines))) { break; } lines++; } if (lines == 0) { // drawWrappedText(canvas, "...", paintTextIcon.getTextSize(), x, y + r + 2 + // paintTextIcon.getTextSize() / 2, 1); } else { drawWrappedText( canvas, name, paintTextIcon.getTextSize(), x, y + r + 2 + paintTextIcon.getTextSize() / 2, lines); while (lines > 0) { set.add(division(tx, ty, 1, lines - 1)); set.add(division(tx, ty, -1, lines - 1)); set.add(division(tx, ty, 0, lines - 1)); lines--; } } } } } } }
@Override public double getLongitude() { return a.getLocation().getLongitude(); }