Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving all the map-related code to TypeScript #100

Merged
merged 7 commits into from Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/visualizations/src/components/Map/MapRender.svelte
Expand Up @@ -8,7 +8,7 @@
NavigationControl,
LngLatBoundsLike,
MapSourceDataEvent,
MapMouseEvent,
MapLayerMouseEvent,
LngLatLike,
} from 'maplibre-gl';
import { onMount } from 'svelte';
Expand Down Expand Up @@ -129,7 +129,9 @@
function sourceLoadingCallback(e: MapSourceDataEvent) {
// sourceDataType can be "visibility" or "metadata", in which case it's not about the data itself
if (e.isSourceLoaded && e.sourceId === sourceId && !e.sourceDataType) {
// @ts-ignore // The type forces you to pass a filter parameter in the option, but it's not required by the real code
// The type forces you to pass a filter parameter in the option, but it's not required by the real code
// https://github.com/maplibre/maplibre-gl-js/issues/1393
// @ts-ignore
const renderedFeatures = map.querySourceFeatures(sourceId, { sourceLayer: layerId });

if (renderedFeatures.length) {
Expand All @@ -151,7 +153,7 @@
}
}

function addTooltip(e: MapMouseEvent) {
function addTooltip(e: MapLayerMouseEvent) {
// @ts-ignore // Somehow `features` isn't part of the type, but exists in the object at runtime
wmai marked this conversation as resolved.
Show resolved Hide resolved
const description = renderTooltip(e.features[0]);
if (hoverPopup.isOpen()) {
Expand Down
10 changes: 8 additions & 2 deletions packages/visualizations/src/components/Map/utils.ts
Expand Up @@ -19,7 +19,13 @@ export const colorShapes = (
values: ChoroplethDataValue[],
colorsScale: ColorsScale,
emptyValueColor: Color
) => {
): {
geoJson: FeatureCollection;
bounds: {
min: number;
max: number;
};
} => {
// Key in the values is "x"
// Key in the shapes is "key"
// We add a color property in the JSON
Expand Down Expand Up @@ -140,7 +146,7 @@ function mergeBboxFromFeaturesWithSameKey(features: Feature[]) {
export const computeMaxZoomFromGeoJsonFeatures = (
mapContainer: HTMLElement,
features: Feature[]
) => {
): number => {
let maxZoom = 0; // maxZoom lowest value possible
const filteredBboxes = mergeBboxFromFeaturesWithSameKey(features);
Object.values(filteredBboxes).forEach((value: any) => {
Expand Down