-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1371 from osmdroid/bug/#1299_3
bug/#1299_3 - demo for "Snappable" feature
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/events/SampleSnappable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.osmdroid.samplefragments.events; | ||
|
||
import android.graphics.Point; | ||
|
||
import org.osmdroid.api.IMapView; | ||
import org.osmdroid.api.IProjection; | ||
import org.osmdroid.samplefragments.BaseSampleFragment; | ||
import org.osmdroid.util.GeoPoint; | ||
import org.osmdroid.views.overlay.Overlay; | ||
|
||
/** | ||
* @since 6.1.0 | ||
* @author Fabrice Fontaine | ||
*/ | ||
public class SampleSnappable extends BaseSampleFragment { | ||
|
||
// cf. https://en.wikipedia.org/wiki/Gare_de_Perpignan | ||
private final GeoPoint MAP_CENTER = new GeoPoint(42.696111, 2.879444); | ||
|
||
@Override | ||
public String getSampleTitle() { | ||
return "Snappable"; | ||
} | ||
|
||
class MyOverlay extends Overlay implements Overlay.Snappable { | ||
|
||
@Override | ||
public boolean onSnapToItem(int x, int y, Point snapPoint, IMapView mapView) { | ||
final IProjection projection = mapView.getProjection(); | ||
projection.toPixels(MAP_CENTER, snapPoint); | ||
return true; | ||
} | ||
} | ||
|
||
@Override | ||
protected void addOverlays() { | ||
super.addOverlays(); | ||
|
||
mMapView.getOverlayManager().add(new MyOverlay()); | ||
mMapView.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
mMapView.getController().setZoom(14.); | ||
mMapView.setExpectedCenter(MAP_CENTER); | ||
} | ||
}); | ||
} | ||
} |