Select to view content in your preferred language

Graphics without a base map

3813
10
Jump to solution
08-24-2012 02:34 AM
VladimirElistratov
Occasional Contributor
I am unable to use graphics without a base map.

It's written in the doc for Map.onLoad:
Fires when the first or base layer has been successfully added to the map.

So I do the following:

dojo.connect(map,"onLoad", init);
var graphics = new esri.layers.GraphicsLayer();
map.addLayer(graphics);

But I'm getting an error after map.addLayer(graphics):
Uncaught TypeError: Cannot read property '_surface' of null

How can I use graphics without a base map?

Thanks,
Vladimir
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Deactivated User
It is not currently possible to use only a graphics layer (or a feature layer in your map). A dynamic or tiled map service layer is required.

What you can do is subclass dynamic map service layer and override getImageUrl so that it does nothing. This way you end up with an empty layer, and you can use whatever spatial reference you like. This is shown in the writing a class conceptual help topic and here's an example of it:  http://servicesbeta.esri.com/demos/using-classes-with-javascript/legacy/empty_basemap.html

View solution in original post

0 Kudos
10 Replies
__Rich_
Deactivated User
I am unable to use graphics without a base map.

It's written in the doc for Map.onLoad:
Fires when the first or base layer has been successfully added to the map.

So I do the following:

dojo.connect(map,"onLoad", init);
var graphics = new esri.layers.GraphicsLayer();
map.addLayer(graphics);

But I'm getting an error after map.addLayer(graphics):
Uncaught TypeError: Cannot read property '_surface' of null

How can I use graphics without a base map?

Thanks,
Vladimir

Off the top of my head, the first layer you add (i.e. the base layer) cannot be a graphics layer.

I don't know if this is documented anywhere or whether I'm 100% correct, perhaps someone from ESRI can confirm?
0 Kudos
VladimirElistratov
Occasional Contributor
How about adding a dummy non-graphics layer?.


How to add a dummy non-graphics layer?
0 Kudos
__Rich_
Deactivated User
How to add a dummy non-graphics layer?

Add a different layer type that doesn't inherit from esri.layers.GraphicsLayer.

Although, I wonder if this occurs if you add a esri.layers.FeatureLayer as your base layer?  Worth a try?

Any reason why you don't want a 'normal' base layer?
0 Kudos
JeffPace
MVP Alum
Just add layer from AGO (like the world basemap), then set the visibility off.
0 Kudos
VladimirElistratov
Occasional Contributor
jeff.pace:

You solution does works, e.g.:

dojo.connect(map,"onLoad", init);
var agoLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
agoLayer.setVisibility(false);
map.addLayer(agoLayer);

However, this looks like a kind of hack.
I hope, someone from ESRI comes to this thread to provide clarifications.

geos_rfleet:
A base map is simply not need for my app.
0 Kudos
JeffPace
MVP Alum
Its definitely a hack, that's why i suggested it.  You should see my code 😉

Have you tried manually setting the spatial reference of the map after creating it? I know that is what happens when the first layer loads, so maybe that is all that is missing.
0 Kudos
VladimirElistratov
Occasional Contributor
jeff.pace:

It looks like the spatial reference of the map is set to the spatial reference of the map's extent.
I checked this in the debugger
0 Kudos
JeffPace
MVP Alum
jeff.pace:

It looks like the spatial reference of the map is set to the spatial reference of the map's extent.
I checked this in the debugger


Ok, sounds like other stuff that the graphics layer is dependent on is not created in the map object until a layer is added.  Unfortunate in your scenario, but probably necessary in general.
0 Kudos
derekswingley1
Deactivated User
It is not currently possible to use only a graphics layer (or a feature layer in your map). A dynamic or tiled map service layer is required.

What you can do is subclass dynamic map service layer and override getImageUrl so that it does nothing. This way you end up with an empty layer, and you can use whatever spatial reference you like. This is shown in the writing a class conceptual help topic and here's an example of it:  http://servicesbeta.esri.com/demos/using-classes-with-javascript/legacy/empty_basemap.html
0 Kudos