Bookmark Widget Fit Extent

340
1
06-13-2013 10:01 AM
JustinShepard
Occasional Contributor II
I have a series of bookmarks that are in the same wkid as the map. However, for some of them if I click on the bookmark the feature extends off of the display area because it seems to be snapping to the closest Level of Detail. I'm looking for a way to force a bookmark to fit the extent to the map when I have a tiled layer (i.e. basemap) in the map; something like the setExtent(extent,fit) has http://developers.arcgis.com/en/javascript/jsapi/map.html. Has anyone run into this before?

The workaround, that I don't like, is to zoom out by 1 level after the extent changes. This ensures that everything is visible but zooms out farther than necessary in other cases.
0 Kudos
1 Reply
JustinShepard
Occasional Contributor II
Hopefully someone has a simpler solution to this but in case anyone else is looking for a workaround, or a starting point to keep working from, here's what I have thus far (using a mix of jquery and dojo):

var iBookmarkXDiff;
var iBookmarkYDiff;

var bookmarksAll = new esri.dijit.Bookmarks({
        map: map,
        bookmarks: bookmarkList_All
    }, dojo.byId('BookmarkID'));

$(".esriBookmarkLabel").click(function () {
        var bookmarkName = $(this).html();
        for (var i = 0; i < bookmarkList_All.length; i++) {
            var iBookmark = bookmarkList_All;
            if (bookmarkName == iBookmark["name"]) {
                //set global values that will be used in fitBookmark function
                iBookmarkXDiff = iBookmark["extent"].xmax - iBookmark["extent"].xmin;
                iBookmarkYDiff = iBookmark["extent"].ymax - iBookmark["extent"].ymin;
            }  
        }
    });

dojo.connect(bookmarksAll, "onClick", function myfunction() {
        // connect fit handler to execute when the map update is finished
        fitHandler = dojo.connect(map, "onUpdateEnd", fitBookmark);
    });

function fitBookmark() {
    dojo.disconnect(fitHandler);
    var cMapLevel = map.getLevel();
    var cExtent = map.extent;
    var cMapXDiff = cExtent.xmax - cExtent.xmin;
    var cMapYDiff = cExtent.ymax - cExtent.ymin;
    if (cMapXDiff < iBookmarkXDiff || cMapYDiff < iBookmarkYDiff) {
        map.setLevel(cMapLevel - 1);
    }
}
0 Kudos