Skip to content

Commit

Permalink
use e.propagatedFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Nov 4, 2024
1 parent 88400c0 commit a688b62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/Choropleth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,20 @@ const style = (p: GeoJsonProperties) => {
};
};
const getTooltip = (e: LeafletMouseEvent) => tooltipForFeature(getFeatureId(e.layer.properties), getFeatureName(e.layer.properties));
const getTooltip = (e: LeafletMouseEvent) => {
const properties = e.propagatedFrom.properties;
return tooltipForFeature(
getFeatureId(properties),
getFeatureName(properties)
);
};
// when rendering the geojson, leaflet will attach event listener specified here to each feature.
// here we use it to control mapLoading element and changing the URL of the app when they click on
// a feature based on what country it is
const clickEvent = (e: LeafletMouseEvent) => {
mapLoading.value = true;
// TODO: layer is deprecated, what should we use?
const properties = e.layer.properties;
const properties = e.propagatedFrom.properties;
const country = properties[featureProperties.country];
// select feature's country, or unselect if click on it when already selected
const countryToSelect = country === mapSettings.value.country ? "" : country;
Expand Down
7 changes: 7 additions & 0 deletions src/composables/useLeaflet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import { MapFeature } from "../types/resourceTypes";

type TooltipOptionAndContent = { content: string; options?: TooltipOptions };

// Need this to prevent "L.DomEvent.fakeStop is not a function" error with canvas mode VectorGrid
//https://stackoverflow.com/questions/73833142/leaflet-vectorgrid-problem-with-click-event
L.DomEvent.fakeStop = function () {
return true;
}

export const useLeaflet = (
style: (f: GeoJsonProperties) => PathOptions,
getTooltip: (e: LeafletMouseEvent) => TooltipOptionAndContent,
Expand Down Expand Up @@ -138,6 +144,7 @@ export const useLeaflet = (

// TODO: fix up types again - shouldn't really need to use L
vectorGridLayer.value = vectorGrid.slicer(geoJsonDocument, {
rendererFactory: L.canvas.tile, // or L.svg.tile
interactive: true,
vectorTileLayerStyles: {
sliced: style
Expand Down

0 comments on commit a688b62

Please sign in to comment.