Using Callbacks
Using Mappedin SDK for Android with your own map requires an Enterprise license. Try a demo map for free or refer to the Pricing page for more information.
The Mappedin Mobile SDKs offer callback functions that developers can use to trigger various events based on the completion of certain actions. These methods are useful for modifying UI elements such as loading views, changing floors, changing polygon colours, adding markers etc.
An MPIMapViewListener
will respond to events triggered by the MPIMapView
. To listen to these events, create or modify a class to fit the MPIMapViewListener
interface and implement the methods you'd like to use. They will be executed automatically after the corresponding event has occurred.
onDataLoaded
A callback function that is executed when the 3D files have been downloaded for the first map, and are starting to load into memory. The MPIMapView
is fully functional at this point, but some things will still be popping in.
At this point, you can interact with the MPIMapView
, venue data, call helper functions, call other mapView functions, and set up your application. This function will pass in an MPIData
parameter, data
, which allows you to use maps, locations, polygons, nodes, vortexes, and map groups of the venue. For example, you can access the list of a venue’s locations by using the class variable locations of the data parameter. You can also call other mapView
functions here. For example, you can label your polygons by calling labelPolygon and passing in both an MPIPolygon
parameter and various customization options for your labels.
onFirstMapLoaded
A callback that is executed when the first map is fully loaded. This means onDataLoaded
has already been fired (if specified) and all the textures and other resources have finished popping in.
onMapChanged
A callback function that is executed when the map of your MPIMapView
changes. A common use of this callback is to add a level selector for your venue. If you are working with a venue that has multiple maps (such as a venue with multiple floors) you may want to create a dropdown to allow the user to select a level. When you change the map, this callback will be executed, and it will pass in an MPIMap
parameter, map
, which is the current map. You can access different properties of map
using this parameter.
Sample Code
class MainActivity : AppCompatActivity(), MPIMapViewListener {
override fun onBlueDotPositionUpdate(update: MPIBlueDotPositionUpdate) {
// Called when the blueDot that tracks the user position is updated
}
override fun onBlueDotStateChange(stateChange: MPIBlueDotStateChange) {
// Called when the state of blueDot is changed
}
override fun onMapChanged(map: MPIMap) {
// Called when the map is changed
}
override fun onPolygonClicked(polygon: MPIPolygon) {
// Called when the polygon is clicked
}
override fun onNothingClicked() {
// Called when a tap doesn't hit any spaces
}
override fun onDataLoaded(data: MPIData) {
// Called when the mapView has finished loading both the view and venue data
}
override fun onFirstMapLoaded() {
// Called when the first map is fully loaded
}
override fun onStateChanged(state: MPIState) {
// Called when the state of the map has changed
}
}