Running out of memory while adding polygons to array

Viewed 36

I am building a Google Maps application, which needs to load and filter hundred of thousands of polygons. I have an array, where I push every polygon with custom properties in order later to be able to filter them. This all works great, but when the polygons are too many the browser runs out of memory. This is due to the array of polygons, which is taking too much memory. If I don't push the objects in the array, then I can't filter them in later stage. Is there some workaround? Here is the function that I use to draw the polygons for example:

     const polygon = new window.google.maps.Polygon({
        paths: polyArr,
        strokeColor: "blue",
        strokeWeight: 1,
        strokeOpacity: 0.2,
        fillColor: "rgba(0, 0, 255)",
        fillOpacity: 0.35,
        filterId: obj.filter,
        id: obj.id,
        map: this.map,
      });
     this.figuresArr.push(polygon);

If I don't push the object into the array, then the map loads everything. I am working in Vue, if this makes any difference.

0 Answers
Related