arc-node
v0.4.5
Published
Node module to work with ArcGIS Online and ArcGIS Server
Downloads
14
Readme
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
- Check if a feature service exists
- Create an empty feature service
- Add layers to a feature service
- Add features to a layer
- Find address candidates
- Export a webmap
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
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
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
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
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
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
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
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"));
});