FeatureLayer is loaded but not shown

4029
15
Jump to solution
12-07-2016 04:53 PM
雯妍汤
New Contributor II

   When loading a Feature Service from my localhost, I came to this strange thing: All my feature layers are loaded without any error, but they can not be seen on the map. 

   In ArcGIS, it should be like this:

   

   In Browser, it shows nothing. However, click on feature do does a query and returns the right data.

   Changing Layer's Display Order does not fix it. 

   Do I have to write a client js Render myself, or am I missing something. Can anyone give some help.

Tags (1)
0 Kudos
15 Replies
RobertScheitlin__GISP
MVP Emeritus

Hmm..

   I can use the same code (and just update to my local WKID urls and change the maps extent to mine) and it works fine.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Get started with MapView - Create a 2D map - 4.1</title>
  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <link rel="stylesheet" href="https://js.arcgis.com/4.1/esri/css/main.css">
  <script src="https://js.arcgis.com/4.1/"></script>

  <script>
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/Basemap",
      "esri/layers/TileLayer",
      "esri/layers/FeatureLayer",
      "dojo/domReady!"
    ], function(Map, MapView, Basemap, TileLayer, FeatureLayer) {

      /** tile map server url */
    var tileUrl = "my url/arcgis/rest/services/myservice/MapServer";
    var tileLayer = new TileLayer({
        url: tileUrl
    });
    /** feature server url  */
    var featureBaseUrl = "my url/arcgis/rest/services/my service/MapServer";

    /** predefined layer id array list*/
    var featureArray = ['0', '1', '2', '3', '4','6'];
    /** store feature layer in this list */
    var featureLayerList = [];

    /** create a basemap */
    var baseMap = new Basemap({
        baseLayers: [tileLayer],
        title: "Metro Scan Basemap",
        id: "scanBaseMap"
    });
    /** initial a map, set the TileLayer as its basemap*/
    var map = new Map({
        basemap: baseMap //comment or uncomment this line not solve my issue
    });

    /** create map view */
    var view = new MapView({
        container: "viewDiv",
        map: map,
        extent: {
            xmin: 561001.09,
            ymin: 1111717.35,
            xmax: 748322.18,
            ymax: 1262842.31,
            spatialReference: 102629
        }
    });
    var popupTemplate = {
        title: "<h5 style='font-family:Microsoft Yahei Light;'>{Type}</h5>",
        content: "<table style='font-family:Microsoft Yahei Light;'><tbody>" +
            // "<tr><td>类型:</td><td> " + layerName + "</td></tr>" +
            "<tr><td>环号:</td><td> {Ring}</td></tr>" +
            "<tr><td>里程:</td><td> {Mile}</td></tr>" +
            "</tbody></table>"
    };
    view.then(function () {
        /** add feature layer to map */
        featureArray.forEach(function (layerName) {
            var url = featureBaseUrl + '/' + layerName;
            var layer = new FeatureLayer({
                url: url,
                outFields: ["*"],
                popupTemplate: popupTemplate,
                opacity: 0.5
            });
            map.add(layer);
            featureLayerList.push(layer);
        });
    });

    });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>
</html>
0 Kudos
雯妍汤
New Contributor II

Your starting point is right, the problem comes from the Spatial Reference. 

After replace the former SR with WGS_1984_Web_Mercator_Auxiliary_Sphere, feature layer can now properly display.

Thanks for your time Robert!

0 Kudos
FC_Basson
MVP Regular Contributor

You haven't loaded your custom(?) basemap/Image Service over you features by accident?

0 Kudos
雯妍汤
New Contributor II

No, I don't think so.

After removing the base map layer, feature layer symbol still won't show.

0 Kudos
雯妍汤
New Contributor II

    All right, after several days of struggle, I finally make symbols show by switching my Spatial Reference System from Beijing_1954_GK_Zone_20N(WKID: 21480) to WGS_1984_Web_Mercator_Auxiliary_Sphere(WKID: 3857).

   My map is a subway 3D-laser scanning image using an assumed coordinate system, it does not matter whatever the actual SR is.

   But, curiously, I'm wondering what if I'm really have to use that projection system, how to solve that question I raised above.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Wen Yan Tang,


  The 4.x Js API is not as mature as the 3.x API so because you are using a custom WKID and are only using a 2D view I would recommend using the 3.x version

0 Kudos