Google Maps – Expressions
Sharperlight has many expression functions that can be used to manipulate or generate coordinates. These expression functions include those which determine coordinates relative to the provided starting position, which can be very useful when displaying data on a map without a permanent or pre-defined set of coordinates. For example, within an orchard, there are many rows of trees. However, the precise coordinates of each row of trees is not measured and stored in the database, but the approximate distance between each row is known. With that information, the user is able to use the expression functions to create coordinates for each row, relative to the very first row of trees. Below are examples on how to use a few of the many expression functions.
Creating parallel lines relative to the starting line
Create a base published query, please refer to the “Creating a Basic Map” section in Google Maps – Layered Maps for more information.
Make sure that the contents of the Type expression is “Polyline”.
Make a prompt only filter and place the starting line coordinates in there.
Now that we have a very basic query, the next step is to create the location output.
Create an expression and use the function
LatLongGetOffsetJson(starting coordinates, longitude offset (m), latitude offset (m)).
Please refer to the example below.
- The starting coordinates would always stay the same and the offset would be multiplied by line number, which would evenly space the lines and not stack them all on top of each other.
- The outer if bracket ensures that the original line coordinates are displayed.
Make sure to set the published default type to Chart under the Options tab and select one of the Layered Mapping types under the Chart tab. Refer to Google Maps – Layered Maps for more details.
The above example shows a simple instance of multiple parallel lines relative to the starting line. This example can also extend to more detailed instances, where the lines are diagonals instead of completely straight, it takes into account both longitude and latitude changes. It can also be applied to other object types, such as polygons and individual points.
Creating a rectangle relative to a line
Continuing on from the published query created in the Parallel Lines section.
Add an expression called Colour and one called Zoom (Refer to Adding Additional Features section in Google Maps – Layered Maps for more info).
Define the contents of the Colour expression to “Red” and the Zoom expression to 0.
Rename the Location field to Line Location and hide the field.
Create another expression and output the Line Location field (i.e. {@StartingCoordinates}). Name this expression Location.
Create a union and within that union, change the contents of the Colour Expression to “Blue”, Zoom to -15 and type to “Polygon”.
Within the union, edit the Location expression. Delete the original contents and use the function:
LatLongLineGetRectangleJsonFromDistanceAndLengthAndWidth(Coordinates, distance (m), length (m), width (m)).
This will create a rectangle on the line. However, users might want a bit of a space in between the line and the rectangle, especially when they plan to display both the line and the rectangle on the same map. To do this, add LatLongGetOffsetJson(coordinates, offset latitude (m), offset longitude (m)).
The preview of the full query should now include both the line records and the rectangle records.
As shown below, a blue rectangle has been created for each red line, and they are offset by a small amount so that they are not touching the line.
Creating multiple points in a circle
Create a base published query, same as the Parallel Lines section, but set the Type to “Marker”. Refer to the example below for the starting outputs.
Create an expression and use the function
LatLongJsonGetPointFromDistanceAndBearing(starting coordinates, bearing, distance (m)).
Enclose that function in ConvertLatLongPointToJson() to covert the output to the right format.
The output of that query will produce a circle of markers on a map.
