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

The following examples show how to use org.osmdroid.views.overlay.Marker#setImage() . 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: IISTrackerBase.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
protected void addOverlays() {
    super.addOverlays();

    mMapView.setTilesScaledToDpi(true);
    mMapView.getController().setZoom(3);

    cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);

    image = getResources().getDrawable(R.drawable.sfppt);
    icon =getResources().getDrawable(R.drawable.sfppt_small);
    //icon_old=getResources().getDrawable(R.drawable.sfppt_small);
    //icon_old.setAlpha(77);

    marker = new Marker(mMapView);
    marker.setImage(image);
    marker.setIcon(icon);
    marker.setTitle("International Space Station");


}
 
Example 2
Source File: SampleCustomMyLocation.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void addOverlays() {
    super.addOverlays();
    myLocation = new Marker(mMapView);
    myLocation.setIcon(getResources().getDrawable(org.osmdroid.R.drawable.icon));
    myLocation.setImage(getResources().getDrawable(org.osmdroid.R.drawable.icon));


}
 
Example 3
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 4
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 5
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;
    }
}