Adding Custom Basemaps to Basemap Gallery in 4.3

5350
10
Jump to solution
04-10-2017 08:30 AM
NathanSommers1
New Contributor

I have imagery dating back 20 years or so that I need to add to my Basemap Gallery widget in a v4.3 map. Has anyone figured out how to add these custom basemap layers to the widget in this version of the APi?

Here's an example of one of the layers I'd like to add to the Basemap Gallery.

// Mapbox Basemap URL
 var mapbox = new WebTileLayer({
 urlTemplate: "https://api.mapbox.com/styles/v1/mapbox/streets-v10/tiles/256/{level}/{col}/{row}"
 });
 
 // Mapbox Basemap
 var mapboxBasemap = new Basemap({
 baseLayers: [mapbox],
 title: "Mapbox",
 id: "mapbox",
 thumbnailUrl: "includes/images/mapbox.PNG"
 });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This is how I have the Basemap Gallery widget styled right now. I'm using an Expand on it, so it may look different than the normal widget layout.

//Basemap Gallery Widget
 var basemapGallery = new BasemapGallery({
 view: view,
 container: document.createElement("div")
 });
 
 var basemapGalleryExpand = new Expand({
 view: view,
 content: basemapGallery.domNode,
 expandIconClass: "esri-icon-basemap"
 });
 
 view.ui.add(basemapGalleryExpand, {
 position: "top-right"
 });

Also, does anyone known the line to hide the default ArcGIS Basemaps in the widget? The old line doesn't/didn't work in this version of the API. (Below is the old line of code that used to hide the default basemaps.)

showArcGISBasemaps: false,
0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Occasional Contributor III

I don't see the part where you are trying to add your Basemap to the BasemapGallery. Below is the documentation for source in BasemapsGallery

The source for basemaps that the widget will display. This property can be autocast with an array or Collection of Basemaps, a Portal instance, or a URL to a portal instance. The default source is a PortalBasemapsSource that points to the default portal instance set in esriConfig.portalUrl.

You need to create an instance of LocalBasemapsSource, and set the source property of the BasemapGallery. That will clear all the protal basemaps and only your custom basemap will be available.

      var localSource = new LocalBasemapsSource({
        basemaps : [stamen]
      })

      var basemapGallery = new BasemapGallery({
        view: view,
        container: document.createElement("div"),
        source: localSource
      });

View solution in original post

10 Replies
thejuskambi
Occasional Contributor III

I don't see the part where you are trying to add your Basemap to the BasemapGallery. Below is the documentation for source in BasemapsGallery

The source for basemaps that the widget will display. This property can be autocast with an array or Collection of Basemaps, a Portal instance, or a URL to a portal instance. The default source is a PortalBasemapsSource that points to the default portal instance set in esriConfig.portalUrl.

You need to create an instance of LocalBasemapsSource, and set the source property of the BasemapGallery. That will clear all the protal basemaps and only your custom basemap will be available.

      var localSource = new LocalBasemapsSource({
        basemaps : [stamen]
      })

      var basemapGallery = new BasemapGallery({
        view: view,
        container: document.createElement("div"),
        source: localSource
      });
NathanSommers1
New Contributor

Perfect. That's just what I was looking for.

0 Kudos
AlifShaikh
New Contributor

Hi,

Can you Nathan Sommers   post a complete sample code?

Regards,

Alif

0 Kudos
JayakumarPD
Occasional Contributor

Hi,

Create a local base map like this

var Localbasemap = new Basemap({
baseLayers: [
new MapImageLayer({
url: "https://XXXXXXXX/rest/services/XXXXX/XXXXX/MapServer",
title: "Basemap"
})
],
title: "basemap",
id: "basemap12"
});

and add it like this

var basemapGallery = new BasemapGallery({
view: view,
//source:localSource
source: [Basemap.fromId("topo-vector"), Basemap.fromId("hybrid"), Localbasemap]
});

If youo want more default basemap from esri add Basemap.fromId("what ever required")

Note: please add "esri/layers/MapImageLayer" in required library

0 Kudos
syamalaNarem
New Contributor

Hi ,

 

This code works fine if I provide BaseMaps id like topo-vector, streets , already  defined once.

 

my local source is not working  not loading any maps and no errors shown in console for my own urls.

My local source titles are displaying correctly , but no action is done when I click on it.

can you please provide one sample for changing/adding our own  custom base map widget   along with layers in the collection of base map for local source.

Also please provide if available in 4.22 version.

 Thanks.

0 Kudos
JayakumarPD
Occasional Contributor

What is local source ? Not understood.  

0 Kudos
ADITYAKUMAR1
Occasional Contributor III

Hi @syamalaNarem ,

I am facing a similar issue where I can see the map  in the basemap gallery but on click nothing happens. Did you managed to  solve it?

0 Kudos
JayakumarPD
Occasional Contributor

is it possible to share the code

0 Kudos
ADITYAKUMAR1
Occasional Contributor III

this.customBasemap = new Basemap({

                                      baseLayers: [

                                          new TileLayer({

                                              url: customBasemapServiceUrl,

                                              title: mapservice.MapServiceName

                                          })

                                      ],

                                      title: mapservice.MapServiceName,

                                      id: mapservice.MapServiceName,

                                      thumbnailUrl: customBasemapServiceUrl + '/info/thumbnail'

 

                                     

                                  });

0 Kudos