fix: avoid error if asset has no geometry
This commit is contained in:
parent
f0fa189bcd
commit
969497826d
1 changed files with 14 additions and 12 deletions
|
|
@ -372,21 +372,23 @@ class AssetMasterView(WuttaFarmMasterView):
|
|||
# TODO: eventually sync GIS data, avoid this API call?
|
||||
client = get_farmos_client_for_user(self.request)
|
||||
result = client.asset.get_id(asset.asset_type, asset.farmos_uuid)
|
||||
geometry = result["data"]["attributes"]["intrinsic_geometry"]
|
||||
if geometry := result["data"]["attributes"]["intrinsic_geometry"]:
|
||||
|
||||
context["map_center"] = [geometry["lon"], geometry["lat"]]
|
||||
context["map_center"] = [geometry["lon"], geometry["lat"]]
|
||||
|
||||
context["map_bounds"] = [
|
||||
[geometry["left"], geometry["bottom"]],
|
||||
[geometry["right"], geometry["top"]],
|
||||
]
|
||||
context["map_bounds"] = [
|
||||
[geometry["left"], geometry["bottom"]],
|
||||
[geometry["right"], geometry["top"]],
|
||||
]
|
||||
|
||||
if match := re.match(
|
||||
r"^POLYGON \(\((?P<points>[^\)]+)\)\)$", geometry["value"]
|
||||
):
|
||||
points = match.group("points").split(", ")
|
||||
points = [[float(pt) for pt in pair.split(" ")] for pair in points]
|
||||
context["map_polygon"] = [points]
|
||||
if match := re.match(
|
||||
r"^POLYGON \(\((?P<points>[^\)]+)\)\)$", geometry["value"]
|
||||
):
|
||||
points = match.group("points").split(", ")
|
||||
points = [
|
||||
[float(pt) for pt in pair.split(" ")] for pair in points
|
||||
]
|
||||
context["map_polygon"] = [points]
|
||||
|
||||
return context
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue