I've added the HomeButton dijit into my map. When it is first opened, the map is centered on the state of Alabama. When the HomeButton is pressed, the extent moves to the northeast and is centered on the eastern Tennesse area. Has anyone else experienced this or know a way to resolve it? Thanks in advance!
Ashley,
You can assign the extent that you want the button to use in the dijits constructor.
https://developers.arcgis.com/javascript/jsapi/homebutton-amd.html#homebutton1
Robert,
I did use the constructors yesterday before I posted the initial question. I should have mentioned that.
I had previously created an initial extent to use within my map. I used that same variable in the HomeButton with the extent constructor. As soon as I open the map, I can hit the HomeButton and it will automatically move to the northeast of where I have it set.
I haven't tried hardcoding the extent in to see if that would work, but I'm not sure what else to try.
Ashley
Ashley,
Can you post the code you are using? Minus your service urls of course.
Here's the portion of the .js file I've modified that deals with the HomeButton and initial extent. I know I likely don't need the center, extent and zoom constructors in the map, but I've been trying a multitude of different things to resolve the map bumping away. If you need the rest of the code, let me know and I'll post it.
*Edit - Looking further, could this be a wkid issue?
var extentInitial = new Extent({
"xmin": -9850000,
"ymin": 3400000,
"xmax": -9320000,
"ymax": 4300000,
"spatialReference": {
"wkid": 102100
}
});
// Create the map
mapMain = new Map("cpCenter", {
basemap: "satellite",
//center: [-85.6, 34.4],
extent: extentInitial,
zoom: 7
});
// Add BasemapGallery widget to the map
var basemapGallery = new BasemapGallery ({
showArcGISBasemaps: true,
map: mapMain}, "basemapGallery");
basemapGallery.startup();
// Add HomeButton widget to the map
var home = new HomeButton({
map: mapMain,
extent: extentInitial
}, "HomeButton");
home.startup();
I tested the idea of the wkid being an issue. My services had 2 wkids. I fixed those where they all have the same wkid now. I also re-did my initial extent to reflect the new wkid. The map still moves when I press the home button.
Ashley,
I am not having any luck on this issue.
Thanks for your time Robert!
I use the map.centerAndZoom() method on a button of my own making instead of the Home button offered by ESRI. Have you given that a try?
On map load I grab the layer in the map that I want to use for center, get the extent, then get the center of the extent (re-project to web mercator if necessary) and use that as the center point:
map.centerAndZoom(layer.fullExtent.getCenter(), 10)
Or
GS.project([layer.fullExtent.getCenter()], mercProjectionVar, function(pt) { map.centerAndZoom(pt[0], 10) });
Sarah,
I haven't tried that, but it sounds like it may be worth the effort. I'm new to JavaScript, so I'm trying to keep things as simple as possible. So right now, though the HomeButton dijit is acting a little wonky, it's usable. But I'll give that a shot once I feel more confident in my JavaScript writing capabilities!
Ashley