Select to view content in your preferred language

Add layer from Arcgis Server to API Javascript

4883
4
Jump to solution
01-27-2015 01:31 AM
VincentChoffrut
New Contributor

Hello everyone,

I would like to add a layer (stored with arcgis server on localhost -as you can see with the url) on my map (and this SHOULD be quite simple).

can someone tell me why this simple script isn't working? (it loads the topo basemap, ok, but NO LAYER)

<script>

            var map;

      require

            (["esri/map",

                "esri/layers/FeatureLayer",

                "dojo/domReady!"],

               

                    function(Map,

                    FeatureLayer)

                        {

                            var map = new Map("map",

                            {

                            basemap: "topo",

                            center: [0.694357, 47.395560],

                            zoom: 8

                            });

                   

                            var rivers = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/CARTAGES/Lineaire_Hydro_Loire_Bretagne/MapServer");

                       

                            map.addLayer(rivers);

                        }

            ); 

    </script>

thanx a lot in advance

vincent

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

When you add a FeatureLayer, you have to specify a single layer within the service.

var rivers = new FeatureLayer("http://localhost:6080/arcgis/rest/services/CARTAGES/Lineaire_Hydro_Loire_Bretagne/MapServer/0");

From the Help‌:

The feature layer inherits from the graphics layer and can be used to display features from a single layer in either a Map Service or Feature Service.

View solution in original post

4 Replies
TimWitt2
MVP Alum

Vincent,

try the following:

<script>

            var map;

      require

            (["esri/map",

                "esri/layers/ArcGISTiledMapServiceLayer",

                "dojo/domReady!"],

              

                    function(Map,

                    ArcGISTiledMapServiceLayer)

                        {

                            var map = new Map("map",

                            {

                            basemap: "topo",

                            center: [0.694357, 47.395560],

                            zoom: 8

                            });

                  

                            var rivers = new ArcGISTiledMapServiceLayer("http://localhost:6080/arcgis/rest/services/CARTAGES/Lineaire_Hydro_Loire_Bretagne/MapServer");

                      

                            map.addLayer(rivers);

                        }

            );

    </script>

Hope this helps!

Tim

0 Kudos
VincentChoffrut
New Contributor

I had already tryed using the tiledmapservice but it doen't provide any display (at all, in my simple case, I mean).

Thanx a lot, Tim, for your answer & advice!

greetings from paris, anyway

vincent

0 Kudos
KenBuja
MVP Esteemed Contributor

When you add a FeatureLayer, you have to specify a single layer within the service.

var rivers = new FeatureLayer("http://localhost:6080/arcgis/rest/services/CARTAGES/Lineaire_Hydro_Loire_Bretagne/MapServer/0");

From the Help‌:

The feature layer inherits from the graphics layer and can be used to display features from a single layer in either a Map Service or Feature Service.

VincentChoffrut
New Contributor

THAT'S IT

thank you Ken, like, a million times!!!

0 Kudos