Bookmarks/BookmarksViewModel on Create, Update, Delete events

927
3
Jump to solution
02-13-2020 01:47 PM
RichardMoussopo
Occasional Contributor III

I am trying to store bookmarks on the client local-storage but I can't seem to intercept the following events on the bookmark widget or on the BookmarkViewModel class [on Create, Update, Delete]. I would like to use the bookmark widget for its UI. Any idea?

Bookmarks | ArcGIS API for JavaScript 4.14 

BookmarksViewModel | ArcGIS API for JavaScript 4.14  

Thanks

0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

You can listen for the bookmarks collections change event. You'll want to wait until the webmap is ready so the bookmarks are populated. Here's an example: https://codepen.io/kellyhutchins/pen/ExjPGQe 

View solution in original post

3 Replies
KellyHutchins
Esri Frequent Contributor

You can listen for the bookmarks collections change event. You'll want to wait until the webmap is ready so the bookmarks are populated. Here's an example: https://codepen.io/kellyhutchins/pen/ExjPGQe 

RichardMoussopo
Occasional Contributor III

Thank you Kelly,

The "Add", and "Remove" event works great! I was able to capture those two events. then what about when the bookmark's name gets updated? I was looking for an event like "updated". I am wondering if I can watch for the property name change using watchUtils | ArcGIS API for JavaScript 4.14 ?

Thank you

0 Kudos
KellyHutchins
Esri Frequent Contributor

Yep looks like you'd want to watch the name property. 

        bookmarkWidget.bookmarks.forEach(function (bookmark) {
          bookmark.watch("name", function (name) {
            console.log("Name Changed", name);
          });
        });