EDIT: Actually this posted link ended up helping me quite a bit but don't mark it as duplicate because the problem I had using it stemmed from needing to define the map before defining the basemapGallery. See ADDENDUM below.
Note that this post does NOT help me ... How do I use the Terrain with Labels basemap in the Map constructor
I am using PHP and trying to pass in this variable (among others) representing the basemap id "basemap_5" to determine the selected basemap when a new page is "launched" (basically my page launches a new map with the same center (XY) and zoom level).
Then using $_GET I can access the php variable in my javascript to determine which basemap was being viewed and use those variables like this ...
map = new Map("map", {
basemap: bMapName,
center: passedCenter,
zoom: zoomLevel
});
I added a new argument for the basemap (as shown above ... "bMapName") and they all work except this one (basemap_5 aka Terrain with Labels). The error I get is ...
Map.setBasemap: Unable to find basemap definition for: "Terrain with Labels". Try one of these: streets,satellite,hybrid,topo,gray,oceans,national-geographic,osm
I sure wish the error message were updated to include the terrain with labels map!
I also tried "World Terrain Base" since that appears to be the name of the service Link to Service
EDIT: Let me add to this that I'm using the BasemapGallery widget. The problem centers around needing to identify the basemap before creating the basemapGallery (which has "map" set for it's map property). If I can just get around that, I think I could get this to work. I have tried the samples below and from the post I linked to above. I can add custom maps but they aren't recognized (obviously) before they have been added. So how can I get around that?
map = new Map("map", {
basemap: bMapName,
center: passedCenter,
zoom: zoomLevel
});
//add the basemap gallery, in this case we'll display maps from ArcGIS.com including bing maps
basemapGallery = new BasemapGallery({
showArcGISBasemaps: true,
map: map
}, "basemapGallery");
ADDENDUM I got this to work by defining "map" conditionally and setting the basemap property to a created basemap (as in the posted link) in the condition that one of the two maps that weren't working (my custom basemap and the "Terrain with Labels" basemap) were the ones being referenced "over the wire". setting the basemap property as shown in the linked SE post was actually the most helpful part of this but the answer provided here was similarly helpful.
switch (bMap) {
case "basemap_0":
bMapName = "MD Imagery";
break;
case "basemap_1":
bMapName = "osm";
break;
// SEVERAL MORE CASES HERE; TRUNCATED FOR SE POST ...
}
mdImagelayer = new ArcGISTiledMapServiceLayer("http://geodata.md.gov/imap/rest/services/Imagery/MD_SixInchImagery/MapServer");
if (bMapName === "terrain") {
map = new Map("map", {
basemap: new Basemap({id: 'terrain',
layers: [new BasemapLayer({url: 'http://services.arcgisonline.com/arcgis/rest/services/World_Terrain_Base/MapServer'}),
new BasemapLayer({url: 'http://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Reference_Overlay/MapServer'})
]
}),
center: passedCenter, // [-79.2, 39.5]
zoom: zoomLevel // 12
});
} else if (bMapName === "MD Imagery") {
map = new Map("map", {
basemap: new Basemap({id: 'MD Imagery', layers: [mdImagelayer]}),
center: passedCenter, // [-79.2, 39.5]
zoom: zoomLevel // 12
});
} else {
// You may wish to change the id to map or mapDiv (if that is the map you are using
map = new Map("map", {
basemap: bMapName,
center: passedCenter, // [-79.2, 39.5]
zoom: zoomLevel // 12
});
};
//add the basemap gallery, in this case we'll display maps from ArcGIS.com including bing maps
basemapGallery = new BasemapGallery({
showArcGISBasemaps: true,
map: map
}, "basemapGallery");