Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Ashwini Kumar describes basics of creating custom Openlayers behavior in his article. He doesn't focus on any specific functionality, but provides a skeleton.
Another example could be found in tutorial by cableman, who shows not only general structure (as above), but also example of functionality.