Sorted it all by myself 😄I needed to assigned IDs to the graphics as they were being read in, with the stored localstorage index, so;
for (var i = 0; i < localStorage.length; i++) {
var n= "SavedGraphic" + i
saved = dojo.fromJson(localStorage.getItem(localStorage.key(i)));
console.debug(localStorage.getItem(localStorage.key(i)))
var graphic = new esri.Graphic(saved);
graphic.setAttributes({ "ID": n,"LSNo":i });
userGraphics.add(graphic);
}
This gives each graphic that is loaded in for a new session a attribute (LSNo) that equals the index in localstorage.Then I need to delete the store when it is edited - I also need to delete the store if it is a new graphic, added that session. So in the createToolbarAndContextMenu function (I'm using the function from (http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/graphics_contextmenu.html) dojo.connect(editToolbar, "onDeactivate", function (tool, graphic, info) {
if (graphic.attributes.newID) {
localStorage.removeItem(graphic.attributes.newID)
}
else {
localStorage.removeItem(localStorage.key(graphic.attributes.LSNo))
}
var now = new Date();
var n = now.getTime();
GraphicName = "storedGraphic" + n
window.localStorage.setItem(GraphicName, dojo.toJson(graphic.toJson()));
});
Having added graphic.setAttributes({ newID: GraphicName })
To the addToMap function. So if the graphic has been added because it was saved before or if it was added in that session the delete from localstorage is treated differently. For previously saved the index is used. For newly added the id is used.Finally, to the createGraphicsMenu function, the delete section, I add userGraphics.remove(selected); if (selected.attributes.newID) {
localStorage.removeItem(selected.attributes.newID)
}
else {
localStorage.removeItem(localStorage.key(selected.attributes.LSNo))
}
That does the same for deletions.I'm sure there is a tidier way, bu this appears to work.