0

I built a map page using tile layers, but the layer colors specified in the requirements are the ones in the image below:

required color

The initial color of the implemented layer is now as shown in the figure:

The initial color after implementation

Use the following code to convert the color:

.tileLayer{
  filter: invert(100%);
}

As shown below:

The color after filter conversion

A bit far from the required color.

I tried the following code

filter: hue-rotate(100deg);

Still can't meet the desired color. I wonder if there is a way to achieve the hue shift in requirement. Use filter or other methods will do. I hope you can provide an example of a solution.

var map = L.map('map', {
  layers: [
    L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
      'attribution': 'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors',
      className: 'tileLayer',
    })
  ],
  center: [10, 0],
  zoom: 14
});

var canvasRenderer = L.canvas();

function createWavingCircle(latlng, color, fromRadius, toRadius) {
  var circle = L.circle(latlng, {
    radius: fromRadius,
    color,
    renderer: canvasRenderer
  }).addTo(map);
  var nextCircle;
  var interval = setInterval(() => {
    var radius = circle.getRadius() + 1;
    if (radius <= toRadius) {
      circle.setRadius(radius);
      if (Math.round((radius / toRadius) * 100) >= 30 && !nextCircle) {
        nextCircle = createWavingCircle(latlng, color, fromRadius, toRadius);
      }
    } else {
      if (nextCircle && nextCircle.getRadius() >= toRadius) {
        circle.remove();
        clearInterval(interval);
      }
    }
  }, 1)
  return circle;
}

createWavingCircle(map.getCenter(), 'red', 10, 400);
body {
  margin: 0;
}

html,
body,
#map {
  height: 100%
}

.tileLayer {
  filter: invert(100%);
}
<link type="text/css" rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />

<div id="map"></div>
<script src="https://unpkg.com/leaflet/dist/leaflet-src.js"></script>

example https://plnkr.co/edit/2k8mdrGDLhOQc93L?preview

1 Answers1

-1

Try this filter:

.tileLayer{
  filter: invert(100%) invert(8%) sepia(91%) saturate(4456%) hue-rotate(231deg) brightness(96%) contrast(101%)
}

https://codepen.io/sosuke/pen/Pjoqqp (starting color is always black -> do first invert(100%) )

How to transform black into any given color using only CSS filters

Falke Design
  • 10,635
  • 3
  • 15
  • 30