mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Merge pull request #3565 from alphagov/polygon-overspill
Show indication of how a broadcast will overspill the selected area
This commit is contained in:
@@ -138,5 +138,17 @@ class BroadcastAreaLibraries(SerialisedModelCollection, GetItemByIdMixin):
|
||||
for polygon in self.get_polygons_for_areas_long_lat(*area_ids)
|
||||
]
|
||||
|
||||
def get_simple_polygons_for_areas_long_lat(self, *area_ids):
|
||||
return list(itertools.chain(*(
|
||||
area.simple_polygons
|
||||
for area in self.get_areas(*area_ids)
|
||||
)))
|
||||
|
||||
def get_simple_polygons_for_areas_lat_long(self, *area_ids):
|
||||
return [
|
||||
[[long, lat] for lat, long in polygon]
|
||||
for polygon in self.get_simple_polygons_for_areas_long_lat(*area_ids)
|
||||
]
|
||||
|
||||
|
||||
broadcast_area_libraries = BroadcastAreaLibraries()
|
||||
|
||||
@@ -4,9 +4,9 @@ from copy import deepcopy
|
||||
from pathlib import Path
|
||||
|
||||
import geojson
|
||||
import shapely.geometry as sgeom
|
||||
from notifications_utils.safe_string import make_string_safe_for_id
|
||||
|
||||
import shapely.geometry as sgeom
|
||||
from repo import BroadcastAreasRepository
|
||||
|
||||
package_path = Path(__file__).resolve().parent
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
from random import sample
|
||||
|
||||
import geojson
|
||||
import shapely.geometry as sgeom
|
||||
from notifications_utils.safe_string import make_string_safe_for_id
|
||||
|
||||
import cartopy.crs as ccrs
|
||||
import cartopy.feature as cfeature
|
||||
import matplotlib.pyplot as plt
|
||||
import shapely.geometry as sgeom
|
||||
from repo import BroadcastAreasRepository
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ from datetime import datetime
|
||||
|
||||
from notifications_utils.template import BroadcastPreviewTemplate
|
||||
from orderedset import OrderedSet
|
||||
from shapely.geometry import MultiPolygon, Polygon
|
||||
from shapely.ops import unary_union
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.broadcast_areas import broadcast_area_libraries
|
||||
@@ -76,6 +78,25 @@ class BroadcastMessage(JSONModel):
|
||||
*self._dict['areas']
|
||||
)
|
||||
|
||||
@property
|
||||
def simple_polygons(self):
|
||||
simple_polygons = broadcast_area_libraries.get_simple_polygons_for_areas_lat_long(
|
||||
*self._dict['areas']
|
||||
)
|
||||
unioned_polygons = unary_union([
|
||||
Polygon(i) for i in simple_polygons
|
||||
])
|
||||
if isinstance(unioned_polygons, MultiPolygon):
|
||||
return [
|
||||
[
|
||||
[x, y] for x, y in p.exterior.coords
|
||||
]
|
||||
for p in unioned_polygons
|
||||
]
|
||||
return [[
|
||||
[x, y] for x, y in unioned_polygons.exterior.coords
|
||||
]]
|
||||
|
||||
@property
|
||||
def template(self):
|
||||
response = service_api_client.get_service_template(
|
||||
|
||||
@@ -36,12 +36,23 @@
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(mymap);
|
||||
|
||||
{% for polygon in broadcast_message.simple_polygons %}
|
||||
polygons.push(
|
||||
L.polygon({{polygon}}, {
|
||||
color: '#2B8CC4', // $light-blue
|
||||
opacity: 0.4,
|
||||
fillColor: '#2B8CC4', // $light-blue
|
||||
fillOpacity: 0.3,
|
||||
weight: 1
|
||||
})
|
||||
);
|
||||
{% endfor %}
|
||||
|
||||
{% for polygon in broadcast_message.polygons %}
|
||||
polygons.push(
|
||||
L.polygon({{polygon}}, {
|
||||
color: '#0b0b0c', // $black
|
||||
fillColor: '#2B8CC4', // $light-blue
|
||||
fillOpacity: 0.2,
|
||||
fillOpacity: 0,
|
||||
weight: 2
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user