Java Code Examples for org.osmdroid.views.MapView#getProjection()
The following examples show how to use
org.osmdroid.views.MapView#getProjection() .
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: SimpleFastPointOverlay.java From osmdroid with Apache License 2.0 | 6 votes |
@Override public boolean onTouchEvent(MotionEvent event, final MapView mapView) { if(mStyle.mAlgorithm != SimpleFastPointOverlayOptions.RenderingAlgorithm.MAXIMUM_OPTIMIZATION) return false; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: startBoundingBox = mapView.getBoundingBox(); startProjection = mapView.getProjection(); break; case MotionEvent.ACTION_MOVE: hasMoved = true; break; case MotionEvent.ACTION_UP: hasMoved = false; startBoundingBox = mapView.getBoundingBox(); startProjection = mapView.getProjection(); mapView.invalidate(); break; } return false; }
Example 2
Source File: PolyOverlayWithIW.java From osmdroid with Apache License 2.0 | 6 votes |
/** * Used to be in both {@link Polyline} and {@link Polygon} * Default listener for a single tap event on a Poly: * set the infowindow at the tapped position, and open the infowindow (if any). * @return true if tapped */ @Override public boolean onSingleTapConfirmed(final MotionEvent pEvent, final MapView pMapView){ final Projection projection = pMapView.getProjection(); final GeoPoint eventPos = (GeoPoint) projection.fromPixels((int)pEvent.getX(), (int)pEvent.getY()); final GeoPoint geoPoint; if (mPath != null) { final boolean tapped = contains(pEvent); if (tapped) { geoPoint = eventPos; } else { geoPoint = null; } } else { final double tolerance = mOutlinePaint.getStrokeWidth() * mDensity * mDensityMultiplier; geoPoint = getCloseTo(eventPos, tolerance, pMapView); } if (geoPoint != null) { return click(pMapView, geoPoint); } return false; }
Example 3
Source File: OsmMarker.java From FancyPlaces with GNU General Public License v3.0 | 5 votes |
public boolean isHit(MotionEvent event, MapView mapView) { Projection pj = mapView.getProjection(); Point PositionPixels = new Point(); pj.toPixels(this.Position, PositionPixels); Rect screenRect = pj.getIntrinsicScreenRect(); int x = -PositionPixels.x + screenRect.left + (int) event.getX(); int y = -PositionPixels.y + screenRect.top + (int) event.getY(); boolean hit = this.Icon.getBounds().contains(x, y); return hit; }
Example 4
Source File: OsmMarker.java From FancyPlaces with GNU General Public License v3.0 | 5 votes |
@Override protected void draw(Canvas canvas, MapView mapView, boolean shadow) { if (this.Icon != null) { Projection pj = mapView.getProjection(); Point PositionPixels = new Point(); pj.toPixels(this.Position, PositionPixels); int width = this.Icon.getIntrinsicWidth(); int height = this.Icon.getIntrinsicHeight(); Rect rect = new Rect(0, 0, width, height); rect.offset(-((int) (this.AnchorU * (float) width)), -((int) (this.AnchorV * (float) height))); this.Icon.setBounds(rect); this.Icon.setAlpha((int) (this.Alpha * 255.0F)); drawAt(canvas, this.Icon, PositionPixels.x, PositionPixels.y, false, 0); } }
Example 5
Source File: ClickableIconOverlay.java From osmdroid with Apache License 2.0 | 5 votes |
/** * From {@link Marker#hitTest(MotionEvent, MapView)} * @return true, if this marker was taped. */ protected boolean hitTest(final MotionEvent event, final MapView mapView){ final Projection pj = mapView.getProjection(); // sometime at higher zoomlevels pj is null if ((mPosition == null) || (mPositionPixels == null) || (pj == null)) return false; pj.toPixels(mPosition, mPositionPixels); final Rect screenRect = pj.getIntrinsicScreenRect(); int x = -mPositionPixels.x + screenRect.left + (int) event.getX(); int y = -mPositionPixels.y + screenRect.top + (int) event.getY(); boolean hit = mIcon.getBounds().contains(x, y); return hit; }
Example 6
Source File: SimpleFastPointOverlay.java From osmdroid with Apache License 2.0 | 5 votes |
/** * Default action on tap is to select the nearest point. */ @Override public boolean onSingleTapConfirmed(final MotionEvent event, final MapView mapView) { if(!mStyle.mClickable) return false; float hyp; Float minHyp = null; int closest = -1; Point tmp = new Point(); Projection pj = mapView.getProjection(); for(int i = 0; i < mPointList.size(); i++) { if(mPointList.get(i) == null) continue; // TODO avoid projecting coordinates, do a test before calling next line pj.toPixels(mPointList.get(i), tmp); if(Math.abs(event.getX() - tmp.x) > 50 || Math.abs(event.getY() - tmp.y) > 50) continue; hyp = (event.getX() - tmp.x) * (event.getX() - tmp.x) + (event.getY() - tmp.y) * (event.getY() - tmp.y); if(minHyp == null || hyp < minHyp) { minHyp = hyp; closest = i; } } if(minHyp == null) return false; setSelectedPoint(closest); mapView.invalidate(); if(clickListener != null) clickListener.onClick(mPointList, closest); return true; }
Example 7
Source File: MapSnapshot.java From osmdroid with Apache License 2.0 | 5 votes |
public MapSnapshot(final MapSnapshotable pMapSnapshotable, final int pIncludeFlags, final MapView pMapView) { this(pMapSnapshotable, pIncludeFlags, pMapView.getTileProvider(), pMapView.getOverlays(), pMapView.getProjection() ); }
Example 8
Source File: FragmentiGapMap.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
private void drawMark(MotionEvent motionEvent, MapView mapView) { Projection projection = mapView.getProjection(); GeoPoint loc = (GeoPoint) projection.fromPixels((int) motionEvent.getX(), (int) motionEvent.getY()); OverlayItem mapItem = new OverlayItem("", "", new GeoPoint((((double) loc.getLatitudeE6()) / 1000000), (((double) loc.getLongitudeE6()) / 1000000))); drawMark(mapItem, false, 0); }
Example 9
Source File: Marker.java From osmdroid with Apache License 2.0 | 4 votes |
public void moveToEventPosition(final MotionEvent event, final MapView mapView){ float offsetY = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, mDragOffsetY, mapView.getContext().getResources().getDisplayMetrics()); final Projection pj = mapView.getProjection(); setPosition((GeoPoint) pj.fromPixels((int)event.getX(), (int)(event.getY()-offsetY))); mapView.invalidate(); }
Example 10
Source File: MapEventsOverlay.java From osmdroid with Apache License 2.0 | 4 votes |
@Override public boolean onSingleTapConfirmed(MotionEvent e, MapView mapView){ Projection proj = mapView.getProjection(); GeoPoint p = (GeoPoint)proj.fromPixels((int)e.getX(), (int)e.getY()); return mReceiver.singleTapConfirmedHelper(p); }
Example 11
Source File: MapEventsOverlay.java From osmdroid with Apache License 2.0 | 4 votes |
@Override public boolean onLongPress(MotionEvent e, MapView mapView) { Projection proj = mapView.getProjection(); GeoPoint p = (GeoPoint)proj.fromPixels((int)e.getX(), (int)e.getY()); //throw event to the receiver: return mReceiver.longPressHelper(p); }
Example 12
Source File: IconOverlay.java From osmdroid with Apache License 2.0 | 4 votes |
public IconOverlay moveTo(final MotionEvent event, final MapView mapView){ final Projection pj = mapView.getProjection(); moveTo(pj.fromPixels((int) event.getX(), (int) event.getY()), mapView); return this; }