Select to view content in your preferred language

Change the togglebasemap title

3499
6
Jump to solution
06-17-2016 01:48 AM
Pierre-JeanMuller
Occasional Contributor

I want to change the togglebasemap titles. I tried with the basemaps object, but it doesn't work.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Pierre,

  Here is a sample of how to apply custom basemap names:

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <title>Basemap Toggle</title>
  <link rel="stylesheet" href="http://js.arcgis.com/3.16/esri/css/esri.css">
  <style>
    html, body, #map {
      padding:0;
      margin:0;
      height:100%;
    }
    #BasemapToggle {
      position: absolute;
      top: 20px;
      right: 20px;
      z-index: 50;
    }
  </style>
  <script src="http://js.arcgis.com/3.16/"></script>
  <script>
var map;
    require([
      "esri/map",
      "esri/dijit/BasemapToggle",
      "esri/dijit/Basemap",
      "esri/dijit/BasemapLayer",
      "esri/geometry/Extent",
      "esri/basemaps",
      "dojo/domReady!"
    ], function(
      Map,
      BasemapToggle,
      Basemap,
      BasemapLayer,
      Extent,
      esriBasemaps
    )  {

      map = new Map("map", {
        basemap: 'streets'
      });

      var toggle = new BasemapToggle({
        map: map,
        basemap: "topo",
        basemaps:{
          "streets":{
            "title":"Streets 777",
            "thumbnailUrl":"https://js.arcgis.com/3.16/esri/images/basemap/streets.jpg"
          },
          "topo":{
            "title":"Topography 777",
            "thumbnailUrl":"https://js.arcgis.com/3.16/esri/images/basemap/topo.jpg"
          }
        }
      }, "BasemapToggle");
      toggle.startup();

    });
  </script>
</head>
<body>
  <div id="map" class="map">
    <div id="BasemapToggle"></div>
  </div>
</body>
</html>

View solution in original post

6 Replies
FC_Basson
MVP Regular Contributor

Which version of the API?  3.x or 4.0?

0 Kudos
Pierre-JeanMuller
Occasional Contributor

api 3.16

0 Kudos
FC_Basson
MVP Regular Contributor

I assume you are referring to the Widget title text (Switch Basemap) then.

Specify an id attribute for the TitlePane div:

<div id="basemapTitle" data-dojo-type="dijit/TitlePane"  data-dojo-props="title:'Switch Basemap', closable:false, open:false">

Then with dijit set the new title:

dijit.byId("basemapTtile").set("title", "My new awesome title");

0 Kudos
Pierre-JeanMuller
Occasional Contributor

thanks for your answer, but what I want is to change the texte under the basemap name. For example : in the image, I want to change "Topographie" to "Topography"

2016_06_17_16_33_24_MAP.png

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Pierre,

  Here is a sample of how to apply custom basemap names:

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <title>Basemap Toggle</title>
  <link rel="stylesheet" href="http://js.arcgis.com/3.16/esri/css/esri.css">
  <style>
    html, body, #map {
      padding:0;
      margin:0;
      height:100%;
    }
    #BasemapToggle {
      position: absolute;
      top: 20px;
      right: 20px;
      z-index: 50;
    }
  </style>
  <script src="http://js.arcgis.com/3.16/"></script>
  <script>
var map;
    require([
      "esri/map",
      "esri/dijit/BasemapToggle",
      "esri/dijit/Basemap",
      "esri/dijit/BasemapLayer",
      "esri/geometry/Extent",
      "esri/basemaps",
      "dojo/domReady!"
    ], function(
      Map,
      BasemapToggle,
      Basemap,
      BasemapLayer,
      Extent,
      esriBasemaps
    )  {

      map = new Map("map", {
        basemap: 'streets'
      });

      var toggle = new BasemapToggle({
        map: map,
        basemap: "topo",
        basemaps:{
          "streets":{
            "title":"Streets 777",
            "thumbnailUrl":"https://js.arcgis.com/3.16/esri/images/basemap/streets.jpg"
          },
          "topo":{
            "title":"Topography 777",
            "thumbnailUrl":"https://js.arcgis.com/3.16/esri/images/basemap/topo.jpg"
          }
        }
      }, "BasemapToggle");
      toggle.startup();

    });
  </script>
</head>
<body>
  <div id="map" class="map">
    <div id="BasemapToggle"></div>
  </div>
</body>
</html>
SteveCole
Honored Contributor

I think another option is modifying the default string used by the API. This link discusses that topic. If you follow the suggestion at the bottom of that page, you'll notice that there's a "basemaps" object and I think you'd be able to modify the label/string in there.

Steve

0 Kudos