XY Maps with Version Control

Creating XY Maps with Version Control

XY Maps with Version Control

XY maps are powerful tool for AppSheet developers. However, one of the challenges with XY maps is that the maps have no knowledge of scale since they are an image placed on a 0 to 100 xy coordinate scale. If a XY map needs to be updated, developers need to ensure the updated map has the exact same cropping and the same scale as the previous version. If not, existing pins will appear to shift on the map when the new map is loaded. This becomes a tedious time consuming process if the app has tens to hundreds of different maps to manage.

To solve for this, I created a demo app that shows how you can let user admins of an app manage their own maps and prevent pins from shifting on them.

If you develop an app that requires the user to “define the extents of the map” by selecting a top left and bottom right extent, the app will always ensure the pins do not shift or move to a new location even if a map of different scale or cropping is loaded.

How it works

Whenever a new map is loaded into app, the map is saved in a new table. Each map gets a Top Left and Bottom Right extent pin, the original pin placement is always shown as a reference below.

Once the top left and bottom right extent is established, then the app will be able to maintain pin locations even when new versions are added.

Here is an example below where 3 pins were placed on version 1 of the map. Then version 2 of the map was added with a large padding on the right side of the image (this extreme was done for the demo). Then after version 2 was loaded and the extents were defined, the pins automatically adjusted based on the extents defined in v2 of the map.

image

Notice how all previous placed pins show up in their expected location even though the new image has different scale and cropping.

How It was Made

Whenever a pin is placed on a map, the input location is stored along with the version of the map it was placed on. Then the v1 map position is calculated using the top left and bottom right extents and stored too. Below is the formula used to calculate the V1 coordinates, where

[Location] = the xy column
[Map Version] = map version number
[Map Extent TL V1] = version 1xy coordinates of the top left corner of the map extent
[Map Extent BR V1] = version 1 xy coordinates of the bottom right corner of the map extent
[Map Extent TL] = current version xy coordinates of the top left corner of the map extent
[Map Extent BR] = current version xy coordinates of the bottom right corner of the map extent

if([Map Version]=1, [Location],
xy(
lat([Map].[Map Extent TL V1])
+
(
((lat([Location])-lat([Map].[Map Extent TL]))
/
(lat([Map].[Map Extent BR])-lat([Map].[Map Extent TL])))
*
(lat([Map].[Map Extent BR V1])-lat([Map].[Map Extent TL V1]))
)
,
long([Map].[Map Extent TL V1]) +
(
((long([Location])-long([Map].[Map Extent TL]))
/
(long([Map].[Map Extent BR])-long([Map].[Map Extent TL])))
*
(long([Map].[Map Extent BR V1])-long([Map].[Map Extent TL V1]))
)
))

Calculating the v1 map position acts to normalize all pin locations to a common reference regardless of map version. This also would allow maps to be reverted back to a previous version too without affecting existing pins.

A virtual column then calculates and displays the current location pin relative the to the current map version. Here is the formula:

xy(
lat([Map].[Map Extent TL])
+

(
((lat([Coordinates_V1_Map])-lat([Map].[Map Extent TL V1]))
/
(lat([Map].[Map Extent BR V1])-lat([Map].[Map Extent TL V1])))
*
(lat([Map].[Map Extent BR])-lat([Map].[Map Extent TL]))
)
,

long([Map].[Map Extent TL]) +
(
((long([Coordinates_V1_Map])-long([Map].[Map Extent TL V1]))
/
(long([Map].[Map Extent BR V1])-long([Map].[Map Extent TL V1])))
*
(long([Map].[Map Extent BR])-long([Map].[Map Extent TL]))
)

)

Try it out

Give this feature a try by using the sample app here: XY Maps with Version Control

  1. Select a building/area on the map or create a new area.

  1. Click “Add Map” to create a new map.

  1. Once a map is loaded you can view the map properties by clicking on the map, or add a task pin to the map to test out how the app retains the pin locations across versions by clicking “Create Task”.

  1. While viewing a map’s details you can add a new version by clicking “Revise Map”. The app will then walk you through the same process for defining the top left and bottom right extents.

.

More!

XY maps are a powerful feature of AppSheet but combining features like this along with Smart Areas on a map can open up so much more functionality in your apps.

As always let me know if you have any questions.

Rich

5 Likes

Nice, great work

1 Like

Everyone should study this App. You thought of everything. Even what to do, when user is canceling the Action Cascade. Wow I’m very impressed.

2 Likes

@Martin_Pace road map for document versioning.

Very useful stuff… Thanks @Rich:ok_hand: