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

Basic CSS principles


Cascading Style Sheets (CSS) is a language used to describe how HTML elements should be displayed on a web page. For instance, CSS is often used to define common styling elements for a page or set of pages, such as the font, background color, font size, link colors, and many other things related to the visual design of a web page. Take a look at the following code snippet:

<style>
  html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
  }
  
  #map{
    
    padding:0;
    border:solid 2px #94C7BA;
    margin:5px;
  }
  #header {
    border: solid 2px #94C7BA;
    padding-top:5px;
    padding-left:10px;
    background-color:white;
    
    color:#594735;
    
    font-size:14pt;
    text-align:left;
    font-weight:bold;
    height:35px;
    margin:5px;
    overflow:hidden;
  }
  .roundedCorners{
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
  }
  .shadow{
    
    -webkit-box-shadow: 0px 4px 8px #adadad;
    -moz-box-shadow: 0px 4px 8px #adadad;
    -o-box-shadow: 0px 4px 8px #adadad;
    box-shadow: 0px 4px 8px #adadad;
  }
</style>

CSS syntax

CSS follows certain rules that define what HTML element to select along with defining how that element should be styled. A CSS rule has two main parts: a selector and one or more declarations. The selector is typically the HTML element that you want to style. In the following diagram, the selector is p. A <p> element in HTML represents a paragraph. The second part of a CSS rule comprises of one or more declarations, each of which consists of a property and a value. The property represents the style attribute that you want to change. In our example, we are setting the color property to red. In effect, what we have done with this CSS rule is define that all the text within our paragraph should be in red.

We have used p {color:red}, as shown in the following diagram:

You can include more than one declaration in a CSS rule as you see in the following example. A declaration is always surrounded by curly brackets and each declaration ends with a semicolon. In addition, a colon should be placed between the property and the value. In this particular example, two declarations have been made: one for the color of the paragraph and another for the text alignment of the paragraph. Notice that the declarations are separated by a semicolon:

p {color:red;text-align:center}

CSS comments are used to explain your code. You should get into the habit of always commenting on your CSS code just as you would in any other programming language. Comments are always ignored by the browser. Comments begin with a slash followed by an asterisk and end with an asterisk followed by a slash. Everything in between is assumed to be a comment and is ignored:

/*
h1 {font-size:200%;}
h2 {font-size:140%;}
h3 {font-size:110%;}
*/

In addition to specifying selectors for specific HTML elements, you can also use the id selector to define styles for any HTML elements with an id value that matches the id selector. An id selector is defined in CSS through the use of the pound sign (#), followed by an id value.

For instance, in the following code example, you see three id selectors: rightPane, leftPane, and map. In ArcGIS API for JavaScript applications, you almost always have a map. When you define a <div> tag that will serve as the container for the map, you define an id selector and assign it a value that is often the word map. In this case, we are using CSS to define several styles for our map, including a margin of 5 pixels along with a solid styled border of a specific color and a border radius:

#rightPane {
    background-color:white;
    color:#3f3f3f;
    border: solid 2px #224a54;
    width: 20%;
}
#leftPane {
    margin: 5px;
    padding: 2px;
    background-color:white;
    color:#3f3f3f;
    border: solid 2px #224a54;
    width: 20%;
}
#map {
    margin: 5px;
    border: solid 4px #224a54;
    -mox-border-radius: 4px;
}

Unlike id selectors that are used to assign styles to a single element, the class selectors are used to specify styles for a group of elements, all of which have the same HTML class attribute. A class selector is defined with a period, followed by the class name. You may also specify that only specific HTML elements with a particular class should be affected by the style. Examples of both are shown in the following code example:

.center {text-align:center;}
p.center {text-align:center;}

Your HTML code would then reference the class selector as follows:

<p class="center">This is a paragraph</p>

There are three ways to insert CSS into your application: inline, internal stylesheets, and external stylesheets.

Inline styling

The first method of defining CSS rules for your HTML elements is through the use of inline styles. This method is not recommended because it mixes style with presentation and is difficult to maintain. It is an option in some cases where you need to define a very limited set of CSS rules. To use inline styles, simply place the style attribute inside the relevant HTML tag:

<p style="color:sienna;margin-left:20px">This is a paragraph.</p>

Internal stylesheets

An internal stylesheet moves all the CSS rules into a specific web page. Only HTML elements within that particular page have access to the rules. All CSS rules are defined inside the <head> tag and are enclosed inside a <style> tag, as seen in the following code example:

<head>
    <style type="text/css">
        hr {color:sienna;}
        p {margin-left:20px;}
        body {background-image:url("images/back40.gif");}
    </style>
</head>

External stylesheets

An external stylesheet is simply a text file containing CSS rules and is saved with a .css file extension. This file is then linked to all web pages that want to implement the styles defined within the external stylesheet through the use of the HTML <link> tag. This is a commonly used method to split the styling from the main web page and gives you the ability to change the look of an entire website through the use of a single external stylesheet.

Now let's put some emphasis on the cascading part of cascading stylesheets. As you now know, styles can be defined in external stylesheets, internal stylesheets, or inline. There is a fourth level that we didn't discuss, which is the browser default. You don't have any control over that though. In CSS, an inline style has the highest priority, which means that it will override a style defined in an internal stylesheet, an external stylesheet, or the browser default. If an inline style is not defined, any style rule defined in an internal stylesheet would take precedence over styles defined in an external stylesheet. The caveat here is that if a link to an external stylesheet is placed after the internal stylesheet in HTML <head>, the external stylesheet will override the internal sheet!

That's a lot to remember! Just keep in mind that style rules defined further down the hierarchy override style rules defined higher in the hierarchy, as shown in the following diagram:

These are the basic concepts that you need to understand with regard to CSS. You can use CSS to define styles for pretty much anything on a web page, including backgrounds, text, fonts, links, lists, images, tables, maps, and any other visible objects.