arc-node

0.4.5 • Public • Published

ArcNode

Node module to work with ArcGIS Online and ArcGIS Server.

How to install it

Just write this in your prompt: npm install --save arc-node

And you are ready to go, just instantiate the object like this:

var ArcNode = require('arc-node'),
    service = new ArcNode(<config object>);

Check here the description of the <config object> parameter.

Documentation

When you have instantiate the service you will have available methods to:

Get a new token

Description: Gets a new valid token.
Return: a deferred object. When it's resolved: it returns the ArcGIS REST API response.
Example: See full example

Name getToken(options)
Options
(JSON object)
Name Type Required? Description
client String No The client type that will be granted access to the token. Only the referer value is supported. In the Generate Token page, the referer is specified in the Webapp URL field, for example: referer=http://myserver/mywebapp
referer String No Default value: arcgis.com | The base URL of the client application that will use the token to access the Portal for ArcGIS API. In the Generate Token page, the referer is specified in the Webapp URL field, for example: referer=http://myserver/mywebapp.
expiration Integer No The token expiration time in minutes. The default and maximum is 15 days.

How to use it

//Get a token valid for 60 minutes
service.getToken({
    expiration: 60
}).then(function(response){
    console.log("response: ", response);
});

Check if a feature service exists

Description: Check if a feature service with a given name exists.
Return: a deferred object. When it's resolved: it returns the ArcGIS REST API response.
Example: See full example

Name checkIfFSExists(options?)
Options
(JSON object)
Name Type Required? Description
serviceName String Yes Name of the service

How to use it

service.checkIfFSExists( { serviceName: "Service name" } ).then(function(response){
  console.log("response = ", response);
}, function(e){
  console.log("Error: ", e);
});

Create an empty feature service

Description: it creates a feature service with no layers in it
Return: a deferred object. When it's resolved: it returns the ArcGIS REST API response.
Example: See full example

Name createFeatureService(options?)
Options
(JSON object)
Name Type Required? Description
name String Yes Name of the service

How to use it

service.createFeatureService({name: "My empty feature service"}).then(function(response){
  console.log("response = ", response);
}, function(e){
  console.log("Error: ", e);
});

Add layers to a feature service

Description: it add layers to a service based on the definition of each layer.
Return: a deferred object. When it's resolved: it returns the ArcGIS API REST response.
Example: See full example

Name addLayersToFS(options?)
Options
(JSON object)
Name Type Required? Description
service String Yes URL of the service where the layers is going to be added
layers Array of JSON Objects Yes Array of objects describing the layers (see an example). It can be generated using the createLayer() method

How to use it

service.addLayersToFS({
  service: response.encodedServiceURL,
  layers: [layer]
}).then(function(response){
  console.log("response: ", response);
}, function(e){
  console.log("Error: ", e);
});

Add features to a layer

Description: add features to a feature layer
Return: a deferred object. When it's resolved: it return de ArcGIS API REST response.
Example: See full example

Name addFeatures(options?)
Options
(JSON object)
Name Type Required? Description
serviceName String Yes Service name where the layer is hosted
layer Integer Yes Layer index where the features want to be added
features Array of features Yes Array of features objects

How to use it

var data = [{
    "attributes":{
        "name": "Feature name"
    },
    "geometry": {
        "x": -3,
        "y": 40,
        "spatialReference": {"wkid" : 4326}
    }
  }
  // Add as many features as you want
];
 
service.addFeatures({
    serviceName: "Your service name",
    layer: 0, //<layer index, Ex: 0, 1, 2, ...>
    features: data
}).then(function(response){
    console.log("response = ", response);
},function(e){
    console.log("Error: ", e);
});

Find address candidates

Description: find xy locations for an address
Return: a deferred object. When it's resolved: it return de ArcGIS API REST response.
Example: See full example

Name findAddressCandidates(options?)
Options
(JSON object)
Name Type Required? Description
address String Yes The address

How to use it

service.findAddressCandidates({
    address: "Emilio muñoz 35, madrid"
}).then(function(response){
    console.log("response: ", JSON.stringify(response, null, "\t"));
});

Export a webmap

Description: generate a static image from a webmap object Return: a deferred object. When it's resolved: it return de ArcGIS API REST response.
Example: See full example

Name ExportWebMapTask(options?)
Options
(JSON object)
Name Type Required? Description
webmap JSON Object Yes A webmap object

How to use it

var webmap = ArcJSON.exportableWebmap({
    "mapOptions": {
        "extent": {
            "xmin": -422228.3214312691,
            "ymin": 4921137.768125086,
            "xmax": -396125.07627191657,
            "ymax": 4928896.126496022
        }
    },
    "operationalLayers": [
        {
            "opacity": 1,
            "url": "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
        }
    ],
    "exportOptions": {
        "outputSize": [
            600,
            300
        ],
        "dpi": 192
    }
});
 
service.ExportWebMapTask({
    webmap: webmap
}).then(function(response){
    console.log("response: ", JSON.stringify(response, null, "\t"));
});

Package Sidebar

Install

npm i arc-node

Weekly Downloads

3

Version

0.4.5

License

AGPL-3.0

Unpacked Size

77.9 kB

Total Files

6

Last publish

Collaborators

  • esries