Convert a Binding to a Script

Hello everyone

I’m having trouble switching from a binding to a script

Let me explain, first I created a map with markers, according to their alarm levels the marker flashes, so far everything works

I wanted to automate the system because we enter all the markers by hand, so now it’s a script that enters the marker data according to my folders in [default], only I can’t manage to implement the binding as a script
I copy binding and put it in my script but it doesn’t work

If anyone has a solution, or an indication

Thanks

My binding on the marker :


Now my script

Method that will run whenever the selected event fires.



Arguments:
self: A reference to the component that is invoking this function.
"""

Centrales = system.tag.browse("[default]")
centrale= []
paths = []
liste = []
lat = []
lon = []

for Centrale in Centrales.getResults():



centrale.append(str(Centrale['name']))



## informationtag = system.tag.getConfiguration(Centrale, True)




for i in range(len(centrale)):
paths.append('[default]' + centrale[i] + '/INFORMATION')

for k in range(len(paths)):
lat.append(str(paths[k]) + '/Latitude')

for l in range(len(paths)):
lon.append(str(paths[l]) + '/Longitude')

valuelat = system.tag.readBlocking(lat)
valuelon = system.tag.readBlocking(lon)

for m in range(len(centrale)):
name = centrale[m]
texte = centrale[m].title()
latitude = valuelat[m].value
longitude = valuelon[m].value
liste.append({
'name': name,
'enabled': True,
'lat': latitude,
'lng': longitude,
'opacity': "1",
'icon': {
'path': "material/location_on",
'color': "#4190F7",
'size': {
'width': 20,
'height': 20
},
'style': {
'classes':
{
"type": "expr",
"config": {
"expression": "runScript(\"Color.Color\", 10, {this.props.layers.ui.marker[1].name}) "
},
"transforms": [
{
"fallback": "",
"inputType": "scalar",
"mappings": [
{
"input": 1,
"output": "blink"
},
{
"input": 2,
"output": "blink"
},
{
"input": 3,
"output": ""
},
{
"input": 4,
"output": ""
},
{
"input": 5,
"output": ""
}
],
"outputType": "style-list",
"type": "map"
}
]
}
}
},
'event': {
'stopPropagation': False
},
'tooltip': {
'content': {
'text': texte,
'view': {
'path': "",
'params': {}
}
},
'direction': "auto",
'permanent': False,
'sticky': False,
'opacity': 1
},
'popup': {
'enabled': False,
'content': {
'text': texte,
'view': {
'path': "",
'params': {}
}
},
'width': {
'max': 300,
'min': 50
},
'height': {
'max': ''
},
'pan': {
'auto': True
},
'closeButton': True,
'autoClose': True,
'closeOnEscapeKey': True,
'closeOnClick': ''
}
})

self.props.layers.ui.marker = liste

Not certain on using an expression in a class like that, but I’m not seeing any indentation in your loops. Example:

for i in range(len(centrale)):
	paths.append('[default]' + centrale[i] + '/INFORMATION')

for k in range(len(paths)):
	lat.append(str(paths[k]) + '/Latitude')

for l in range(len(paths)):
	lon.append(str(paths[l]) + '/Longitude')

I reformatted your code a bit, so that it’s readable. I also ‘fixed’ a few things in the initial part.


centrales = [
	{
		'name': c['name']
		'info_path': "{}/INFORMATION".format(c['fullPath'])
	} for c in system.tag.browse("[default]")
]

latitudes_paths = ["{}/Latitude".format(c['info_path']) for c in centrales]
longitudes_paths = ["{}/Longitude".format(c['info_path']) for c in centrales]
tags = [tag.value for tag in system.tag.readBlocking(latitudes_paths + longitudes_paths)]

latitudes = tags[::2]
longitudes = tags[1::2]


markers = []
for c, lat, lon in zip(centrales, latitudes, longitudes):
	name = c['name']
	text = name.title()
	markers.append(
		{
			'name': name,
			'enabled': True,
			'lat': lat,
			'lng': lon,
			'opacity': "1",
			'icon': {
				'path': "material/location_on",
				'color': "#4190F7",
				'size': {
					'width': 20,
					'height': 20
				},
				'style': {
					'classes': {
						"type": "expr",
						"config": {
							"expression": "runScript(\"Color.Color\", 10, {this.props.layers.ui.marker[1].name}) "
						},
						"transforms": [
							{
								"fallback": "",
								"inputType": "scalar",
								"mappings": [
									{
										"input": 1,
										"output": "blink"
									},
									{
										"input": 2,
										"output": "blink"
									},
									{
										"input": 3,
										"output": ""
									},
									{
										"input": 4,
										"output": ""
									},
									{
										"input": 5,
										"output": ""
									}
								],
								"outputType": "style-list",
								"type": "map"
							}
						]
					}
				}
			},
			'event': {
				'stopPropagation': False
			},
			'tooltip': {
				'content': {
					'text': text,
					'view': {
						'path': "",
						'params': {}
					}
				},
				'direction': "auto",
				'permanent': False,
				'sticky': False,
				'opacity': 1
			},
			'popup': {
				'enabled': False,
				'content': {
					'text': text,
					'view': {
						'path': "",
						'params': {}
					}
				},
				'width': {
					'max': 300,
					'min': 50
				},
				'height': {'max': ''},
				'pan': {'auto': True},
				'closeButton': True,
				'autoClose': True,
				'closeOnEscapeKey': True,
				'closeOnClick': ''
			}
		}
	)

self.props.layers.ui.marker = markers

When is that script called ? Why aren’t you using a binding on the marker property, returning the markers list ?

Try manually creating pins on your map and copy/paste that to a text editor.

Write your script output to a custom property on the control and copy/paste that property to a text editor.

Compare the output and see if anything jumps out.