Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Open layers Angular how to adjust opacity with a slider

I have a map thats generated on the components init that runs a method called makeMap() that creates a map that looks like follows

makeMap() {

  var osm = new TileLayer({
    source: new OSM(),
  });

  ...

  this.map = new Map({
    layers: [osm, wktLayer, this.tiles],
    target: 'ol-map',
    view: new View({
      center: proj.fromLonLat(coordinates),
      zoom: 9,
      minZoom: 8.75,
    }),
  });
}

I am trying to add a slider on the front end that can adjust the opacity of the layer "this.tiles". I have the following html for a slider. for testing right now im trying to adjust it as follows.

  setOpacity() {
    this.tiles.setOpacity(0);
    this.map.render()
  }

the issue is when I try to call the method after the map is created it doesnt update the layer only if I call it before its made. Im trying to connect it to a slider as follows

      <input
        id="opacity-input"
        type="range"
        min="0"
        max="1"
        step="0.01"
        value="1"
      />

How can I update the opacity of the layer when the slider changes value? I am new to angular and openlayers so im not sure how to create this functionality.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Works for me like this with react:

<RangeInput onValueChanged={(value) => handleOpcitry(value)} />

const handleOpcitry = useCallback(
    (value: number) => {
      if (!osmLayer) {
        return;
      }

      const opacity = value / 100;

      console.log(opacity);

      osmLayer.setOpacity(opacity);
    },
    [osmLayer]
  );

Range Input:

<input
        type="range"
        min="0"
        max="100"
        value={100}
        onChange={handleValueChange}
></input>
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!