L.esri.MapService

Extends L.esri.Service

L.esri.MapService is an abstraction for interacting with Map Services running on ArcGIS Online and ArcGIS Server that allows you to make requests to the API, as well as query and identify published features.

Constructor

ConstructorDescription
L.esri.mapService(<Object>options)options for configuring the ArcGIS Server or ArcGIS Online map service you would like to consume. Options includes a url parameter which refers to the ArcGIS Server or ArcGIS Online service you would like to consume.

Options

L.esri.MapService accepts all L.esri.Service options.

Events

L.esri.MapService fires all L.esri.service events.

Methods

MethodReturnsDescription
query()this

Returns a new

L.esri.Query

object that can be used to query this service.

mapService.query()
.layer(0)
.within(latlngbounds)
.run(function (error, featureCollection, response) {
    console.log(featureCollection);
});
identify()this

Returns a new

L.esri.IdentifyFeatures

object that can be used to identify features contained within this service.

mapService.identify()
.on(map)
.at(latlng)
.run(function (error, featureCollection, response) {
    console.log(featureCollection)
});
find()this

Returns a new

L.esri.Find

object that can be used to find features by text.

mapService.find()
.layers('18')
.text('Colorado')
.fields('name')
.run(function (error, featureCollection, response) {
    console.log(featureCollection)
});

Examples

Identify task

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var map = new L.Map('map').setView([45.543, -122.621], 5);

var service = L.esri.mapService({
    url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer'
});

service.identify()
    .on(map)
    .at([45.543, -122.621])
    .layers('visible:1')
    .run(function (error, featureCollection, response) {
        if (error) {
        console.log(error);
        return;
        }
        console.log('UTC Offset: ' + featureCollection.features[0].properties.ZONE);
});

Find task

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var service = L.esri.mapService({
    url: 'https://carto.nationalmap.gov/arcgis/rest/services/govunits/MapServer'
});

service.find()
    .layers('18')
    .text('Colorado')
    .searchFields('GNIS_NAME')
    .run(function (error, featureCollection, response) {
        if (error) {
        console.log(error);
        return;
        }
    console.log('Found GNIS ID: ' + featureCollection.features[0].properties.GNIS_ID + ' for the state of ' + featureCollection.features[0].properties.STATE_NAME);
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.