Commit c31dd631 authored by Elger Jonker's avatar Elger Jonker

Fix nasty/invisible onMouseOut bug, rename category to layer


Former-commit-id: 53246d30
parent 5ce2ab96
......@@ -18,6 +18,8 @@ const failmap = {
// happens. The options/icon is eaten after the first expansionmarkerClusterGroup or something like that.
// icon is then null. And even if we don't make a marker, the same issue happens.
// is the problem in the retract function not storing anything correctly?
// cause found: mouseout of a point. Probably the code in that thing.
{
// zoomToBoundsOnClick: false,
// spiderfyOnMaxZoom: false,
......@@ -50,7 +52,9 @@ const failmap = {
className: 'marker-cluster marker-cluster-' + css_class,
// title: 'SWAG', // properties.organization_name
iconSize: [40, 40] }); // why a new L.Point? new L.Point(40, 40)
}}
}
}
),
greenIcon: new L.divIcon({className: 'leaflet-marker-green'}),
......@@ -231,7 +235,6 @@ const failmap = {
// the map will always fit to bounds after loading the dataset, but at least it shows the right country if the
// data lodas slow.
initial_location: function(country_code) {
// you might want to set the zoomlevel
// data from: https://worldmap.harvard.edu/data/geonode:country_centroids_az8
let startpositions = {
......@@ -637,9 +640,13 @@ const failmap = {
// console.log(point);
pointlayer = failmap.pointToLayer(point, L.latLng(point.geometry.coordinates.reverse()));
// which of one of these three triggers the bug?
pointlayer.on({
mouseover: failmap.highlightFeature,
mouseout: failmap.resetHighlight,
// mouseout triggered a bug that was not in the stack trace of the map.
// It prevented to show markers on the same location twice. So expanding markers twice
// resulted in a crash. Sine we don't really need this here it has been disabled.
// mouseout: failmap.resetHighlight,
click: failmap.showreport
});
......@@ -746,8 +753,6 @@ const failmap = {
},
showreport: function (e) {
// console.log(e);
let organization_id = e.target.feature.properties['organization_id'];
if (failmap.map.isFullscreen()) {
// var layer = e.target;
......
This diff is collapsed.
......@@ -166,12 +166,12 @@
</div>
</nav>
<nav class="navbar navbar-expand-md navbar-light" id="categorynavbar" v-if="categories.length > 1" v-cloak>
<nav class="navbar navbar-expand-md navbar-light" id="layernavbar" v-if="layers.length > 1" v-cloak>
<div class="container">
<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item" v-for="(x, key) in categories" v-bind:class="[selected_category == x ? 'selected_category' : '']">
<a class="nav-link" v-on:click="set_category(x)">
<li class="nav-item" v-for="(x, key) in layers" v-bind:class="[selected_layer == x ? 'selected_layer' : '']">
<a class="nav-link" v-on:click="set_layer(x)">
{% verbatim %}{{ translate("category_menu_" + x) }}{% endverbatim %}</a>
</li>
</ul>
......@@ -1252,7 +1252,7 @@
<p></p>
</div>
<div class="row">
<div class="col-md-4" v-for="category in categories">
<div class="col-md-4" v-for="layer in layers">
<table style="width:100%" class="table table-striped">
<thead>
<tr>
......
......@@ -28,15 +28,16 @@ urlpatterns = [
path('data/organizationtype_exists/<slug:organization_type_name>', views.organizationtype_exists),
path('data/map/<c:country>/<slug:organization_type>/<d:days_back>/<slug:displayed_issue>/', views.map_data),
path('data/map/<c:country>/<slug:organization_type>/<d:days_back>//', views.map_data),
path('data/map/potential/<c:country>/<slug:organization_type>/', views.map_potential),
path('data/map_default/<d:days_back>/<slug:displayed_issue>/', views.map_default),
path('data/map_default/<d:days_back>//', views.map_default),
path('data/stats/<c:country>/<slug:organization_type>/<w:weeks_back>', views.stats),
path('data/countries/', views.get_countries),
path('data/default_country/', views.get_default_country),
path('data/default_category/', views.get_default_category),
path('data/default_layer/', views.get_default_layer),
path('data/defaults/', views.get_defaults),
path('data/default_category_for_country/<c:country>/', views.get_default_category_for_country),
path('data/categories/<c:country>/', views.get_categories),
path('data/default_layer_for_country/<c:country>/', views.get_default_layer_for_country),
path('data/layers/<c:country>/', views.get_layers),
path('data/vulnstats/<c:country>/<slug:organization_type>/<w:weeks_back>', views.vulnerability_graphs),
path('data/topfail/<c:country>/<slug:organization_type>/<w:weeks_back>', views.top_fail),
path('data/topwin/<c:country>/<slug:organization_type>/<w:weeks_back>', views.top_win),
......
......@@ -94,7 +94,7 @@ def get_defaults(request, ):
if not data:
return JsonResponse({'country': "NL", 'category': "municipality"}, safe=False, encoder=JSEncoder)
return JsonResponse({'country': data['country'], 'category': data['organization_type__name']},
return JsonResponse({'country': data['country'], 'layer': data['organization_type__name']},
safe=False, encoder=JSEncoder)
......@@ -110,7 +110,7 @@ def get_default_country(request, ):
return JsonResponse([country], safe=False, encoder=JSEncoder)
def get_default_category(request, ):
def get_default_layer(request, ):
organization_type = Configuration.objects.all().filter(
is_displayed=True,
......@@ -123,7 +123,7 @@ def get_default_category(request, ):
return JsonResponse([organization_type], safe=False, encoder=JSEncoder)
def get_default_category_for_country(request, country: str = "NL"):
def get_default_layer_for_country(request, country: str = "NL"):
organization_type = Configuration.objects.all().filter(
is_displayed=True,
......@@ -152,7 +152,7 @@ def get_countries(request,):
return JsonResponse(list, safe=False, encoder=JSEncoder)
def get_categories(request, country: str = "NL"):
def get_layers(request, country: str = "NL"):
categories = Configuration.objects.all().filter(
country=get_country(country),
......@@ -1326,6 +1326,155 @@ def map_data(request, country: str = "NL", organization_type: str = "municipalit
return JsonResponse(data, encoder=JSEncoder)
def map_potential(request, country: str = "NL", organization_type: str = "municipality"):
"""
Creates an overview of all organizations and regions on a certain layer. It does not have ratings or anything else.
This has been created to see what the potential is for a certain dataset. It also shows how easy it is to show
something on the map if you don't have to take in account filters and stacking.
Warning: the result of this feature is SLOW. It's built to be barely good enough, not to really preview.
:param request:
:param country:
:param organization_type:
:return:
"""
country = get_country(country)
organization_type = get_organization_type(organization_type)
# in this case to_attr results in a
# 'Coordinate' object has no attribute '_iterable_class' (if you use .latest, so you cannot get the newest... :()
# And this is also interesting: the IN query generated with prefetch on ALL organizations is optimized to be
# one query, and that cannot work on a larger dataset. It's dangerous to use it in production at all, as the dataset
# grows. So well, separate queries it is, again. Which is extremely slow...
"""
Prefetch, returns this ridiculous query:
.prefetch_related(
Prefetch(
"coordinate_set",
queryset=Coordinate.objects.all().filter(is_dead=False).order_by('-created_on'),
to_attr='coordinates'
)
)
('SELECT "coordinate"."id", "coordinate"."organization_id", '
'"coordinate"."geoJsonType", "coordinate"."area", "coordinate"."edit_area", '
'"coordinate"."created_on", "coordinate"."creation_metadata", '
'"coordinate"."is_dead", "coordinate"."is_dead_since", '
'"coordinate"."is_dead_reason" FROM "coordinate" WHERE '
'("coordinate"."is_dead" = %s AND "coordinate"."organization_id" IN (%s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, ... <trimmed 5630 bytes string>
"""
organizations = Organization.objects.all().filter(
country=country,
type=organization_type,
is_dead=False
).select_related('organization_type__name')
data = {
"metadata": {
"type": "FeatureCollection",
"render_date": datetime.now(pytz.utc),
"data_from_time": datetime.now(pytz.utc),
"remark": remark,
},
"crs": {
"type": "name",
"properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}
},
"features": []
}
for organization in organizations:
try:
coordinate = Coordinate.objects.all().filter(is_dead=False, organization=organization).latest('created_on')
except Coordinate.DoesNotExist:
log.debug('Organization %s does not have any coordinate yet....' % organization)
continue
feature = {
"type": "Feature",
"properties":
{
"organization_id": "%s" % organization.pk,
"organization_type": organization.type.name,
"organization_name": organization.name,
"organization_slug": slugify(organization.name),
"overall": 0,
"high": 0,
"medium": 0,
"low": 0,
"data_from": 0,
"color": "green",
"total_urls": 0,
"high_urls": 0,
"medium_urls": 0,
"low_urls": 0,
"origin": "add_bare_url_features"
},
"geometry":
{
"type": coordinate.geojsontype,
# Sometimes the data is a string, sometimes it's a list. The admin
# interface might influence this.
"coordinates": coordinate.area
}
}
data["features"].append(feature)
return JsonResponse(data, encoder=JSEncoder)
def get_map_data(country: str = "NL", organization_type: str = "municipality", days_back: int = 0,
displayed_issue: str = None):
......
......@@ -93,7 +93,6 @@ def compose_discover_task(
# make sure we're dealing with a list for the coming random function
# randomize the endpoints to better spread load over urls.
random.shuffle(urls)
tasks = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment