Aha this is a little bit tricky. I will attempt to write the basic version of this but there are so many edge cases that this script doesn't solve. (Moving feature, deleting a bunch of features at once) .. But this is just a start..
Two classes
polygonClass
pointClass
On the pointClass add an attribute rule on insert
var fsPolygon = FeatureSetByName($datastore, "polygonClass", ["globalId"], false);
var intersectedPolygons = Intersects (fsPolygon, $feature);
var polygonFeature = null;
for (polygonFeature in intersectedPolygons) break;
if (polygonFeature == null) return $feature.field;
return {
"result": $feature.field,
"edit": [
{
"className" : "polygonClass",
"updates": [
{
"globalId": polygonFeature.globalId,
"attributes": {"hasPoint": "yes" }
}
]
}
]
}
On the pointClass add another attribute rule on Delete
var fsPolygon = FeatureSetByName($datastore, "polygonClass", ["globalId"], true);
var intersectedPolygons = Intersects (fsPolygon, $feature);
var polygonFeature = null;
for (polygonFeature in intersectedPolygons) break;
if (polygonFeature == null) return $feature.field;
var pointGlobalId = $feature.globalid;
var fsPoint = FeatureSetByName($datastore, "pointClass", ["globalId"], false);
var intersectedPoints = Filter(Intersects (fsPoint, Geometry(polygonFeature)), "globalId <> @pointGlobalId");
if (Count(intersectedPoints) > 0) return $feature.field
return {
"result": $feature.field,
"edit": [
{
"className" : "polygonClass",
"updates": [
{
"globalId": polygonFeature.globalId,
"attributes": {"hasPoint": "no" }
}
]
}
]
}