Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions _layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
>
<div class="wrapper">
{% include header.html %}

<main class="content">
{% include txtbot.html %}
<div class="map-header">
Expand All @@ -23,7 +23,7 @@ <h3>Shelter Locations</h3>
<div id="map">
</div>
<div id='geocoder' class='geocoder'></div>

</div>
<div class="map-legend">
<h3>Legend</h3>
Expand All @@ -50,7 +50,7 @@ <h3>Legend</h3>
</div>
Shelter
</p>
</div>
</div>
</div>
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.3.0/mapbox-gl-geocoder.min.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.3.0/mapbox-gl-geocoder.css' type='text/css' />
Expand All @@ -61,7 +61,7 @@ <h3>Legend</h3>

//TODO: move this to config.
const MAP_LOAD_CENTER = [{{ site.shelter_map_center }}];
const ZOOM = [{{ site.shelter_zoom }}];
const INITIAL_ZOOM = [{{ site.shelter_zoom }}];

var map = new mapboxgl.Map({
// container id specified in the HTML
Expand All @@ -70,8 +70,7 @@ <h3>Legend</h3>
style: 'mapbox://styles/miklb-c4tb/cjnozdzs41qlx2rqvf7mwfztt',
// initial position in [lon, lat] format
center: MAP_LOAD_CENTER,
// initial zoom
zoom: ZOOM
zoom: INITIAL_ZOOM
});


Expand Down Expand Up @@ -128,6 +127,25 @@ <h3>Legend</h3>
"text-size": 12
}
});

// on mouseover, make it obvious that clusters are interactive
map.on('mouseenter', 'clusters', () => {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'clusters', () => {
map.getCanvas().style.cursor = '';
});

map.on('click', 'clusters', e => {
const cluster = map.queryRenderedFeatures(e.point, { layers: ['clusters'] })[0];
const clusterId = cluster.properties.cluster_id;
const center = cluster.geometry.coordinates;
map.getSource('shelters').getClusterExpansionZoom(clusterId, (err, zoom) => {
err || map.easeTo({ center, zoom });
});
});


map.loadImage("{{site.baseurl}}/assets/images/shelter-icon.png", (error, img) => {
map.addImage("shelter", img);
map.addLayer({
Expand All @@ -152,7 +170,7 @@ <h3>Legend</h3>
map.on('mouseenter', 'unclustered-point', function () {
map.getCanvas().style.cursor = 'pointer';
});

// Change it back to a pointer when it leaves.
map.on('mouseleave', 'unclustered-point', function () {
map.getCanvas().style.cursor = '';
Expand Down
34 changes: 27 additions & 7 deletions _layouts/pod.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
>
<div class="wrapper">
{% include header.html %}

<main class="content">
{% include txtbot.html %}
<div class="map-header">
Expand All @@ -22,7 +22,7 @@ <h3>Points of Distribution and Food Locations</h3>
<div id="map-container" class="shelter-map_container">
<div id="map">
</div>

</div>
<div class="map-legend">
<h3>Legend</h3>
Expand All @@ -49,14 +49,14 @@ <h3>Legend</h3>
</div>
Shelter
</p>
</div>
</div>
</div>
<script>
// Load access token from config
mapboxgl.accessToken = '{{site.mapbox_access_token}}';

const MAP_LOAD_CENTER = [{{ site.pod_map_center }}];
const ZOOM = [{{ site.pod_zoom }}];
const INITIAL_ZOOM = [{{ site.pod_zoom }}];

var map = new mapboxgl.Map({
// container id specified in the HTML
Expand All @@ -65,8 +65,7 @@ <h3>Legend</h3>
style: 'mapbox://styles/miklb-c4tb/cjnozdzs41qlx2rqvf7mwfztt',
// initial position in [lon, lat] format
center: MAP_LOAD_CENTER,
// initial zoom
zoom: ZOOM
zoom: INITIAL_ZOOM
});
map.on('load', function() {
// Add a new source from our GeoJSON data and set the
Expand Down Expand Up @@ -110,6 +109,7 @@ <h3>Legend</h3>
]
}
});

map.addLayer({
id: "cluster-count",
type: "symbol",
Expand All @@ -121,6 +121,26 @@ <h3>Legend</h3>
"text-size": 14
}
});

// on mouseover, make it obvious that clusters are interactive
map.on('mouseenter', 'clusters', () => {
map.getCanvas().style.cursor = 'pointer';
});

// Change it back to a pointer when it leaves.
map.on('mouseleave', 'clusters', () => {
map.getCanvas().style.cursor = '';
});

map.on('click', 'clusters', e => {
const cluster = map.queryRenderedFeatures(e.point, { layers: ['clusters'] })[0];
const clusterId = cluster.properties.cluster_id;
const center = cluster.geometry.coordinates;
map.getSource('pods').getClusterExpansionZoom(clusterId, (err, zoom) => {
err || map.easeTo({ center, zoom });
});
});

map.loadImage("{{site.baseurl}}/assets/images/shelter-icon.png", (error, img) => {
map.addImage("shelter", img);
map.addLayer({
Expand All @@ -145,7 +165,7 @@ <h3>Legend</h3>
map.on('mouseenter', 'unclustered-point', function () {
map.getCanvas().style.cursor = 'pointer';
});

// Change it back to a pointer when it leaves.
map.on('mouseleave', 'unclustered-point', function () {
map.getCanvas().style.cursor = '';
Expand Down