In Situm Platform, a building can have a number of floors, each associated with a floorplan image.


For detailed information on floors & floorplans, you may read their introductory description and how to create them in Situm Dashboard. You may also find interesting their data models as provided by Situm REST API Floor methods and Situm SDK Floor model.



Fetching all the floors of a building


The following code snippet shows how to retrieve the floors of a certain building and output their information on the application Log. For this example, we will use building 8377, which we know from a previous example. Remember to change the building id 8377 for your building id.


//Fetches all the floors of building 8377
SitumSdk.communicationManager().fetchFloorsFromBuilding("8377", new Handler<Collection<Floor>>() {
    @Override
    public void onSuccess(Collection<Floor> floors) {

        //Receives all the buildings and loops over them
        for (Floor floor: floors){

            Log.i(TAG, "BuildingID: " + floor.getBuildingIdentifier());
            Log.i(TAG, "FloorID: " + floor.getIdentifier());

            Log.i(TAG, "Name: " + floor.getName());
            Log.i(TAG, "Floor (Order): " + floor.getFloor());
            Log.i(TAG, "Altitude: " + floor.getAltitude());
            Log.i(TAG, "CustomFields: " + floor.getCustomFields());

            Log.i(TAG, "MapURL: " + floor.getMapUrl());
            Log.i(TAG, "Scale (pixels / meter): " + floor.getScale());
        }
    }

    @Override
    public void onFailure(Error error) {
Log.e(TAG, "Error: " + error );
    }
});


In the previous code snippet, we are receiving a Collection of Floor objects (the floors in Building 8377), and we loop over them to print their properties. Your application logs should be something like this: 



...
BuildingID: 8377
FloorID: 20541
Name: F0
Floor (Order): 0
Altitude: 0.0
CustomFields: {}
MapURL: URL{value='https://dashboard.situm.es/uploads/floor/20541/51b985cf-4c2b-4327-bbab-a53b9c50b916.png', isAbsolute=true}
Scale (pixels / meter): 17.25033570894508

...

BuildingID: 8377
FloorID: 20542
Name: F1
Floor (Order): 1
Altitude: 15.0
CustomFields: {show_in_app=true}
MapURL: URL{value='https://dashboard.situm.es/uploads/floor/20542/aa275ada-5ca2-4d51-be61-71fec14f29be.png', isAbsolute=true}
Scale (pixels / meter): 17.25033570894508
...


Let's examine them in detail.



Building Identifier

First, you will notice that the Floor data object allows you to retrieve the identifier of the building to which the floor belongs. This is handy if you need this information later in your code. For more information about this identifier, please check this Section.


BuildingID: 8377


Floor Identifier

Then, we output the floor identifier.


FloorID: 20542


The floor identifier is automatically generated by Situm Platform when the floor is created. Another way to know the identifier of a floor is to look for in Situm Dashboard's Configuration screen, in the calibrations associated to that floor.



Floor Name, Floor (order), Altitude and Custom Fields


After that, we see the floor name, the floor order, the altitude of that particular floor (in meters) and any user-defined custom-fields.


Name: F1
Floor (Order): 1
Altitude: 0.0
CustomFields: {show_in_app=true}

All this information can be configured when creating a floor:  




Floorplan


The previous image shows how we can upload the floorplan image of a floor. Once we do that, we can retrieve this information with Situm SDK and output its information as shown in this section.  


MapURL: URL{value='https://dashboard.situm.es/uploads/floor/20542/aa275ada-5ca2-4d51-be61-71fec14f29be.png', isAbsolute=true}
Scale (pixels / meter): 17.25033570894508


The floorplan is provided as a URL object. You may download the content from this URL (e.g.  "https://dashboard.situm.es/uploads/floor/20541/51b985cf-4c2b-4327-bbab-a53b9c50b916.png" in this example) in order to download the floorplan image.


The scale of the floorplan is also provided in pixels per meter. This way, you may know how many meters are contained within each pixel. This can be handy, for instance, to compute distances within the floorplan image. Note that all floorplans have the same scale, since all floorplans must have the same size (width & heigth) in pixels.




Downloading all the floorplans of a building


As explained in the previous section, you may retrieve the floorplan of each building by downloading it from the URL provided by method Floor.getMapURL. Additionally, Situm SDK provides a the method CommunicationManager.fetchMapFromFloor, which handles the download for you. The following snippet shows you how to use this method.


//First, we need to fetch all the floors of the building (e.g. building 8377)
SitumSdk.communicationManager().fetchFloorsFromBuilding("8377", new Handler<Collection<Floor>>() {
    @Override
    public void onSuccess(Collection<Floor> floors) {
        for (final Floor floor: floors) {

            //Then, we may download all the floorplans
            SitumSdk.communicationManager().fetchMapFromFloor(floor, new Handler<Bitmap>() {
                @Override
                public void onSuccess(Bitmap bitmap) {
                    Log.i(TAG, "FloorId: " + floor.getIdentifier());
                    Log.i(TAG, "   Size in pixels. Height: " + bitmap.getHeight() + " Width: " + bitmap.getWidth());
                    Log.i(TAG, "   Size in meters. Height: " + bitmap.getHeight()/floor.getScale() + " Width: " + bitmap.getWidth()/floor.getScale());
                }

                @Override
                public void onFailure(Error error) {
                    Log.e(TAG, "Error: " + error);
                }
            });
        }
    }

    @Override
    public void onFailure(Error error) {
        Log.e(TAG, "Error: " + error );
    }
});


Note that the floorplan is provided as an Android Bitmap object. As an example, the previous snippet shows for each building the size of the image in pixels and in meters (using the Floor.getScale method).

FloorId: 20541
   Size in pixels. Height: 758 Width: 1264
   Size in meters. Height: 43.941173829268884 Width: 73.273936306327
FloorId: 20542
   Size in pixels. Height: 758 Width: 1264
   Size in meters. Height: 43.941173829268884 Width: 73.273936306327