Skip to content

Commit 67db2ac

Browse files
committed
change tile provider
map fixes
1 parent a1b0165 commit 67db2ac

File tree

6 files changed

+27
-45
lines changed

6 files changed

+27
-45
lines changed

findthatpostcode/__init__.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import re
44

55
import sentry_sdk
6-
from flask import Flask, make_response, render_template, request
6+
from flask import Flask, make_response, render_template
77
from flask_cors import CORS
88
from sentry_sdk.integrations.flask import FlaskIntegration
9-
from ua_parser import user_agent_parser
109

1110
from findthatpostcode import blueprints, commands, db
1211
from findthatpostcode.controllers.areatypes import area_types_count
@@ -107,34 +106,4 @@ def about():
107106

108107
blueprints.init_app(app)
109108

110-
@app.after_request
111-
def request_log(response):
112-
ua = user_agent_parser.Parse(request.user_agent.string)
113-
if request.endpoint == "static":
114-
return response
115-
db.get_log_db()["logs"].insert(
116-
{
117-
"app": "findthatpostcode",
118-
"timestamp": datetime.datetime.now().isoformat(),
119-
"url": request.url,
120-
"path": request.path,
121-
"method": request.method,
122-
"params": request.args.to_dict(),
123-
"origin": request.origin,
124-
"referrer": request.referrer,
125-
# "remote_addr": request.remote_addr, # we don't collect IP address
126-
"endpoint": request.endpoint,
127-
"view_args": request.view_args,
128-
"user_agent_string": ua.get("string") if ua else None,
129-
"user_agent": {k: v for k, v in ua.items() if k != "string"}
130-
if ua
131-
else None,
132-
"status_code": response.status_code,
133-
"response_size": response.content_length,
134-
"content_type": response.mimetype,
135-
},
136-
)
137-
db.close_log_db()
138-
return response
139-
140109
return app

findthatpostcode/blueprints/areas.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ def get_area(areacode, filetype="json"):
106106
return jsonify(r)
107107

108108
return return_result(
109-
result, filetype, "area.html.j2", child=request.values.get("child")
109+
result,
110+
filetype,
111+
"area.html.j2",
112+
child=request.values.get("child"),
113+
example_postcode_json=[
114+
p.attributes.get("location")
115+
for p in result.relationships["example_postcodes"]
116+
if p.attributes.get("location")
117+
],
110118
)
111119

112120

findthatpostcode/limiter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def exempt_if_header():
1616

1717
limiter = Limiter(
1818
get_remote_address,
19-
default_limits=["2 per minute"],
19+
default_limits=["2 per second"],
2020
application_limits=["20000 per day"],
2121
storage_uri="memory://",
2222
headers_enabled=True,

findthatpostcode/static/js/map.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ if (window.postcodes && postcodes.length > 0) {
1010
var mymap = L.map('postcode-map', {
1111
zoomSnap: 0.1
1212
}).setView(center, 9);
13-
// var layer = new L.tileLayer('https://tiles.stadiamaps.com/tiles/stamen_terrain/{z}/{x}/{y}{r}.png', {
14-
// attribution: '&copy; <a href="https://stadiamaps.com/" target="_blank">Stadia Maps</a> <a href="https://www.stamen.com/" target="_blank">&copy; Stamen Design</a> &copy; <a href="https://openmaptiles.org/" target="_blank">OpenMapTiles</a> &copy; <a href="https://www.openstreetmap.org/about" target="_blank">OpenStreetMap</a> contributors',
15-
// }).addTo(mymap);
1613
var layer = L.maplibreGL({
17-
style: 'https://tiles.stadiamaps.com/styles/alidade_smooth.json',
18-
attribution: '&copy; <a href="https://stadiamaps.com/" target="_blank">Stadia Maps</a> <a href="https://www.stamen.com/" target="_blank">&copy; Stamen Design</a> &copy; <a href="https://openmaptiles.org/" target="_blank">OpenMapTiles</a> &copy; <a href="https://www.openstreetmap.org/about" target="_blank">OpenStreetMap</a> contributors',
14+
style: 'https://tiles.openfreemap.org/styles/positron',
15+
attribution: `
16+
<a href="https://openfreemap.org" target="_blank">OpenFreeMap</a>
17+
<a href="https://www.openmaptiles.org/" target="_blank">&copy; OpenMapTiles</a>
18+
Data from <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>`,
1919
}).addTo(mymap);
2020
L.osGraticule({ showLabels: false, lineColor: '#ddd' }).addTo(mymap);
2121

@@ -30,7 +30,7 @@ if (document.getElementById('location-map')) {
3030
scrollWheelZoom: false,
3131
});
3232
var layer = L.maplibreGL({
33-
style: 'https://tiles.stadiamaps.com/styles/alidade_smooth.json',
33+
style: 'https://tiles.openfreemap.org/styles/positron',
3434
}).addTo(location_map);
3535
location_map.fitBounds(UK_BOUNDS);
3636
location_map.setMinZoom(location_map.getZoom());

findthatpostcode/templates/area.html.j2

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,13 @@
174174
{% endblock %}
175175

176176
{% block bodyscripts %}
177-
{% if example_postcodes or result.has_boundary %}
177+
{% if example_postcode_json or result.has_boundary %}
178178
<script type="text/javascript">
179-
var postcodes = [
180-
{% for p in example_postcodes %}{% if p.attributes.location %} { { p.attributes.location | tojson } },
181-
{% endif %} {% endfor %}];
179+
{% if example_postcode_json %}
180+
var postcodes = {{ example_postcode_json | tojson }};
181+
{% else %}
182+
var postcodes = null;
183+
{% endif %}
182184
{% if result.has_boundary %}
183185
var geojson = {{ url_for('areas.get_area_boundary', areacodes = result.id) | tojson }};
184186
{% else %}

findthatpostcode/templates/postcode.html.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@
5353

5454
{% if result.attributes.location %}
5555
<div class="fl w-two-thirds-l w-100">
56-
<figure class="ma0 pa0">
56+
<figure class="ma0 w-70 fl">
5757
<div id="postcode-map" style="height:500px;"></div>
5858
</figure>
59+
<figure class="ma0 w-30 fl">
60+
<div id="location-map" style="height:500px;"></div>
61+
</figure>
5962
<p class="f5 b mt0 mb1 w-100">
6063
{% if result.get_area('laua') %}
6164
Approximate location within

0 commit comments

Comments
 (0)