Map marker in perspective

I've never used the Map component but was interested in your question. Try this:

Map markers 1

Figure 1.

  1. Create two custom properties on the Map component:
  • vehicleStatus and create a binding on this to your GPS data tags that you posted above.
  • sampleMarker. Create the property and paste in a sample marker or the one below.
sampleMarker
{
  "name": "marker0",
  "properties": {},
  "enabled": true,
  "lat": 25.938225,
  "lng": 49.938877,
  "opacity": 1,
  "icon": {
    "path": "material/location_on",
    "color": "#4190F7",
    "rotate": 0,
    "size": {
      "width": 36,
      "height": 36
    },
    "style": {
      "classes": ""
    }
  },
  "event": {
    "stopPropagation": false
  },
  "tooltip": {
    "content": {
      "text": "Vehicle ID",
      "view": {
        "path": "",
        "params": {}
      }
    },
    "direction": "auto",
    "permanent": false,
    "sticky": false,
    "opacity": 1
  },
  "popup": {
    "enabled": false,
    "content": {
      "text": "",
      "view": {
        "path": "",
        "params": {}
      }
    },
    "width": {
      "max": 300,
      "min": 50
    },
    "height": {
      "max": null
    },
    "pan": {
      "auto": true
    },
    "closeButton": true,
    "autoClose": true,
    "closeOnEscapeKey": true,
    "closeOnClick": null
  }
}
  1. Create a property binding on ui.marker as shown below.
    Map markers 2

Figure 2.

  1. Paste in the following code:
ui.marker binding script transform

	def recursiveCopy(original):
		# With credit to https://forum.inductiveautomation.com/u/lrose
		# https://forum.inductiveautomation.com/t/copy-dictionary-and-modify-it-without-affecting-the-original/62297/9
	    from copy import deepcopy
	    from com.inductiveautomation.ignition.common.script.abc import AbstractMutableJythonMap,AbstractMutableJythonSequence
	
	    if isinstance(original,AbstractMutableJythonMap):
	        return {key:recursiveCopy(value) for key,value in original.iteritems()}
	
	    if isinstance(original,AbstractMutableJythonSequence):
	        return [recursiveCopy(item) for item in original]
	
	    return deepcopy(original)
	
	markers = []
	for car in value['tags']:
		protoMarker = recursiveCopy(self.custom.sampleMarker)
		name = car['name']
		for dic in car['tags']:
			if dic['name'] == 'Latitude':
				lat = dic['value']
			if dic['name'] == 'Longitude':
				lng = dic['value']
		protoMarker['lat'] = lat
		protoMarker['lng'] = lng
		protoMarker['tooltip']['content']['text'] = name
		markers.append(protoMarker)
	
	return markers

How it works:

  • The initial binding brings in this.custom.vehicleStatus. That gets passed to the script transform as value.
  • We read in self.custom.sampleMarker as a template for constructing the list of markers. Due to the way Jython works we need to make a deepcopy of it (otherwise all the markers will be set to the last value). See the article referenced in the script to understand more.
  • Loop through your GPS data and find the name, lat and lng of each vehicle. Note that dictionaries are unordered so we need a loop. Since your data will be short a simple loop is adequate and readable.
  • Update the copy of the template and add it to the list of markers.