From cd55cd73aafd43c7f0bdf7e0eb7052ba3a6d62a1 Mon Sep 17 00:00:00 2001 From: Nitesh Date: Fri, 29 Nov 2024 19:00:58 +0530 Subject: [PATCH] fix disputes boundaries issue --- src/@/country/country.utils.ts | 31 ++++++++++++++++++++++++++----- src/@/map/utils.ts | 11 +++++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/@/country/country.utils.ts b/src/@/country/country.utils.ts index ebc861e..551a7a2 100644 --- a/src/@/country/country.utils.ts +++ b/src/@/country/country.utils.ts @@ -4,7 +4,7 @@ import { Expression, LngLatBoundsLike, Map, MapLayerMouseEvent } from "mapbox-gl import { mapCountry } from "~/core/routes"; import { Colors, getCountryLine, getCountryLineWidth, getDefaultCountryColor, getDefaultCountryOpacity } from "../map/map.constant"; -import { checkSourceAvailable, filterCountry, findLayer, getAllSourceLayers, hideLayer, isDefaultStyle, mapDotsClickIdsAndHandler, matchAdminFilter, showLayer, wvFilter } from "../map/utils"; +import { checkSourceAvailable, filterCountry, findLayer, getAllSourceLayers, hideLayer, isDefaultStyle, mapDotsClickIdsAndHandler, matchAdminFilter, notHasDispute, showLayer, wvFilter } from "../map/utils"; import { AdminLayerFillPrefix, AdminLayerLinePrefix, AdminSourcePrefix, CountryAdminIdsName, CountryAdminLevel, mapAdminLayerList, mapLabelLayerList, zoomPaddingMobile } from "./country.constant"; import { setZoomCountryCode } from "./country.model"; import { AddCountries } from "./country.types"; @@ -91,24 +91,45 @@ export const createLineLayerForCountry = ({ map, paintData, level, selectedLevel const { isLessThan } = getCountryLevels(level, selectedLevel); const layerId = getAdminCountryLayerLine(level); const isLevel0 = level === CountryAdminLevel.level0; + const liveOFilter = isLevel0 ? notHasDispute(worldView) : wvFilter(worldView); if (!map.getLayer(layerId) && !isLessThan) { map.addLayer({ id: getAdminCountryLayerLine(level), type: 'line', source: getAdminCountrySource(level), "source-layer": `boundaries_admin_${level}`, - filter: countryCode ? filterCountry(countryCode, isLevel0 ? "!=" : "==", worldView) : wvFilter(worldView), + filter: countryCode ? filterCountry(countryCode, isLevel0 ? "!=" : "==", worldView) : liveOFilter, paint: { 'line-color': getCountryLine(paintData), 'line-width': getCountryLineWidth(), }, - }); - map.setFilter('admin-0-boundary-disputed', countryCode ? filterCountry(countryCode, isLevel0 ? "!=" : "==", worldView) : wvFilter(worldView)); + }, 'admin-0-boundary-disputed'); + if (isLevel0) { + map.setPaintProperty('admin-0-boundary-disputed', 'line-opacity', [ + 'case', + [ + 'all', + ["==", ["get", "dispute"], "true"], + wvFilter(worldView), + ], + 0, 1 + ]); + + map.setPaintProperty('admin-0-boundary-disputed', 'line-opacity', [ + 'case', + [ + 'all', + ["!", ["has", "dispute"]], + wvFilter(worldView), + ], + 1, 0 + ]); + } } else if (isLessThan) { hideLayer(map, layerId); } else { showLayer(map, layerId) - map.setFilter(layerId, countryCode ? filterCountry(countryCode, isLevel0 ? "!=" : "==", worldView) : wvFilter(worldView)); + map.setFilter(layerId, countryCode ? filterCountry(countryCode, isLevel0 ? "!=" : "==", worldView) : liveOFilter); } } diff --git a/src/@/map/utils.ts b/src/@/map/utils.ts index a9dd097..75c243d 100644 --- a/src/@/map/utils.ts +++ b/src/@/map/utils.ts @@ -5,7 +5,7 @@ import { getBaseUrl } from "~/api/project-connect"; import { GeoJSONFeatureCollection, GeoJSONPoint } from '~/core/global-types'; import { ConnectivityDistribution, ConnectivityStatusDistribution, Layers, SCHOOL_STATUS_LAYER } from "../sidebar/sidebar.constant"; -import { animateCircleConfig, Colors, LayerDataProps, mapPaintData } from "./map.constant"; +import { animateCircleConfig, Colors, defaultWorldView, LayerDataProps, mapPaintData } from "./map.constant"; import { setPopupOnClickDot } from "./map.model"; import { ChangeLayerOptions, StylePaintData } from "./map.types"; import { gigaThemeList, ThemeType } from "~/core/theme.model"; @@ -336,7 +336,7 @@ export const filterSchoolStatus = (lengendsSelected: string[]) => { } // Creates a worldview filtes for Mapbox Boundaries tilesets -export const wvFilter = (worldview = "IN") => { +export const wvFilter = (worldview = defaultWorldView) => { return [ "any", ["==", "all", ["get", "worldview"]], @@ -344,6 +344,13 @@ export const wvFilter = (worldview = "IN") => { ]; } +export const notHasDispute = (worldview = defaultWorldView) => { + return [ + "all", + ["!", ["has", "dispute"]], + wvFilter(worldview), + ] +} export const filterCountry = (countryCode: string, operator = "==", worldView?: string) => { // Create a filter expression for the boundary layer using the country and worldview selection if (!countryCode) return []