org.osmdroid.views.overlay.Overlay Java Examples

The following examples show how to use org.osmdroid.views.overlay.Overlay. 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: MapSnapshot.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public MapSnapshot(final MapSnapshotable pMapSnapshotable,
                   final int pIncludeFlags,
                   final MapTileProviderBase pTileProvider,
                   final List<Overlay> pOverlays,
                   final Projection pProjection) {
    mMapSnapshotable = pMapSnapshotable;
    mIncludeFlags = pIncludeFlags;
    mTileProvider = pTileProvider;
    mOverlays = pOverlays;
    mProjection = pProjection;
    mProjection.getMercatorViewPort(mViewPort);
    mTilesOverlay = new TilesOverlay(mTileProvider, null);
    mTilesOverlay.setHorizontalWrapEnabled(mProjection.isHorizontalWrapEnabled());
    mTilesOverlay.setVerticalWrapEnabled(mProjection.isVerticalWrapEnabled());
    mHandler = new MapSnapshotHandler(this);
    mTileProvider.getTileRequestCompleteHandlers().add(mHandler);
}
 
Example #2
Source File: HeatMap.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * converts the bounding box into a color filled polygon
 *
 * @param key
 * @param value
 * @param redthreshold
 * @param orangethreshold
 * @return
 */
private Overlay createPolygon(BoundingBox key, Integer value, int redthreshold, int orangethreshold) {
    Polygon polygon = new Polygon(mMapView);
    if (value < orangethreshold)
        polygon.getFillPaint().setColor(Color.parseColor(alpha + yellow));
    else if (value < redthreshold)
        polygon.getFillPaint().setColor(Color.parseColor(alpha + orange));
    else if (value >= redthreshold)
        polygon.getFillPaint().setColor(Color.parseColor(alpha + red));
    else {
        //no polygon
    }
    polygon.getOutlinePaint().setColor(polygon.getFillPaint().getColor());

    //if you set this to something like 20f and have a low alpha setting,
    // you'll end with a gaussian blur like effect
    polygon.getOutlinePaint().setStrokeWidth(0f);
    List<GeoPoint> pts = new ArrayList<GeoPoint>();
    pts.add(new GeoPoint(key.getLatNorth(), key.getLonWest()));
    pts.add(new GeoPoint(key.getLatNorth(), key.getLonEast()));
    pts.add(new GeoPoint(key.getLatSouth(), key.getLonEast()));
    pts.add(new GeoPoint(key.getLatSouth(), key.getLonWest()));
    polygon.setPoints(pts);
    return polygon;
}
 
Example #3
Source File: SampleTileStates.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void addOverlays() {
    super.addOverlays();

    final Bitmap ok = ((BitmapDrawable)getResources().getDrawable(R.drawable.baseline_done_outline_black_36)).getBitmap();
    final Bitmap ko = ((BitmapDrawable)getResources().getDrawable(R.drawable.twotone_warning_black_36)).getBitmap();
    mMapView.getOverlayManager().add(new Overlay() {
        @Override
        public void draw(Canvas c, Projection projection) {
            final Bitmap bitmap = mOk ? ok : ko;
            c.drawBitmap(bitmap, c.getWidth() / 2 - bitmap.getWidth() / 2, c.getHeight() / 2 - bitmap.getHeight() / 2, null);
        }
    });
    mMapView.getMapOverlay().getTileStates().getRunAfters().add(new Runnable() {
        @Override
        public void run() {
            mTextView.setText(mTileStates.toString());
            mOk = mTileStates.isDone() && mTileStates.getTotal() == mTileStates.getUpToDate();
        }
    });
}
 
Example #4
Source File: OverlayAdapter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.drawer_list_item, parent, false);
    TextView view = rowView.findViewById(R.id.itemText);

    Overlay overlay = getItem(position);
    if (overlay!=null) {
        if (overlay instanceof OverlayWithIW) {
            String title  = ((OverlayWithIW) overlay).getTitle();
            if (title==null || title.length()==0)
                title = overlay.getClass().getSimpleName();
            view.setText(title);
        }
        else view.setText(overlay.getClass().getSimpleName());
    }
    return rowView;
}
 
Example #5
Source File: LocationActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
protected void clearMarkers() {
	synchronized (this.map.getOverlays()) {
		for (final Overlay overlay : this.map.getOverlays()) {
			if (overlay instanceof Marker || overlay instanceof MyLocation) {
				this.map.getOverlays().remove(overlay);
			}
		}
	}
}
 
Example #6
Source File: MapSnapshot.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
private void draw() {
    mBitmap = Bitmap.createBitmap(mProjection.getWidth(), mProjection.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(mBitmap);
    mProjection.save(canvas, true, false);
    mTilesOverlay.drawTiles(canvas, mProjection, mProjection.getZoomLevel(), mViewPort);
    if (mOverlays != null) {
        for (final Overlay overlay : mOverlays) {
            if (overlay != null && overlay.isEnabled()) {
                overlay.draw(canvas, mProjection);
            }
        }
    }
    mProjection.restore(canvas, false);
}
 
Example #7
Source File: ShapeConverter.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
public static List<Overlay>  convert(MapView map, File file) throws Exception {
    return convert(map, file, getDefaultValidationPreferences());
}
 
Example #8
Source File: AsyncTaskDemoFragment.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
private Overlay createMarker(double lat, double lon, int zoom) {
    return new IconOverlay(new GeoPoint(lat,lon), mMarkerIcon);
}
 
Example #9
Source File: SampleShapeFile.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
private void showPicker() {
    DialogProperties properties = new DialogProperties();
    properties.selection_mode = DialogConfigs.SINGLE_MODE;
    properties.selection_type = DialogConfigs.FILE_SELECT;
    properties.root = new File(DialogConfigs.DEFAULT_DIR);
    properties.error_dir = new File(DialogConfigs.DEFAULT_DIR);
    properties.offset = new File(DialogConfigs.DEFAULT_DIR);

    Set<String> registeredExtensions = ArchiveFileFactory.getRegisteredExtensions();
    registeredExtensions.add("shp");


    String[] ret = new String[registeredExtensions.size()];
    ret = registeredExtensions.toArray(ret);
    properties.extensions = ret;

    FilePickerDialog dialog = new FilePickerDialog(getContext(), properties);
    dialog.setTitle("Select a File");
    dialog.setDialogSelectionListener(new DialogSelectionListener() {
        @Override
        public void onSelectedFilePaths(String[] files) {
            //files is the array of the paths of files selected by the Application User.
            try {
                List<Overlay>  folder = ShapeConverter.convert(mMapView, new File(files[0]));
                for (final Overlay item : folder) {
                    if (item instanceof PolyOverlayWithIW) {
                        final PolyOverlayWithIW poly = (PolyOverlayWithIW)item;
                        poly.setDowngradePixelSizes(50, 25);
                        poly.setDowngradeDisplay(true);
                        final Paint paint = poly.getOutlinePaint();
                        paint.setStyle(Paint.Style.STROKE);
                        paint.setStrokeJoin(Paint.Join.ROUND);
                        paint.setStrokeCap(Paint.Cap.ROUND);
                    }
                }
                mMapView.getOverlayManager().addAll(folder);
                mMapView.invalidate();
            } catch (Exception e) {
                Toast.makeText(getActivity(), "Error importing file: " + e.getMessage(), Toast.LENGTH_LONG).show();
                Log.e(TAG, "error importing file from " + files[0], e);
            }

        }

    });
    dialog.show();

}
 
Example #10
Source File: OverlayAdapter.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
public Overlay getItem(int position) {
    return manager.get(position);
}
 
Example #11
Source File: SampleMapCenterOffset.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void addOverlays() {
	super.addOverlays();

	final Drawable drawable = getResources().getDrawable(R.drawable.marker_default);

	mList.add(new GeoPoint(38.8977, -77.0365));  // white house
	mList.add(new GeoPoint(38.8719, -77.0563));  // pentagon
	mList.add(new GeoPoint(38.8895, -77.0353));  // washington monument

	for (final GeoPoint geoPoint : mList) {
		final Marker startMarker = new Marker(mMapView);
		startMarker.setPosition(geoPoint);
		startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
		startMarker.setIcon(drawable);
		mMapView.getOverlays().add(startMarker);
	}

	mPaint.setColor(Color.RED);
	mPaint.setStrokeWidth(5);

	mMapView.getOverlays().add(new Overlay() {

		@Override
		public void draw(Canvas pCanvas, Projection pProjection) {
			mMapView.getProjection().save(pCanvas, false, true);
			final float centerX = pCanvas.getWidth() / 2f;
			final float centerY = pCanvas.getHeight() / 2f;
			pCanvas.drawLine(centerX, centerY, centerX + mOffsetX, centerY + mOffsetY, mPaint);
			mMapView.getProjection().restore(pCanvas, true);
		}
	});

	mMapView.setMapCenterOffset(mOffsetX, mOffsetY);
	mMapView.post(new Runnable() {
		@Override
		public void run() {
			show();
		}
	});
}
 
Example #12
Source File: ShapeConverter.java    From osmdroid with Apache License 2.0 2 votes vote down vote up
public static List<Overlay> convert(MapView map, File file, ValidationPreferences pref) throws Exception {

        return convert(map, file, pref, new DefaultShapeMetaSetter());
    }
 
Example #13
Source File: MapView.java    From osmdroid with Apache License 2.0 2 votes vote down vote up
/**
 * You can add/remove/reorder your Overlays using the List of {@link Overlay}. The first (index
 * 0) Overlay gets drawn first, the one with the highest as the last one.
 */
public List<Overlay> getOverlays() {
	return this.getOverlayManager().overlays();
}