Skip to content

Commit 2a0d2d9

Browse files
authored
Merge pull request #92 from Xpirix/fix_homepage_map
Enhance map functionality with improved bounds and tile layer handling
2 parents dae50c4 + d381c0f commit 2a0d2d9

File tree

2 files changed

+72
-15
lines changed

2 files changed

+72
-15
lines changed

django_project/certification/templates/certifying_organisation/detail.html

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,35 @@ <h1>Certifying Organisation (all)</h1>
3232

3333
// Add map
3434
$('#map').css({'height': 400, 'width': "100%"});
35-
map = Leaflet.map('map').setView([lat, long], 4);
36-
Leaflet.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
37-
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">'+
38-
'OpenStreetMap</a>, Tiles courtesy of '+
39-
'<a href="http://hot.openstreetmap.org/" target="_blank">'+
40-
'Humanitarian OpenStreetMap Team</a>'
35+
36+
37+
const worldBounds = Leaflet.latLngBounds(
38+
Leaflet.latLng(-90, -180), // south-west
39+
Leaflet.latLng(90, 180) // north-east
40+
);
41+
42+
map = Leaflet.map('map', {
43+
maxBounds: worldBounds,
44+
maxBoundsViscosity: 1.0, // 1.0 = hard lock, won't pan outside at all
45+
minZoom: 2,
46+
}).setView([lat, long], 4);
47+
const RefererTileLayer = Leaflet.TileLayer.extend({
48+
createTile(coords, done) {
49+
const tile = document.createElement('img');
50+
tile.referrerPolicy = 'origin';
51+
tile.onload = () => done(null, tile);
52+
tile.onerror = (e) => done(e, tile);
53+
tile.src = this.getTileUrl(coords);
54+
return tile;
55+
}
56+
});
57+
58+
new RefererTileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
59+
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">'+
60+
'OpenStreetMap</a>, Tiles courtesy of '+
61+
'<a href="http://hot.openstreetmap.org/" target="_blank">'+
62+
'Humanitarian OpenStreetMap Team</a>',
63+
opacity: 0.75,
4164
}).addTo(map);
4265

4366
addMarkers();

django_project/certification/templates/certifying_organisation/includes/world-map.html

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% block js_head %}
2+
23
<script>
34
var map;
45
var geojson;
@@ -8,9 +9,37 @@
89

910
$(document).ready(function () {
1011
$('#map').css('height', 700);
11-
map = Leaflet.map('map').setView([20, 0], 2);
12-
Leaflet.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
13-
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
12+
$('#map').css('background', '#002033');
13+
14+
const worldBounds = Leaflet.latLngBounds(
15+
Leaflet.latLng(-90, -180), // south-west
16+
Leaflet.latLng(90, 180) // north-east
17+
);
18+
19+
map = Leaflet.map('map', {
20+
maxBounds: worldBounds,
21+
maxBoundsViscosity: 1.0, // 1.0 = hard lock, won't pan outside at all
22+
minZoom: 2,
23+
}).setView([20, 0], 2);
24+
25+
const RefererTileLayer = Leaflet.TileLayer.extend({
26+
createTile(coords, done) {
27+
const tile = document.createElement('img');
28+
tile.referrerPolicy = 'origin';
29+
tile.onload = () => done(null, tile);
30+
tile.onerror = (e) => done(e, tile);
31+
tile.src = this.getTileUrl(coords);
32+
return tile;
33+
}
34+
});
35+
36+
new RefererTileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
37+
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">'+
38+
'OpenStreetMap</a>, Tiles courtesy of '+
39+
'<a href="http://hot.openstreetmap.org/" target="_blank">'+
40+
'Humanitarian OpenStreetMap Team</a>',
41+
opacity: 0.75,
42+
className: 'basemap-tiles',
1443
}).addTo(map);
1544

1645
add_layers_to_map();
@@ -125,9 +154,9 @@
125154
return {
126155
fillColor: get_color(feature.properties.organisation_count),
127156
weight: 1,
128-
opacity: 1,
129-
color: '#D3D3D3',
130-
fillOpacity: 0.7
157+
opacity: .5,
158+
color: '#002033',
159+
fillOpacity: 0.75
131160
};
132161
}
133162

@@ -144,10 +173,10 @@
144173
var feature = e.target;
145174

146175
feature.setStyle({
147-
weight: 1.5,
176+
weight: 3,
148177
color: '#ee7913',
149178
dashArray: '',
150-
fillOpacity: 0.7
179+
fillOpacity: 0.9
151180
});
152181

153182
if (!Leaflet.Browser.ie && !Leaflet.Browser.opera) {
@@ -180,4 +209,9 @@
180209
</div>
181210
</div>
182211
</div>
183-
{% endblock %}
212+
<style>
213+
.basemap-tiles {
214+
filter: grayscale(100%) brightness(80%);
215+
}
216+
</style>
217+
{% endblock %}

0 commit comments

Comments
 (0)