World map plugin, how to store area array of unknown length in context store?

Hi I'm using the node-red world map implementation and creating points on the map and store them in a context store so they won't get lost when the map is refreshed and that works great.

I now also try to store areas that are drawn on the map, this data however has an array within the Object. See the object and my incomplete code.

Any help would be truly appreciated.

action: "draw"
name: "Rectangle12"
type: "Rectangle"
layer: "_drawing"
options: object
color: "#4040F0"
fillColor: "#4040F0"
fillOpacity: 0.4
pane: "overlayPane"
drawCount: 12
area: array[4]
0: object
lat: 50.89802164533274
lng: -2.0228576660156254
1: object
lat: 51.12864468394648
lng: -2.0228576660156254
2: object
lat: 51.12864468394648
lng: -1.57928466796875
3: object
lat: 50.89802164533274
lng: -1.57928466796875


//Check if stored markers in GeozoneObjectArray exists, if not create it
var flowGeozoneObjectArray = flow.get('GeozoneObjectArray')||[];

//Check if GeoZone name is already used
if (flowGeozoneObjectArray.some(element => === {
    //flowMarkersObjectArray contains value that is already in use
    //warn user and don't add it to the flowMarkersObjectArray
    node.warn("Geozone name: " + + " is already used. Please use a diffrent name or Delete current GeoZone with that name");
    //send msg
    msg.payload = flowGeozoneObjectArray;
    return msg;

else {
    //append new Geozone object to flowGeozoneObjectArray
    var newGeozone = {
        "name" :, 
        "type" : msg.payload.type,
        "layer": msg.payload.layer, // "layer": "drawing",
        "color": msg.payload.options.color,
        "fillColor": msg.payload.options.fillColor,
        "fillOpacity": msg.payload.options.fillOpacity,
        "pane": msg.payload.options.pane,
        "drawCount": msg.payload.drawCount,

        ***********How to store the array?**********
    // append new value to the array

    //update the flow.MarkersObjectArray
    flow.set('GeozoneObjectArray', flowGeozoneObjectArray);

    //send msg
    msg.payload = flowGeozoneObjectArray;
    return msg;

Does this do what you want?

        "drawCount": msg.payload.drawCount,
        area: msg.payload.area

Note that you don't need the quotes round property names in javascript provided they do not contain special characters. You do need them if you are writing a JSON string though.

Thank you very much, I have definitive over thinking that one. :grinning:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.