
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
maplibre-transition
Advanced tools
A MapLibre GL JS plugin for smooth transitions between map styles.
A utility plugin for Maplibre GL JS that adds transition-related functionality.
This plugin is compatible with MapLibre GL JS version 3.0.0 and above.
npm install maplibre-transition
import maplibregl from 'maplibre-gl';
import MaplibreTransition from 'maplibre-transition';
const map = new maplibregl.Map({
container: "map",
style: "https://demotiles.maplibre.org/style.json",
center: [0, 0],
zoom: 2,
});
// Initialize the plugin
MaplibreTransition.init(map);
// Use the plugin with either method
map.transition(feature, {
duration: 1000,
delay: 500,
ease: "linear",
paint: {
"fill-opacity": [0.1, 1],
},
});
// Or use the shorthand method (deprecated)
map.T(feature, {
duration: 1000,
delay: 500,
ease: "linear",
paint: {
"fill-opacity": [0.1, 1],
},
});
Note: The
map.T
method is deprecated and will be removed in a future version. Please usemap.transition
for new code.
You can transition multiple style properties simultaneously by specifying them in the paint
object:
map.transition(feature, {
duration: 1000,
paint: {
"circle-radius": [8, 12],
"circle-stroke-width": [2, 4],
"circle-opacity": [1, 0.2],
}
});
All specified properties will transition together using the same duration and easing function. This is useful for creating coordinated visual effects.
The plugin supports the following easing functions from d3-ease:
"linear"
- Linear interpolation (no easing)"quad"
- Quadratic easing (smooth acceleration/deceleration)"cubic"
- Cubic easing (stronger acceleration/deceleration)"elastic"
- Elastic easing (bouncy effect)"bounce"
- Bounce easing (multiple bounces)"circle"
- Circular easing (circular acceleration/deceleration)"exp"
- Exponential easing (exponential acceleration/deceleration)"poly"
- Polynomial easing (configurable power)"sin"
- Sinusoidal easing (smooth sine wave)Example with different easing:
map.transition(feature, {
duration: 1000,
ease: "elastic", // Try different easing functions
paint: {
"fill-opacity": [0.1, 1],
},
});
The plugin supports smooth color transitions using D3's color interpolation. It automatically detects color values and uses the appropriate color space for interpolation:
map.transition(feature, {
duration: 1000,
ease: "linear",
paint: {
"fill-color": ["#ff0000", "#00ff00"], // RGB color transition
"fill-outline-color": ["hsl(0,100%,50%)", "hsl(120,100%,50%)"], // HSL color transition
"fill-opacity": [0.1, 1]
}
});
The plugin supports the following color formats:
Each color format uses its appropriate interpolation method:
You can chain transitions using the onComplete
callback. This is useful for creating complex animations that need to happen in sequence:
map.transition(feature, {
duration: 600,
ease: "elastic",
paint: {
"circle-radius": [8, 12],
"circle-color": ["#ff0000", "#00ff00"] // Color transition
},
onComplete: () => {
// This transition will start after the radius transition completes
map.transition(feature, {
duration: 300,
ease: "linear",
paint: {
"circle-stroke-width": [2, 4],
"circle-opacity": [1, 0.2],
"circle-color": ["#00ff00", "#0000ff"] // Another color transition
},
});
}
});
You can combine multiple properties in both the initial and chained transitions. This allows for complex animations where some properties change together, while others follow in sequence.
The plugin supports multiple breakpoints in transition arrays, enabling complex animations and color cycles. This feature allows for smooth transitions between multiple states or creating color cycling effects.
You can specify multiple colors to create smooth color cycles:
map.transition(feature, {
duration: 3000,
ease: 'elastic',
paint: {
"fill-color": [
"#088", // Start with green
"#f00", // Then red
"#00f", // Then blue
"#ff0", // Then yellow
"#f0f", // Then magenta
"#0ff", // Then cyan
"#088" // Back to green
]
}
});
The plugin automatically interpolates between adjacent colors, creating smooth transitions. The interpolation respects the color space (RGB, HSL, or LAB) of the input colors.
Multiple breakpoints also work for numeric properties, creating piecewise linear interpolations:
map.transition(feature, {
duration: 2000,
ease: 'cubic',
paint: {
"circle-radius": [0, 10, 5, 15, 8] // Complex size animation
}
});
This creates a smooth transition that:
Duration: Use longer durations (2000-3000ms) when working with multiple breakpoints to make transitions more visible and smooth.
Easing Selection:
elastic
or bounce
: Best for playful, dynamic effectscubic
or sin
: Ideal for smooth, professional transitionslinear
: Use for precise, mechanical movementsColor Space Considerations:
Performance: While multiple breakpoints are supported, consider the number of breakpoints you use. More breakpoints mean more interpolation calculations.
Example combining multiple properties with breakpoints:
map.transition(feature, {
duration: 3000,
ease: 'elastic',
paint: {
"fill-color": ["#088", "#f00", "#00f", "#088"],
"circle-radius": [5, 15, 10, 20],
"fill-opacity": [1, 0.5, 0.8, 1]
}
});
I've put together some simple working examples in Observable, here.
# Install dependencies
npm install
# Build the plugin
npm run build
# Run the development environment
npm run dev
# Open the development webserver that refreshes on saving.
npm run serve
FAQs
A MapLibre GL JS plugin for smooth transitions between map styles.
The npm package maplibre-transition receives a total of 32 weekly downloads. As such, maplibre-transition popularity was classified as not popular.
We found that maplibre-transition demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.