Leaflet 1.x and 2.x plugin, Leaflet-tilelayer-mask adds mask effect to tilelayer. Older version for Leaflet 0.7.x is available here.
// Create map var map = L.map("map", { zoom : ..., center : ... }); // Add background tile layer L.tileLayer(...).addTo(map); // Create foreground tile layer with mask var fg = L.tileLayer.mask('https://aginfo.cgk.affrc.go.jp/ws/tmc/1.0.0/Kanto_Rapid-900913-L/{z}/{x}/{y}.jpg', { maskUrl : 'star.png', // optional maskSize : 1024 //optional ).addTo(map); // Add event handler to update mask position map.on("mousemove", function(e) { fg.setCenter(e.containerPoint); });
Note #1 : Built in image 'data:image/png;base64,...' (white circle with soft edge over transparent background)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>TileLayerWithMask for leaflet 2.0.0-alpha.1</title> <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0" /> <link href="https://unpkg.com/leaflet@2.0.0-alpha.1/dist/leaflet.css" rel="stylesheet" /> <script type="importmap"> { "imports": { "leaflet": "https://unpkg.com/leaflet@2.0.0-alpha.1/dist/leaflet.js", "mask": "https://frogcat.github.io/leaflet-tilelayer-mask/TileLayerWithMask.js" } } </script> </head> <body> <div id="map" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0"></div> <script type="module"> import { Map, TileLayer } from "leaflet"; import TileLayerWithMask from "mask"; const map = new Map("map").setView([35.6323, 139.768815], 15); new TileLayer("https://cyberjapandata.gsi.go.jp/xyz/pale/{z}/{x}/{y}.png", { maxZoom: 18, attribution: '<a href="https://maps.gsi.go.jp/development/ichiran.html">GSI pale</a>', }).addTo(map); const mask = new TileLayerWithMask( "https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/{z}/{x}/{y}.jpg", { maxZoom: 18, attribution: '<a href="https://maps.gsi.go.jp/development/ichiran.html">GSI seamlessphoto</a>', maskSize: 800, } ).addTo(map); map.on("pointermove", function (e) { mask.setCenter(e.containerPoint); }); </script> </body> </html>