Book Image

Building Web and Mobile ArcGIS Server Applications with JavaScript

By : Eric Pimpler
Book Image

Building Web and Mobile ArcGIS Server Applications with JavaScript

By: Eric Pimpler

Overview of this book

<p>ArcGIS Server is the leading software for developing both web and mobile GIS applications. There are a number of programming languages that you can use to develop applications with ArcGIS Server including JavaScript, Flex, and Silverlight. However, the ArcGIS API for JavaScript is the preferred way of developing your custom applications for ArcGIS Server since it can be used for both web and mobile application development. It’s easy to use and doesn’t require the use of a browser plugin.</p> <p>This tutorial-based guide provides you with hands-on experience in developing custom web and mobile ArcGIS Server applications with step-by-step style exercises. Along with introducing you to the HTML/CSS/JavaScript technology stack, you will learn to add intuitive geographic layers of information to your map, interactive query and display of spatial data, add user interface widgets, access geoprocessing tasks, and many more in your own web and mobile GIS applications.</p> <p>With this practical, hands-on guide, you will be able to develop fully-functional online GIS applications with ArcGIS Server using the ArcGIS API for JavaScript. After creating your own map, you will explore how to add geographic layers from a variety of sources including tiled and dynamic map services, add graphics to the map, and stream geographic features to the browser using a FeatureLayer.</p> <p>Most applications include the specific functionalities implemented by ArcGIS Server as tasks. You’ll learn how to use the various tasks provided by ArcGIS Server including spatial and attribute queries, identification of features, finding features by attribute, and more. Geocoding and geoprocessing tasks are covered in-depth to help you accomplish your task in GIS. Finally, you’ll learn just how easy it is to integrate ArcGIS.com content into your custom developed applications.</p> <p>This comprehensive guide quickly advances through probing programmatic techniques for building web and mobile GIS applications which will make application development a lot easier!</p>
Table of Contents (20 chapters)
Building Web and Mobile ArcGIS Server Applications with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time to practice with sample layouts


In this exercise, you will download a sample layout provided by Esri. You'll then examine the layout to get a feel of the basic layout elements provided by Dojo. Finally, you'll make some changes to the layout.

  1. Before starting this exercise, you'll want to make sure that you have access to a web server. If you don't have access to a web server or if a web server isn't already installed on your computer, you can download and install the open source web server Apache (http://httpd.apache.org/download.cgi). Microsoft IIS is another commonly used web server and there are many others that you can use as well. For the purpose of this exercise, I will assume that you are using the Apache web server.

  2. A web server installed on your local computer will be referred to through URL as http://localhost. This points to the htdocs folder under C:\Program Files\Apache Software Foundation\Apache2.2\ if you've installed Apache on a Windows platform.

  3. On the Samples tab of the ArcGIS API for JavaScript site (https://developers.arcgis.com/en/javascript/jssamples/), search for Layouts in the search box to generate a list of available layout samples.

  4. Scroll down the list of search results until you see the Layout with left pane sample seen in the following screenshot. Click on this item:

  5. Click on the Download as a zip file link to download the sample.

  6. Create a new folder in your htdocs folder under C:\Program Files\Apache Software Foundation\Apache2.2\ and name it layout. Unzip the file that you downloaded into this folder. This will create a file called index.html, along with the css and images folders.

  7. Open a web browser and go to the URL http://localhost/layout/index.html so you can see the current layout. You should see something similar to the following screenshot:

  8. Open index.html in your favorite text or web editor.

  9. Scroll to the bottom of the file until you see the <body> tag.

  10. The highest level layout container is BorderContainer. A <div> tag will contain BorderContainer and all other child layout elements need to be located inside this <div> tag. Examine the following code. The highlighted section is the code used to define our top level BorderContainer. Notice that the design has been set to headline, which means that the top and bottom regions will be scrolled across the entire width of the screen:

    <body class="claro">
      <div id="mainWindow" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline'"
      style="width:100%; height:100%;">
    
        <div id="header" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
            <div id="title">
          </div>
        </div>
    
        <div data-dojo-type="dijit.layout.ContentPane" id="leftPane" data-dojo-props="region:'left'">
          <div data-dojo-type="dijit.layout.TabContainer">
            <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:'Tab 1', selected:'true'">
              Content for the first tab
            </div>
            <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:'Tab 2'">
              Content for the second tab
            </div>
          </div>
        </div>
    
        <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'"></div>
    
        <div id="footer" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'bottom'">
          <span id="dataSource">
          </span>
        </div>
    
      </div>
    </body>
  11. Inside BorderContainer, you will find several child layout elements defined with the ContentPane dijit. ContentPane is a very generic layout element that simply holds either text or additional layout elements, such as TabContainer or AccordionContainer.

    <body class="claro">
      <div id="mainWindow" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline'"
        style="width:100%; height:100%;">
    
        <div id="header" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
          <div id="title">
          </div>
        </div>
    
        <div data-dojo-type="dijit.layout.ContentPane" id="leftPane" data-dojo-props="region:'left'">
          <div data-dojo-type="dijit.layout.TabContainer">
            <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:'Tab 1', selected:'true'">
              Content for the first tab
            </div>
            <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:'Tab 2'">
              Content for the second tab
            </div>
          </div>
        </div>
    
        <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'"></div>
    
        <div id="footer" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'bottom'">
          <span id="dataSource">
          </span>
        </div>
    
      </div>
    </body>

    Tip

    Notice that in the previous code example, each ContentPane layout element has a region that has been designed for each layout element. In this case, we have defined all of the available regions, with the exception of the right region. This is illustrated in the following screenshot:

  12. Next, examine the following highlighted code. The highlighted code defines the content for the left region. A simple ContentPane layout element is defined, which as I mentioned previously is a very simple container for other layout elements or text. Inside this ContentPane, we have created a TabContainer layout element and assigned two tabs. Each tab is created as ContentPane.

    <body class="claro">
      <div id="mainWindow" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline'"
        style="width:100%; height:100%;">
    
          <div id="header" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
            <div id="title">
            </div>
          </div>
    
          <div data-dojo-type="dijit.layout.ContentPane" id="leftPane" data-dojo-props="region:'left'">
            <div data-dojo-type="dijit.layout.TabContainer">
              <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:'Tab 1', selected:'true'">
                Content for the first tab
              </div>
              <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:'Tab 2'">
                Content for the second tab
              </div>
            </div>
          </div>
    
          <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'"></div>
    
          <div id="footer" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'bottom'">
          <span id="dataSource">
          </span>
        </div>
    
      </div>
    </body>
  13. A common scenario would be to create a tab container that holds a legend for the map, as seen in the following screenshot:

  14. Now that you understand the basic concepts of creating layout elements, you can add content for the right region. Add the following highlighted code:

    <body class="claro">
      <div id="mainWindow" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline'"
        style="width:100%; height:100%;">
    
        <div id="header" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
          <div id="title">
          </div>
        </div>
    
        <div data-dojo-type="dijit.layout.ContentPane" id="leftPane" data-dojo-props="region:'left'">
          <div data-dojo-type="dijit.layout.TabContainer">
            <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:'Tab 1', selected:'true'">
              Content for the first tab
            </div>
            <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:'Tab 2'">
              Content for the second tab
            </div>
          </div>
        </div>
    
        <div data-dojo-type="dijit.layout.ContentPane" id="rightPane" data-dojo-props="region:'right'">
          Content for right pane
        </div>
    
    
        <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'"></div>
    
        <div id="footer" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'bottom'">
          <span id="dataSource">
          </span>
        </div>
    
      </div>
    </body>
  15. In the css folder that you extracted earlier in the exercise, there is a file called layout.css. This contains the styling information for our application. Open this file in your text editor.

  16. Find the text #rightPane as seen in the following code example. Properties are defined for the background color, foreground color, border styling, and width of the region:

    #rightPane {
      background-color:#FFF;
      color:#3f3f3f;
      border:solid 2px #224a54;
      width:20%;
    }
  17. Recall that in the previous code block that you added, we gave id of rightPane to the right region. The CSS section will style our pane by giving it a background color (white), foreground color, width, and border.

  18. Save the file.

  19. If necessary, open your web browser and reload http://localhost/layout/index.html, or simply refresh the page if you already have it opened. Now you should see new content for the right region of the application. Currently, it only holds some text as the content, but you could easily add additional content, including user interface widgets (dijits). We'll do that in the next step when we add AccordionContainer.

  20. Next, we'll add AccordionContainer to the right region.

  21. First, add a reference to the AccordionContainer resource, as seen in the following highlighted code:

    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.ContentPane");
    dojo.require("dijit.layout.TabContainer");
    dojo.require("esri.map");
    dojo.require("esri.arcgis.utils");
    dojo.require("esri.IdentityManager");
    dojo.require("dijit.layout.AccordionContainer");
    
  22. Now, add AccordionContainer inside ContentPane for the right region as well as the content for each of the panes. The highlighted code below should be added to the ContentPane you created in step 14:

    <div data-dojo-type="dijit.layout.ContentPane" id="rightPane" data-dojo-props="region:'right'">
      <div data-dojo-type="dijit.layout.AccordionContainer" >
        <div data-dojo-type="dijit.layout.ContentPane" title="Pane 1">
        Content for Pane 1
        </div>
        <div data-dojo-type="dijit.layout.ContentPane" title="Pane 2">
          Content for Pane 2
        </div>
        <div data-dojo-type="dijit.layout.ContentPane" title="Pane 3">
        Content for Pane 3
        </div>
      </div>
    </div>
  23. Save the file.

  24. Refresh your browser to see the new AccordionContainer layout element as seen in the following screenshot. In this exercise, you learned how to quickly create an application layout using Esri sample layouts.