cwhite911 / angular-arcgis-server

AngularJS utility for ArcGIS Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

angular-arcgis-server

Utility for ArcGIS Server 10.2.2

Purpose

Angular-arcgis-server module is designed to provide an easier way to interact with ArcGIS server by using descriptive layer names to make requests to the server. This provides a more robust foundation for an application when a services layer ids are subject to change from changes on the server. The module also provides easy conversion from ESRI JSON to GeoJSON.

Install

Add via bower

  bower install angular-arcgis-server -S

Add script to html

  <script src="bower_components/angular-arcgis-server/dist/angular-arcgis-server.js"></script>

Usage

Inject module and add factory to controller

angular.module('app', ['agsserver']).
controller('test', [ 'AgsService', function(AgsService){}]);

API

Create server

AgsService(options)

Returns new server object

Options (object)

Parameter Details Type Required Default
host Host where server is located String true null
protocol Protocol to be used String false 'http'
path Path to server String false '/arcgis/rest/services'

Example

Create ArcGIS server object

//Create new server object

var testServer = new AgsService({'protocol': <string>, 'host': <string>, 'path': <string> });

Methods

getConn()

Returns a Server connection url.

Example

Get connection url

testServer.getConn();

resetConn(options)

Return Server object with new connection parameters

Options (object)

Parameter Details Type Required Default
host Host where server is located String true null
protocol Protocol to be used String false 'http'
path Path to server String false '/arcgis/rest/services'

Example

Reset connection parameters

testServer.resetConn({'protocol': <string>, 'host': <string>, 'path': <string> });

setService(options)

Returns a Server object set to make requests on a specified service.

Options (object)

Parameter Details Type Required Default
folder Name of folder String true null
service Name of service String true null
server Type of server
  • 'FeatureServer'
  • 'MapServer'
  • 'GPServer'
String true 'FeatureServer'

Example

Define options

//Setup options

var options = {
  folder: <folder>,
  service: <service>,
  server: 'FeatureServer',
};

Make request to server

//Set service

var myFeatureService = testServer.setService(options);

request(options)

Makes request to server and returns promise, a specific service can be set using the setService method or by including the folder, service and server in the option parameter.

Parameters

Options (object)

Parameter Details Type Required Default
folder Name of folder String false null
service Name of service String false null
server Type of server
  • 'FeatureServer'
  • 'MapServer'
  • 'GPServer'
String false 'FeatureServer'
layer Name of layer String false If layer is not set it is assumed that action find, identify, or export is being used see [example 3]
actions The type of request sent to the server
  • 'query'
  • 'applyEdits'
  • 'addFeatures'
  • 'updateFeatures'
  • 'deleteFeatures'
  • 'generateRenderer'
  • 'identify'
  • 'find'
  • 'export'
String true 'query'
params Parameters matching setting defined in ArcGIS Server 10.2.2 REST API Object true null
geojson Controls whether or not to return response as geojson Boolean false false
timeout Set timeout Number false 5000
header Set request header Object false {'Content-Type': 'text/plain'}

Example 1

Define options with no service set

//Setup request options
var options = {
  folder: <folder>,
  service: <service>,
  server: 'FeatureServer',
  layer: <layer>,
  geojson: true,
  actions: 'query'
  params: {
    f: 'json',
    where: 'OBJECTID > 0'
  }
};

Make request to server

//Make request to Server

testServer.request(options)
.then(function(data){
  //Do something
});

Example 2

Create service

//Setup setService options

var options = {
  folder: <folder>,
  service: <service>,
  server: 'FeatureServer',
};

//Create service object

var myFeatureService = testServer.setService(options);

Make request to server

//Setup request options

var options = {
  layer: <layer>,
  geojson: true,
  actions: 'query'
  params: {
    f: 'json',
    where: 'OBJECTID > 0'
  }
};

//Make request

myFeatureService.request(options)
  .then(function(data){
    //Do something
  });

Example 3

Use Find action on a mapServer

Note
In params.layers use layer names, layer ids or mixed

Yes- params.layers = 'buildings, roads, addresses';

Yes - params.layers = '0,1,2';

Yes - params.layers = 'buildings, 1, addresses';

//Setup setService options

var options = {
  folder: <folder>,
  service: <service>,
  server: 'MapServer',
};

//Create service object

var myFeatureService = testServer.setService(options);

Make request to server

//Setup request options

var options3 = {
  params: {
    f: 'json',
    searchText: 'Main St',
    searchFields: 'street_address',
    layers: '0, roads, 2', //Use layer names or layer ids
    sr: 4326
  },
  actions: 'find',
  geojson: true
};

//Make request

myFeatureService.request(options)
.then(function(data){
  //Do something
});

(type, options)

Makes request to ArcGIS server geometry utilities, takes a single options object as parameter.
Types Options (object)
Areas and Lengths Source Info
Auto Complete Source Info
Buffer Source Info
Convex Hull Source Info
Cut Source Info
Densify Source Info
Difference Source Info
Distance Source Info
Generalize Source Info
Intersect Source Info
Label Points Source Info
Lengths Source Info
Offset Source Info
Project Source Info
Relation Source Info
Reshape Source Info
Simplify Source Info
Trim Extend Source Info
Union Source Info

Example

Project data from SRID 4326 to SRID 102100

//Set options
var projectOptions = {
  f: 'json',
  geometries: {
    geometryType: 'esriGeometryPoint',
    geometries: [ {"x": -76.9346809387207 , "y": 38.1779196445415 }]
  },
  inSR: 4326,
  outSR: 102100
};

//Make request
testServer.('project', projectOptions)
.then(function(data){
  //Do something
});

requestToken(options)

Returns object containing token and expiration.

Options (object)

Parameter Details Type Required Default
username Username String true null
password password String true null
expiration The token expiration time in minutes. The default is 60 minutes. The maximum expiration period is 15 days. Number false 60
f Response format String false 'json'

Additional options found at More Options

Example

Define options

//Setup options

var options = {
  username: <user>,
  password: <password>,
};

Make request to server

//Set service

testServer.requestToken(options)
  .then(function (token) {
    //Do something
  });

Directives

agsLoginForm

<ags-login-form server=""></ags-login-form>

Options (object)

Parameter Details Type Required Default
server Server Object Object true null
Basic Version

alt tag

Bootstrap Version (Modal)

alt tag

Contribute

Contributions are welcomed! Please just fork and submit a pull request. Thanks!

Build & development

Run gulp for preview and gulp build for build.

Testing

Running gulp test will run the unit tests with karma.

About

AngularJS utility for ArcGIS Server


Languages

Language:JavaScript 66.2%Language:HTML 33.5%Language:CSS 0.3%