Select to view content in your preferred language

can the basemap be hidden

7386
7
02-13-2013 10:46 AM
KenDeeds
Regular Contributor
When creating a map I've been unable to add layers or do anything if not defining the map.basemap property.  Once I do define a basemap, is there way to hide it or get rid of it and have no basemap?  I just ask because when panning or zooming after another layer is added on top of the basemap, the map loads the basemap tiles/graphics first then loads the layers on top.  In my case I don't want the basemap tiles to have to load at all, seems like extra bandwidth and it looks bad imo when the layer your not supposed to see pops out briefly on zooming or panning.

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

works, but:

map = new esri.Map("map");

results in a page where I can't add any layers or see anything at all but the ESRI logo in the bottom right.
0 Kudos
7 Replies
DianaBenedict
Frequent Contributor
According to the ESRI Javascript API documentation
http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#Map/MapConst

The only required param when creating a new map is the the "mapDivId"

var map = new esri.Map("map");

where "map" = the name of the html div/container that you are using to display the map.  All other options are optional. 
Confirm that you are specifying to correct divID and it should be a string value. After you have instantiated your map, you can instantiate all your layers and either use map.addLayer(myMapService) or map.addLayers([myMapService1,myMapService2]) to add all your desired map services.  You have the option to use the "pre-defined" basemaps if you choose.  Also, don't forget that you can specify your spatial ref by passing in a spatial extent. Maybe that is why you are not seeing any of your data when using the ESRI basemaps.
0 Kudos
SteveCole
Honored Contributor
I thought that the first layer added to the map had to be a base map (or was treated as such). With that logic, maybe you can just add the basemap but pass the option to make the basemap invisible:

 // Create the map
 var map = new esri.Map("map", {
  extent:initExtent //initExtent is a variable w/ your initial extent
 });

 
 // Set up and establish the data layers for the map, beginning with the basemap
 var primaryMapServiceURL = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
 var theBasemap = new esri.layers.ArcGISTiledMapServiceLayer(primaryMapServiceURL, {
  visible: false
 });
 map.addLayer(theBasemap);


The above code is from v2.8 of the API..
0 Kudos
KellyHutchins
Esri Frequent Contributor
What kind of data are you trying to add? At version 3.3 we made it easier to have a map with only a graphics or feature layer as the first layer in the map. Check out the following sample for an example of this:

http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/#sample/data_gas_prices
0 Kudos
KenDeeds
Regular Contributor
I set up an example.  In the fist link here:

http://citgo.bvk.geoconsensus.com/esri/test_no_basemap.php

I do not include the "basemap" attribute in my map definition (view source on it).

in the 2nd link that works the only difference is I define basemap.

http://citgo.bvk.geoconsensus.com/esri/test_with_basemap.php

What I don't like is in the 2nd example if I zoom or pan quickly (espeically on a slow connection) it loads the basemap first, then the Tiled Map Service that I want to be the only visible layer.  When I also add this to onload "map.basemap.hide()" then the map doesn't work on panning or zooming but it hides the basemap.

The only difference in the two links above is:

map = new esri.Map("map", {
   infoWindow : popup,
   zoom: 6
});

vs

map = new esri.Map("map", {
   infoWindow : popup,
   basemap : "streets",
   zoom: 6
});
0 Kudos
DianaBenedict
Frequent Contributor
I copied your code and put it into my project and was able to step through the code.  I noticed that the mao.OnLoad event does NOT get fired until AFTER the 1st layer has been added

so If you want your map to work without a base map then I would suggest that your do not connect your map.addLayer to the onLoad event. Below is what I mean:

  dojo.require("esri.map");
  dojo.require("esri.layers.osm");
  dojo.require("esri.layers.FeatureLayer");
  dojo.require("dijit.dijit");
  dojo.require("esri.dijit.Popup");

  dojo.addOnLoad(init);
  var centerpoint = 0;
  var map = 0;
  var windowProxy;
  var current_open_marker = 0;
  var mouseover = 0;

  function init() {
    esriConfig.defaults.map.zoomDuration = 220;
    esriConfig.defaults.map.panDuration = 220;
    var popup = new esri.dijit.Popup(null, dojo.create("div"));
    map = new esri.Map("map", {
      infoWindow: popup,
      zoom: 6
    });

    var testlayer = initlayer('http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer', 'CTGF5889DE7840DB7AC4', 1);

    dojo.connect(map, "onLoad", function () {
      //var testlayer = initlayer('http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer', 'CTGF5889DE7840DB7AC4', 1);
      testlayer.show();
      //map.hideZoomSlider();
      $(document).ready(function () {
        //do future onload code 
      });
    });
  }

  function initlayer(url, id, opacity) {
    var layer = new esri.layers.ArcGISTiledMapServiceLayer(url, { 'id': id, 'opacity': opacity, 'visible': false });
    map.addLayer(layer);
    return layer;
  }
KenDeeds
Regular Contributor
Dianna,

Will give this a try later today, thanks for the help, suggestion makes sense.  Will follow up and let you know how it goes.
0 Kudos
by Anonymous User
Not applicable

Yes, you can remove the basemap once it's added to the map. I was unable to find any resources in the documentation, but after some trial and error was able to do so by calling:

map._removeBasemap();

Which is extremely useful if you are using your own custom basemaps with Esri's basemaps. 🙂

0 Kudos