Skip to content

Commit

Permalink
Fix Leaflet marker image path discovery
Browse files Browse the repository at this point in the history
Including `url("/static/leaflet/images/marker-icon.png")` in our Sass
doesn’t work because django-compressor adds a hash as a query parameter,
which breaks Leaflet’s `/^(.*)marker-icon\.png$/` regexp.

So this commit removes the ruleset from our Sass pipeline, and just
embeds it directly into the HTML page, where django-compressor can’t
mess it up.
  • Loading branch information
zarino committed Jul 17, 2024
1 parent 04656f9 commit befa610
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 0 additions & 4 deletions hub/static/css/_leaflet.scss

This file was deleted.

1 change: 0 additions & 1 deletion hub/static/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

@import "../../../vendor/leaflet/leaflet-1.8.0";

@import "leaflet";
@import "leaflet-geosearch";

@import "site-header";
Expand Down
11 changes: 11 additions & 0 deletions hub/templates/hub/explore.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
{% block script %}
<script type="module" src="{% static 'js/home-out-esm.js' %}"></script>
<script type="module" src="{% static 'js/explore-out-esm.js' %}"></script>
<style type="text/css">
{% comment %}
L.Icon.Default uses this style to work out the path to our images.
We define it here, rather than in our Sass pipeline, to bypass
django-compressor’s URL hashing, which is incompatible with the
regular expression used in Leaflet.Icon.Default._stripUrl.
{% endcomment %}
.leaflet-default-icon-path {
background-image: url("{% static 'leaflet/images/marker-icon.png' %}") !important;
}
</style>
{% endblock %}

{% block content %}
Expand Down

0 comments on commit befa610

Please sign in to comment.