2

I have this code that is mostly from an ArcGIS JS API sample:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Create Map and add a dynamic layer</title>
    <link rel="stylesheet" href="http://js.arcgis.com/3.13/esri/css/esri.css"/>
    <style>
      html, body, #mapDiv{
        padding: 0;
        margin: 0;
        height: 100%;
      }
    </style>
    <script src="http://js.arcgis.com/3.13/"></script>
    <script>
      var map;

      require([
        "esri/map",
        "esri/layers/ArcGISDynamicMapServiceLayer",
        "esri/layers/ImageParameters"
      ], function (
        Map, ArcGISDynamicMapServiceLayer, ImageParameters) {

        map = new Map("mapDiv", {
          sliderOrientation : "horizontal"
        });

        var imageParameters = new ImageParameters();
        imageParameters.format = "jpeg"; //set the image type to PNG24, note default is PNG8.

        //Takes a URL to a non cached map service.
        var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer", {
          "opacity" : 0.5,
          "imageParameters" : imageParameters
        });

        map.addLayer(dynamicMapServiceLayer);
      });
    </script>
  </head>
  <body>
    <div id="mapDiv"></div>
  </body>
</html>

It works properly. Now I copied the content of http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer in an html file and saved it in C:\inetpub\wwwroot\myweb\usa.html I started my iis service and tried to use this url http://localhost/myweb/usa.html instead of above mentioned url for ArcGISDynamicMapServiceLayer. It doen't work and it throws this error: Resource interpreted as Script but transferred with MIME type text/html: "http://localhost/myweb/test2.html? Am I missing something? This may be basic question but the answer is important for me.

  • 1
    You've only copied the HTML of a REST endpoint, so the JavaScript API doesn't know how to handle that. Are you trying to run your own GIS server? – Mintx Apr 13 '15 at 21:52
  • Yes, but I don't have arcgis for server. So, what do I need to do? – f.ashouri Apr 14 '15 at 4:52
  • What is your end goal? Do you have a service you are trying to share and using that sample as an example of how to do it, or are you trying to share something you've done like a map service and host it on your website? – Branco Apr 16 '15 at 12:21
  • 2
    So you want to implement map server REST API so your localhost will act as ArcGIS server and to use esri js api. Not so easy task - here is what you need to implement: sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/… You'd better forget this idea. – r.pankevicius Apr 16 '15 at 12:42
  • 2
    Buy ArcGIS server. Or use open source GIS servers. – r.pankevicius Apr 16 '15 at 12:47
3
+50

So from my understanding of the comments, you are looking to share your shapefile data as a service and consume it using ESRI's JS API. From this understanding, I will outline one way of sharing and consuming your data using GeoServer although others like MapServer are similar.

I prefer to get the whole OpenGeo suite from Boundless. It will come with a bunch of pieces of software. The major one to worry about is GeoServer. The rest are very useful if you decide to expand what you're doing.

Setting up GeoServer and publishing a shapefile is far beyond the scope of this forum. However, the documentation should be sufficient to get you going on this. Once you have your server set up and your data published, we have to consume it somehow.

GeoServer doesn't share services completely like the ArcGIS Server. Instead, they opt more for OGC compliant WMS (Web Map Service) as a primary way to share. There are others, but to keep it simple, I am recommend starting with WMS.

ESRI's JS API can utilize a WMS layer to show your data. This sample uses a service shared from an ArcGIS server as WMS instead of REST like your example. There isn't much functionality other than displaying the tiles to show the locations of the features. In order to get more functionality, you will need to query GeoServer to get attribute information for click locations or share the service as another layer. Both of those go beyond this scope.

Now another way to do this much more simpler is to utilize GeoExplorer. In the Boundless package, this integrates pretty well with GeoServer. You can see a demo of GeoExplorer to see how it operates. It is indeed different than ESRI's JS API, but is a lot more beginner friendly. GeoExplorer handles most of the things you would need to code in ESRI's JS API, but it does not support as much customization.

If this is a route you wish to go, get started installing the server and post new questions if problems arise. The documentation should be very thorough for it and should cover most questions.

  • Thanks, about the boundless and geoExplorer, are they kind of api like esri js api or openlayers? Is geoserver included if i install boundless ? (I already have geoserver installed) – f.ashouri Apr 18 '15 at 18:17
  • 1
    The Boundless package includes all of the stuff. I am not entirely sure if you can get something like GeoExplorer outside of that package or not? GeoExplorer isn't like the APIs because it pretty much configures everything for you. You just let it attach to a GeoServer instance, and it handles the difficult stuff for you. Depending on your level of complexity for your application, it may do everything or not enough for you. – Branco Apr 20 '15 at 12:32
1

You cannot just copy a content from a webpage to localhost and await that it will work, especially when it's a service. There will be many broken references and ArcGIS JS API will look for content on your localhost that is not there.

If you want to play with some map server configuration, you have to install one. If not, there is no need to have the map data at localhost, because the only difference in approaching the data is in the URL.

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.