Problems of removing and redrawing the overlays after applying for leaflet.greatCircle.js

the layers remained

  1. I am running a small web project using Open Street Map using leaflet.
  2. Since OSM doesn’t take earth’s curvature into account. It drew a simple straight polyline.
  3. I found leaflet.greatCircle.js on the internet and applied to my twilight overlays and measurement functions
  4. However the layers are not removed properly causing them to keep stacking up each other
  5. I asked gpt to find out what the problem is, and I am replied to modify removing and redrawing layers. I followed its suggestions however the issue persists.

changed the handling of removing and redrawing functions after chatgpt solutions

remove: function () {
    if (this._polygon) this._polygon.remove();
    if (this._circle) this._circle.remove();
    if (typeof this._circles !== "undefined") {
        if (this._circles.length > 0) {
            for (var i in this._circles) {
                this._circles[i].remove();
            }
        }
        this._circles = undefined;
    }
    this._addedToMap = false;
},