Skip to content

Instantly share code, notes, and snippets.

@AshtonIzmev
Created July 17, 2025 22:01
Show Gist options
  • Select an option

  • Save AshtonIzmev/140837f2d76be8b9fed4a7675baf329a to your computer and use it in GitHub Desktop.

Select an option

Save AshtonIzmev/140837f2d76be8b9fed4a7675baf329a to your computer and use it in GitHub Desktop.
Morocco border clean
const mapStyle = `https://api.maptiler.com/maps/dataviz/style.json?key=${apiKey}`;
map.current = new maplibregl.Map({
container: mapContainer.current,
style: mapStyle,
center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],
zoom: INITIAL_VIEW_STATE.zoom
});
map.current.on('load', () => {
console.log('[Debug] MAP LOAD EVENT FIRED! The map is working.');
setMapLoaded(true);
// Attempt to remove Western Sahara by filtering map layers
const layers = map.current.getStyle().layers;
layers.forEach(layer => {
// You can use this log to inspect the layer properties in your browser's developer console.
// console.log(layer);
// Specifically target the Country labels layer
if (layer.id === 'Country labels') {
const existingFilter = map.current.getFilter(layer.id);
let finalFilter;
if (existingFilter) {
// Add Western Sahara exclusion to the existing filter
// The existing filter is already an 'all' array, so we add our condition to it
finalFilter = [...existingFilter, ['!=', 'name:en', 'Western Sahara']];
} else {
finalFilter = ['!=', 'name:en', 'Western Sahara'];
}
try {
map.current.setFilter(layer.id, finalFilter);
console.log(`[WorldMap] Applied 'Western Sahara' filter to layer: ${layer.id}`);
} catch (e) {
console.warn(`[WorldMap] Could not apply filter to layer ${layer.id}: ${e.message}`);
}
}
// Remove disputed border between Morocco and Western Sahara
if (layer.id === 'Disputed border') {
// The filter method wasn't working, but we confirmed that setPaintProperty does.
// So, we'll hide the border by setting its opacity to 0.
try {
map.current.setPaintProperty(
'Disputed border',
'line-opacity',
[
'case',
['==', ['get', 'disputed_name'], 'WesternSahara'],
0, // Make it invisible
1 // Keep original opacity for all other borders
]
);
console.log(`[WorldMap] Hid 'WesternSahara' disputed border using opacity.`);
} catch (e) {
console.warn(`[WorldMap] Could not apply opacity style to layer ${layer.id}: ${e.message}`);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment