After a bit of refactoring and to be more my style, this is what I have come up with for h3.polygonToCells
and h3.cellToChildren
Flow
[{"id":"79fb6c16.c8d374","type":"change","z":"e02f29e1.67d3d8","name":"polygon/resolution","rules":[{"t":"set","p":"payload.polygon","pt":"msg","to":"[\t [payload.south, payload.west],\t [payload.north, payload.west],\t [payload.north, payload.east],\t [payload.south, payload.east],\t [payload.south, payload.west]\t]","tot":"jsonata"},{"t":"set","p":"payload.resolution","pt":"msg","to":"8","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1030,"y":380,"wires":[["3c794efe.320c22","1289562b.53082a"]]},{"id":"3c794efe.320c22","type":"function","z":"e02f29e1.67d3d8","name":"h3.polygonToCells","func":"let h3 = global.get(\"h3\");\nvar resolution = msg.payload.resolution;\nvar polygon = msg.payload.polygon\nvar strings = h3.polygonToCells(polygon, resolution);\nmsg.payload = []; //isa [{string:str, boundry:[[lat,lon], ...]}, ...]\n\nstrings.forEach((string) => {\n var boundry = h3.cellToBoundary(string); //isa [[], [], ...]\n boundry.push(boundry[0]); // OGC closed linear ring\n var cell = {\n \"string\": string, \n \"resolution\": resolution,\n \"boundry\": boundry,\n };\n msg.payload.push(cell);\n});\n\nreturn msg;","outputs":1,"noerr":0,"x":1250,"y":380,"wires":[["d9370a1d.c94488"]]},{"id":"d9370a1d.c94488","type":"split","z":"e02f29e1.67d3d8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1430,"y":380,"wires":[["5c806c3d.f9f4c4","2e52a07d.6a9c5"]]},{"id":"2e52a07d.6a9c5","type":"function","z":"e02f29e1.67d3d8","name":"h3.cellToChildren","func":"let h3 = global.get(\"h3\");\nvar cell = msg.payload;\nvar resolution = cell.resolution + 1; //TODO: allow override\n//node.warn(cell.string);\n//node.warn(resolution);\n\nvar strings = h3.cellToChildren(cell.string, resolution);\n//node.warn(strings);\n\nmsg.payload = []; //isa [{string:str, boundry:[[lat,lon], ...]}, ...]\n\nstrings.forEach((string) => {\n var boundry = h3.cellToBoundary(string); //isa [[], [], ...]\n boundry.push(boundry[0]); // OGC closed linear ring\n var cell = {\n \"string\": string, \n \"resolution\": resolution,\n \"boundry\": boundry,\n };\n msg.payload.push(cell);\n});\n\nreturn msg;","outputs":1,"noerr":0,"x":1610,"y":340,"wires":[["f904cb0d.2228a8"]]},{"id":"f904cb0d.2228a8","type":"split","z":"e02f29e1.67d3d8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1790,"y":340,"wires":[["90e56f86.a1f5"]]},{"id":"90e56f86.a1f5","type":"change","z":"e02f29e1.67d3d8","name":"color","rules":[{"t":"set","p":"cell","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.weight","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"payload.color","pt":"msg","to":"#CCCCCC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1930,"y":340,"wires":[["580b1557.f6291c"]]},{"id":"5c806c3d.f9f4c4","type":"change","z":"e02f29e1.67d3d8","name":"color","rules":[{"t":"set","p":"cell","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.weight","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"payload.color","pt":"msg","to":"#BBBBBB","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1930,"y":380,"wires":[["580b1557.f6291c"]]},{"id":"580b1557.f6291c","type":"change","z":"e02f29e1.67d3d8","name":"format","rules":[{"t":"set","p":"payload.layer","pt":"msg","to":"hex","tot":"str"},{"t":"set","p":"payload.name","pt":"msg","to":"cell.string","tot":"msg"},{"t":"set","p":"payload.line","pt":"msg","to":"cell.boundry","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2070,"y":360,"wires":[["ac5a14e6.2859f8"]]},{"id":"ac5a14e6.2859f8","type":"change","z":"e02f29e1.67d3d8","name":"","rules":[],"action":"","property":"","from":"","to":"","reg":false,"x":2195,"y":440,"wires":[["4c9dc44a.908fdc"]],"l":false},{"id":"4c9dc44a.908fdc","type":"ui_worldmap","z":"e02f29e1.67d3d8","group":"b216f4f.7d69c08","order":1,"width":"20","height":"10","name":"","lat":"38.2","lon":"-97.2","zoom":"4.5","layer":"","cluster":"","maxage":"","usermenu":"hide","layers":"show","panit":"false","panlock":"false","zoomlock":"false","hiderightclick":"true","coords":"deg","showgrid":"false","allowFileDrop":"false","path":"/worldmap","overlist":"","maplist":"OSMG,OSMC,EsriC,EsriS,EsriT,EsriDG","mapname":"","mapurl":"","mapopt":"","mapwms":false,"x":2340,"y":260,"wires":[]},{"id":"9b2015b6.65a058","type":"worldmap in","z":"e02f29e1.67d3d8","name":"worldmap boundary","path":"/worldmap","events":"bounds","x":110,"y":260,"wires":[["9470a517.f4e368","f53a4b1b.56d988"]]},{"id":"f53a4b1b.56d988","type":"trigger","z":"e02f29e1.67d3d8","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"500","extend":true,"units":"ms","reset":"","bytopic":"all","name":"","x":420,"y":260,"wires":[["3a7daa20.4a5456"]]},{"id":"3a7daa20.4a5456","type":"change","z":"e02f29e1.67d3d8","name":"set center","rules":[{"t":"set","p":"payload.center","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.center.lat","pt":"msg","to":"$average([payload.north, payload.south])\t","tot":"jsonata"},{"t":"set","p":"payload.center.lon","pt":"msg","to":"$average([payload.east, payload.west])\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":260,"wires":[["495f29b2.e5e508","9ed54ec.ce141b"]]},{"id":"495f29b2.e5e508","type":"switch","z":"e02f29e1.67d3d8","name":"zoom >= 15.5","property":"payload.zoom","propertyType":"msg","rules":[{"t":"gte","v":"15.5","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":780,"y":260,"wires":[["d306486c.fc1f58","28ef495f.224f26","800fae11.27ece","79fb6c16.c8d374"],["65916287.60cedc","fe6930f5.e980f"]]},{"id":"b216f4f.7d69c08","type":"ui_group","z":"","name":"World Map","tab":"a4e26d94.4446","order":1,"disp":true,"width":"20","collapse":false},{"id":"a4e26d94.4446","type":"ui_tab","z":"","name":"World Map","icon":"dashboard","order":6,"disabled":false,"hidden":false}]
Event Summary:
- on map change of bounding box
- format bbox as polygon (OGC closed ring)
- call polygonToCells at level 8 which returns the cell string and boundary
- split return to process each cell
- get all children for each cell
- format objects for worldmap