Viglino / ol-ext

Cool extensions for Openlayers (ol) - animated clusters, CSS popup, Font Awesome symbol renderer, charts for statistical map (pie/bar), layer switcher, wikipedia layer, animations, canvas filters.
https://viglino.github.io/ol-ext/
Other
1.23k stars 463 forks source link

Request for Crop Functionality in ol/source/IDW #1092

Open fabric-io-rodrigues opened 1 month ago

fabric-io-rodrigues commented 1 month ago

Hello @Viglino and the ol-ext Team,

First, I want to express my appreciation for the outstanding work you’ve done with the ol-ext library. Your contributions to OpenLayers are invaluable, and the library’s suite of features greatly enhances the capabilities of OpenLayers with thoughtful and well-implemented extensions.

I am currently using the ol/source/IDW functionality in my project and would like to request a new feature: a built-in crop function. At present, the heatmap generated by ol/source/IDW covers the entire map, but my use case requires limiting the heatmap rendering to a specific area.

Requested Feature:

Current Workaround:

To achieve similar functionality, I have implemented the following steps:

  1. Create Buffers Around Points: Used Turf.js to generate buffers around the data points.
  2. Union Buffers: Combined these buffers to create a unified polygonal area.
  3. Apply Filter: Applied this polygon as a clipping mask to the heatmap layer using OpenLayers.

Visual Example:

To better illustrate the need for this feature, I have attached an image showing the heatmap with the current cropping method that I implemented. The image demonstrates how the heatmap is confined to a specific area, which is crucial for my project.

image

Adding a native crop functionality to ol/source/IDW would greatly streamline this process and enhance the flexibility of heatmap visualizations. It would be a fantastic addition to an already brilliant set of tools that ol-ext provides.

Thank you for considering this request and for your continued dedication to keeping the ol-ext project active and up-to-date.

Viglino commented 1 month ago

I've added a new maxD options (in projection unit) to limit the computation at a given distance. image

fabric-io-rodrigues commented 1 month ago

Hello @Viglino ,

Thank you very much for the quick response, analysis, and implementation! The new maxD option to limit the computation to a specific distance is working very well.

I took the liberty of creating a setMaxD function to make adjusting the parameter easier, as shown below:

ol.source.IDW.prototype.setMaxD = function(maxD) { 
    this.set("maxD", parseFloat(maxD) || 0); 
    this.changed();
};

ezgif-6-712249bade 1

Thanks again for your dedication. Your work is helping many people!

Viglino commented 1 month ago

You may also have to change the scale factor to prevent aliasing on the edge (but may lag on large datasets). Screenity video - Aug 5, 2024