How to add multiple feature layers to a map?

2019
2
Jump to solution
07-18-2017 07:00 AM
BradGeerdes
New Contributor

I'd like to know how to add multiple feature layers to a map? I tried syntax like the following, but only the last feature was added.

from arcgis.features import FeatureLayer
from arcgis.features import FeatureCollection

my_map4 = my_gis.map('Chicago', 9)
my_map4.basemap = 'osm'

f1 = FeatureLayer('http://xxx.com/arcgis/rest/services/Stage/crew_change_point_service/MapServer/0')
f2 = FeatureLayer('http://xxx.com/arcgis/rest/services/Stage/yard_service/MapServer/0')
my_map4.add_layer([f1, f2])

my_map4

0 Kudos
1 Solution

Accepted Solutions
RohitSingh2
Esri Contributor

The map widget should be displayed before layers are added to it. The following should work:

from IPython.display import display

from arcgis.features import FeatureLayer
from arcgis.features import FeatureCollection

my_map4 = my_gis.map('Chicago', 9)
my_map4.basemap = 'osm'

f1 = FeatureLayer('http://xxx.com/arcgis/rest/services/Stage/crew_change_point_service/MapServer/0')
f2 = FeatureLayer('http://xxx.com/arcgis/rest/services/Stage/yard_service/MapServer/0')
display(my_map4)

my_map4.add_layer([f1, f2])

View solution in original post

0 Kudos
2 Replies
RohitSingh2
Esri Contributor

The map widget should be displayed before layers are added to it. The following should work:

from IPython.display import display

from arcgis.features import FeatureLayer
from arcgis.features import FeatureCollection

my_map4 = my_gis.map('Chicago', 9)
my_map4.basemap = 'osm'

f1 = FeatureLayer('http://xxx.com/arcgis/rest/services/Stage/crew_change_point_service/MapServer/0')
f2 = FeatureLayer('http://xxx.com/arcgis/rest/services/Stage/yard_service/MapServer/0')
display(my_map4)

my_map4.add_layer([f1, f2])

0 Kudos
BradGeerdes
New Contributor

It works like magic. Thank you!

0 Kudos