Java Code Examples for org.osmdroid.views.overlay.Marker#setSnippet()

The following examples show how to use org.osmdroid.views.overlay.Marker#setSnippet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeOpenStreetMapController.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
private void createNativeMarker(final MapMarker aiMarker,
    AsyncCallbackPair<Marker> callback) {
  final Marker osmMarker = new Marker(view);
  featureOverlays.put(aiMarker, osmMarker);
  osmMarker.setDraggable(aiMarker.Draggable());
  osmMarker.setTitle(aiMarker.Title());
  osmMarker.setSnippet(aiMarker.Description());
  osmMarker.setPosition(new GeoPoint(aiMarker.Latitude(), aiMarker.Longitude()));
  osmMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
  getMarkerDrawable(aiMarker, new AsyncCallbackFacade<Drawable, Marker>(callback) {
    @Override
    public void onFailure(String message) {
      callback.onFailure(message);
    }

    @Override
    public void onSuccess(Drawable result) {
      osmMarker.setIcon(result);
      callback.onSuccess(osmMarker);
    }
  });
}
 
Example 2
Source File: BookmarkDatastore.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public List<Marker> getBookmarksAsMarkers(MapView view) {
    List<Marker> markers = new ArrayList<>();
    try {
        //TODO order by title
        final Cursor cur = mDatabase.rawQuery("SELECT * FROM " + TABLE, null);
        while(cur.moveToNext()) {
            Marker m = new Marker(view);
            m.setId(cur.getString(cur.getColumnIndex(COLUMN_ID)));
            m.setTitle(cur.getString(cur.getColumnIndex(COLUMN_TITLE)));
            m.setSubDescription(cur.getString(cur.getColumnIndex(COLUMN_DESC)));
            m.setPosition(new GeoPoint(cur.getDouble(cur.getColumnIndex(COLUMN_LAT)),cur.getDouble(cur.getColumnIndex(COLUMN_LON))));
            m.setSnippet(m.getPosition().toDoubleString());

            markers.add(m);
        }
        cur.close();
    } catch (final Exception e) {
        Log.w(IMapView.LOGTAG,"Error getting tile sources: ", e);
    }
    return markers;
}
 
Example 3
Source File: SampleMilitaryIconsMarker.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
private void addIcons(int count) {
     for (int i = 0; i < count; i++) {
          double random_lon = MapView.getTileSystem().getRandomLongitude(mRandom.nextDouble());
          double random_lat = MapView.getTileSystem().getRandomLatitude(mRandom.nextDouble());
          Marker m = new Marker(mMapView);
          m.setPosition(new GeoPoint(random_lat, random_lon));
          final int index = mRandom.nextInt(icons.size());
          m.setSnippet("A random point");
          m.setSubDescription("location: " + random_lat + "," + random_lon);
          m.setIcon(icons.get(index));
          mMapView.getOverlayManager().add(m);
     }

     mMapView.invalidate();
     Toast.makeText(getActivity(), count + " icons added! Current size: " + mMapView.getOverlayManager().size(), Toast.LENGTH_SHORT).show();

}
 
Example 4
Source File: DefaultShapeMetaSetter.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void set(DbfRecord metadata, Marker marker) throws ParseException {
    if (metadata != null) {
        metadata.setStringCharset(Charset.defaultCharset());
        marker.setSnippet(metadata.toMap().toString());
        marker.setTitle(getSensibleTitle(marker.getSnippet()));
    }
}
 
Example 5
Source File: IconPlottingOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {
    if (markerIcon != null) {
        GeoPoint pt = (GeoPoint) mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY(), null);
        /*
         * <b>Note</b></b: when plotting a point off the map, the conversion from
             * screen coordinates to map coordinates will return values that are invalid from a latitude,longitude
             * perspective. Sometimes this is a wanted behavior and sometimes it isn't. We are leaving it up to you,
             * the developer using osmdroid to decide on what is right for your application. See
             * <a href="https://github.com/osmdroid/osmdroid/pull/722">https://github.com/osmdroid/osmdroid/pull/722</a>
             * for more information and the discussion associated with this.
         */

        //just in case the point is off the map, let's fix the coordinates
        if (pt.getLongitude() < -180)
            pt.setLongitude(pt.getLongitude()+360);
        if (pt.getLongitude() > 180)
            pt.setLongitude(pt.getLongitude()-360);
        //latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
        if (pt.getLatitude() > mapView.getTileSystem().getMaxLatitude())
            pt.setLatitude(mapView.getTileSystem().getMaxLatitude());
        if (pt.getLatitude() < mapView.getTileSystem().getMinLatitude())
            pt.setLatitude(mapView.getTileSystem().getMinLatitude());

        Marker m = new Marker(mapView);
        m.setPosition(pt);
        m.setIcon(markerIcon);
        m.setImage(markerIcon);
        m.setTitle("A demo title");
        m.setSubDescription("A demo sub description\n" + pt.getLatitude() + "," + pt.getLongitude());
        m.setSnippet("a snippet of information");
        mapView.getOverlayManager().add(m);
        mapView.invalidate();
        return true;
    }
    return false;
}
 
Example 6
Source File: Bug512Marker.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void addOverlays(){
    super.addOverlays();
    marker = new Marker(mMapView);
    marker.setSnippet("Hello world, bug 512 part 1");
    marker.setPosition(new GeoPoint(-40d,-74d));
    mMapView.getController().setCenter(marker.getPosition());
    mMapView.getOverlayManager().add(marker);
}
 
Example 7
Source File: MilStdPointPlottingOverlay.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {
    if (def != null) {
        GeoPoint pt = (GeoPoint) mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY(), null);

        //just in case the point is off the map, let's fix the coordinates
        if (pt.getLongitude() < -180)
            pt.setLongitude(pt.getLongitude() + 360);
        if (pt.getLongitude() > 180)
            pt.setLongitude(pt.getLongitude() - 360);
        //latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
        if (pt.getLatitude() > mapView.getTileSystem().getMaxLatitude())
            pt.setLatitude(mapView.getTileSystem().getMaxLatitude());
        if (pt.getLatitude() < mapView.getTileSystem().getMinLatitude())
            pt.setLatitude(mapView.getTileSystem().getMinLatitude());

        String code = def.getSymbolCode().replace("*", "-");
        //TODO if (!def.isMultiPoint())
        {
            int size = 128;

            SparseArray<String> attr = new SparseArray<>();
            attr.put(MilStdAttributes.PixelSize, size + "");

            ImageInfo ii = MilStdIconRenderer.getInstance().RenderIcon(code, def.getModifiers(), attr);
            Marker m = new Marker(mapView);
            m.setPosition(pt);
            m.setTitle(code);
            m.setSnippet(def.getDescription() + "\n" + def.getHierarchy());
            m.setSubDescription(def.getPath() + "\n" + m.getPosition().getLatitude() + "," + m.getPosition().getLongitude());

            if (ii != null && ii.getImage() != null) {
                BitmapDrawable d = new BitmapDrawable(ii.getImage());
                m.setImage(d);
                m.setIcon(d);

                int centerX = ii.getCenterPoint().x;    //pixel center position
                //calculate what percentage of the center this value is
                float realCenterX = (float) centerX / (float) ii.getImage().getWidth();

                int centerY = ii.getCenterPoint().y;
                float realCenterY = (float) centerY / (float) ii.getImage().getHeight();
                m.setAnchor(realCenterX, realCenterY);


                mapView.getOverlayManager().add(m);
                mapView.invalidate();
            }
        }

        return true;
    }
    return false;
}
 
Example 8
Source File: Plotter.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.radio_milstd2525b:
        case R.id.radio_milstd2525c:
            if (((RadioButton) v).isChecked()) {
                RendererSettings.getInstance().setSymbologyStandard(RendererSettings.Symbology_2525C);
            } else
                RendererSettings.getInstance().setSymbologyStandard(RendererSettings.Symbology_2525B);
            break;
        case R.id.cancelAddIcon:
            picker.dismiss();
            break;
        case R.id.addIcon:
            //from the menu, user entered code
            String code = symbolCode.getText().toString();
            int size = 128;
            try {
                size = Integer.parseInt(symbolSize.getText().toString());
            } catch (Exception ex) {
            }
            String baseCode = SymbolUtilities.getBasicSymbolID(code);
            SymbolDef def = SymbolDefTable.getInstance().getSymbolDef(baseCode, RendererSettings.getInstance().getSymbologyStandard());

            SparseArray<String> attr = new SparseArray<>();
            attr.put(MilStdAttributes.PixelSize, size + "");

            ImageInfo ii = mir.RenderIcon(code, new SparseArray<String>(), attr);
            Marker m = new Marker(mMapView);
            m.setPosition((GeoPoint) mMapView.getMapCenter());
            m.setTitle(code);
            if (def != null) {
                m.setSubDescription(def.getFullPath());
                m.setSnippet(def.getDescription() + "\n" + def.getHierarchy());
            }
            Drawable d = new BitmapDrawable(ii.getImage());
            m.setImage(d);
            m.setIcon(d);
            int centerX = ii.getCenterPoint().x;    //pixel center position
            //calculate what percentage of the center this value is
            float realCenterX = (float) centerX / (float) ii.getImage().getWidth();

            int centerY = ii.getCenterPoint().y;
            float realCenterY = (float) centerY / (float) ii.getImage().getHeight();
            m.setAnchor(realCenterX, realCenterY);
            mMapView.getOverlayManager().add(m);
            mMapView.invalidate();
            picker.dismiss();

            //TODO store the symbol code and size as an android preference
            SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
            edit.putString("MILSTDCODE", code);
            RendererSettings.getInstance().setDefaultPixelSize(size);
            edit.putInt("MILSTDSIZE", size);
            edit.commit();

            break;
        case R.id.enablePanning:
            enablePanning();

            break;
        case R.id.enablePainting:
            enablePainting();
            break;
    }
}