2

I have published a shapefile on ArcGIS Server, now want to add it to map. I used feature layer to add it to map but it does not display. Here is my code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>FeatureLayer</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css">
<script src="https://js.arcgis.com/3.20/"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<style>
html, body, #map {
  padding: 0;
  margin: 0;
  height: 100%;
  width: 100%;
}
</style>
<script>
require([
    "esri/map",
    "esri/layers/FeatureLayer",
    "dojo/domReady!"
  ],
  function(
    Map,
    FeatureLayer

  ) {

    var map = new Map("map", {
      basemap: "hybrid",
      center: [69.3451, 30.3753],
      zoom:6
    });

    /****************************************************************
     * Add feature layer - A FeatureLayer at minimum should point
     * to a URL to a feature service or point to a feature collection 
     * object.
     ***************************************************************/


    var featureLayer = new FeatureLayer("url");

    map.addLayer(featureLayer);

  });
</script>
</head>
<body>
  <div id="map"></div>
</body>
</html>

But the problem is my shapefile is in WGS 1984 and the Esri map projection is Web Mercator. Is this the problem? I have tried to display with dynamic layer but same result. My shapefile is not showing in any case.

  • Have you tried publishing the shapefile in the desired projection? It's far less efficient, but not impossibly so. – Vince Apr 9 '17 at 15:17
1

You have a simple fix: In my case I copied/pasted your code, set the URL to an internal service that I knew worked. Then I noticed you defined your URL as a string not a variable. So I commented it out and showed a working example. Good Luck...

    var url = "http://gis02:81/arcgis/rest/services/CIDataTest/FeatureServer/0"

var featureLayer = new FeatureLayer(url);  //<<url is a variable
 //var featureLayer = new FeatureLayer("url");  //<< url is a String
  • shouldnt they both work? – ziggy Apr 10 '17 at 12:39
  • No the string is just the letters url, the variable has the url http://... as it's value, you want the variable so it knows were the service is.. – Bill Chappell Apr 10 '17 at 12:41
  • Add this to your example and you will see it's not a projection issue as the Tree data is in PA state plane, var url = "maps.allentownpa.gov/arcgis/rest/services/ParksMemorialTrees/…" var featureLayer = new FeatureLayer(url); //var featureLayer = new FeatureLayer("url"); – Bill Chappell Apr 10 '17 at 12:53
  • thanks yes i have solved the problem .i was giving string not a variable – Sarah Salar Apr 11 '17 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.