Skip to content
Permalink
Browse files

bug/#1299_3 - demo for "Snappable" feature

...in "More Sample / Events / Snappable"

New class:
* `SampleSnappable`: demo for the "snap" feature, centered on the railway station of Perpignan

Impacted classes:
* `SampleFactory`: added the `SampleSnappable` demo
  • Loading branch information...
monsieurtanuki committed Jul 15, 2019
1 parent cecd937 commit e6d012f86f7b200cefc500b4ada082957d27231b
@@ -37,6 +37,7 @@
import org.osmdroid.samplefragments.data.SampleSimpleFastPointOverlay;
import org.osmdroid.samplefragments.data.SampleSimpleLocation;
import org.osmdroid.samplefragments.events.SampleAnimateToWithOrientation;
import org.osmdroid.samplefragments.events.SampleSnappable;
import org.osmdroid.samplefragments.tileproviders.SampleTileStates;
import org.osmdroid.samplefragments.data.SampleWithMinimapItemizedOverlayWithFocus;
import org.osmdroid.samplefragments.data.SampleWithMinimapItemizedOverlayWithScale;
@@ -305,6 +306,7 @@ private SampleFactory() {
mSamples.add(SampleTileStates.class);
mSamples.add(SampleAnimateToWithOrientation.class);
mSamples.add(SampleMapSnapshot.class);
mSamples.add(SampleSnappable.class);
}

public void addSample(Class<? extends BaseSampleFragment> clz) {
@@ -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);
}
});
}
}

0 comments on commit e6d012f

Please sign in to comment.
You can’t perform that action at this time.