I am using the nutiteq SDK for loading the map mbtiles.
I got the event which which fires when zoom/ rotate/tilt/drag happens. But all this comes under one listener as per the documentation.
Sample code:
public class MyMapEventListener extends MapEventListener {
private final MapView mapView;
private final LocalVectorDataSource vectorDataSource;
public MyMapEventListener(MapView mapView, LocalVectorDataSource vectorDataSource) {
this.mapView = mapView;
this.vectorDataSource = vectorDataSource;
}
@Override
public void onMapMoved() {
// super.onMapMoved();
Toast.makeText(mapView.getContext(),(int)mapView.getZoom()+"",Toast.LENGTH_SHORT).show();
}
How can i figure out which event is happening (rotate/zoom/tilt/drag) when onMapMoved()
method is called?
You can get and remember last MapView
state, and compare with new one - if zoom is changed then it was zoom etc. Be ready that one gestures can include several events (can zoom and rotate with same movement, for example).
But why you need these events exactly? Normally apps do not need it, maybe there is better way to implement same application feature.
I want to show area labels on the map based on the zoom level
Ok, that's a different question, as I suspected :) There are ways to have zoom level based object display without listening of map events, so the display control is done automatically for you. Your map view can be even tilted, then you do not have same zoom level for whole map area and performance of listener-based tricks would be bad in any case.
So the proper solutions would be to use different layers, and limit zoom of each with something like following. Note that you can use same datasource (probably you have LocalVectorDataSource
there) for both layers.
// 1. Initialize a local vector data source and layer
LocalVectorDataSource vectorDataSource = new LocalVectorDataSource(proj);
// Initialize a vector layer with the previous data source
VectorLayer vectorLayer = new VectorLayer(vectorDataSource);
// Add the previous vector layer to the map
mapView.getLayers().add(vectorLayer);
// Set visible zoom range for the vector layer
vectorLayer.setVisibleZoomRange(new MapRange(10, 24));
// Now add the text to the vectorDataSource:
// Create text style
TextStyleBuilder textStyleBuilder = new TextStyleBuilder();
textStyleBuilder.setColor(new Color(0xFFFF0000));
textStyleBuilder.setOrientationMode(BillboardOrientation.BILLBOARD_ORIENTATION_FACE_CAMERA);
// Add text
Text textpopup1 = new Text(proj.fromWgs84(new MapPos(24.653302, 59.422269)),
textStyleBuilder.buildStyle(),
"My text");
vectorDataSource.add(textpopup1);