Search in sources :

Example 11 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class BinaryMapIndexReader method testSearchOnthePath.

private static void testSearchOnthePath(BinaryMapIndexReader reader) throws IOException {
    float radius = 1000;
    final MapPoiTypes poiTypes = MapPoiTypes.getDefault();
    long now = System.currentTimeMillis();
    println("Searching poi on the path...");
    final List<Location> locations = readGPX(new File("/Users/victorshcherb/osmand/maps/2015-03-07_19-07_Sat.gpx"));
    SearchRequest<Amenity> req = buildSearchPoiRequest(locations, radius, new SearchPoiTypeFilter() {

        @Override
        public boolean accept(PoiCategory type, String subcategory) {
            if (type == poiTypes.getPoiCategoryByName("shop") && subcategory.contains("super")) {
                return true;
            }
            return false;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }
    }, null);
    req.zoom = -1;
    List<Amenity> results = reader.searchPoi(req);
    int k = 0;
    println("Search done in " + (System.currentTimeMillis() - now) + " ms ");
    now = System.currentTimeMillis();
    for (Amenity a : results) {
        final float dds = dist(a.getLocation(), locations);
        if (dds <= radius) {
            println("+ " + a.getType() + " " + a.getSubType() + " Dist " + dds + " (=" + (float) a.getRoutePoint().deviateDistance + ") " + a.getName() + " " + a.getLocation());
            k++;
        } else {
            println(a.getType() + " " + a.getSubType() + " Dist " + dds + " " + a.getName() + " " + a.getLocation());
        }
    }
    println("Filtered in " + (System.currentTimeMillis() - now) + "ms " + k + " of " + results.size());
}
Also used : Amenity(net.osmand.data.Amenity) MapPoiTypes(net.osmand.osm.MapPoiTypes) PoiCategory(net.osmand.osm.PoiCategory) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Location(net.osmand.Location)

Example 12 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class MapMarkersLayer method collectObjectsFromPoint.

@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
    if (tileBox.getZoom() < 3) {
        return;
    }
    amenities.clear();
    OsmandApplication app = map.getMyApplication();
    int r = getDefaultRadiusPoi(tileBox);
    boolean selectMarkerOnSingleTap = app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get();
    for (MapMarker marker : app.getMapMarkersHelper().getMapMarkers()) {
        if ((!unknownLocation && selectMarkerOnSingleTap) || !isSynced(marker)) {
            LatLon latLon = marker.point;
            if (latLon != null) {
                int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
                int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
                if (calculateBelongs((int) point.x, (int) point.y, x, y, r)) {
                    if (!unknownLocation && selectMarkerOnSingleTap) {
                        o.add(marker);
                    } else {
                        if (isMarkerOnFavorite(marker) || isMarkerOnWaypoint(marker)) {
                            continue;
                        }
                        Amenity mapObj = getMapObjectByMarker(marker);
                        if (mapObj != null) {
                            amenities.add(mapObj);
                            o.add(mapObj);
                        } else {
                            o.add(marker);
                        }
                    }
                }
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) Amenity(net.osmand.data.Amenity) OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint)

Example 13 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class MapContextMenu method buttonWaypointPressed.

public void buttonWaypointPressed() {
    MapMarker marker = getMapMarker();
    if (marker != null) {
        RenameMarkerBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), marker);
    } else if (pointDescription.isMapMarker()) {
        hide();
        MapActivity.clearPrevActivityIntent();
        MapMarkersDialogFragment.showInstance(mapActivity);
    } else {
        String mapObjectName = null;
        if (object instanceof Amenity) {
            Amenity amenity = (Amenity) object;
            mapObjectName = amenity.getName() + "_" + amenity.getType().getKeyName();
        }
        mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), getPointDescriptionForMarker(), mapObjectName);
    }
    close();
}
Also used : Amenity(net.osmand.data.Amenity) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker)

Example 14 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class MenuBuilder method processNearstWiki.

protected boolean processNearstWiki() {
    if (showNearestWiki && latLon != null) {
        QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 250);
        nearestWiki = app.getResourceManager().searchAmenities(new BinaryMapIndexReader.SearchPoiTypeFilter() {

            @Override
            public boolean accept(PoiCategory type, String subcategory) {
                return type.isWiki();
            }

            @Override
            public boolean isEmpty() {
                return false;
            }
        }, rect.top, rect.left, rect.bottom, rect.right, -1, null);
        Collections.sort(nearestWiki, new Comparator<Amenity>() {

            @Override
            public int compare(Amenity o1, Amenity o2) {
                double d1 = MapUtils.getDistance(latLon, o1.getLocation());
                double d2 = MapUtils.getDistance(latLon, o2.getLocation());
                return Double.compare(d1, d2);
            }
        });
        Long id = objectId;
        List<Amenity> wikiList = new ArrayList<>();
        for (Amenity wiki : nearestWiki) {
            String lng = wiki.getContentLanguage("content", preferredMapAppLang, "en");
            if (wiki.getId().equals(id) || (!lng.equals("en") && !lng.equals(preferredMapAppLang))) {
                wikiList.add(wiki);
            }
        }
        nearestWiki.removeAll(wikiList);
        return true;
    }
    return false;
}
Also used : Amenity(net.osmand.data.Amenity) PoiCategory(net.osmand.osm.PoiCategory) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect)

Example 15 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class MenuBuilder method getCollapsableWikiView.

protected CollapsableView getCollapsableWikiView(Context context, boolean collapsed) {
    LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
    for (final Amenity wiki : nearestWiki) {
        TextViewEx button = buildButtonInCollapsableView(context, false, false);
        String name = wiki.getName(preferredMapAppLang, transliterateNames);
        button.setText(name);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                LatLon latLon = new LatLon(wiki.getLocation().getLatitude(), wiki.getLocation().getLongitude());
                PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(wiki);
                mapActivity.getContextMenu().show(latLon, pointDescription, wiki);
            }
        });
        view.addView(button);
    }
    return new CollapsableView(view, this, collapsed);
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) TextViewEx(net.osmand.plus.widgets.TextViewEx) PointDescription(net.osmand.data.PointDescription) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

Amenity (net.osmand.data.Amenity)53 LatLon (net.osmand.data.LatLon)17 ArrayList (java.util.ArrayList)11 PoiCategory (net.osmand.osm.PoiCategory)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)8 PoiType (net.osmand.osm.PoiType)8 PointDescription (net.osmand.data.PointDescription)7 Paint (android.graphics.Paint)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 FavouritePoint (net.osmand.data.FavouritePoint)6 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)5 File (java.io.File)5 Map (java.util.Map)5 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 QuadRect (net.osmand.data.QuadRect)5 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 LinearLayout (android.widget.LinearLayout)4