esri-leaflet
Version:
Leaflet plugins for consuming ArcGIS Online and ArcGIS Server services.
73 lines (62 loc) • 2.1 kB
JavaScript
import L from 'leaflet';
import { Identify } from './Identify';
import Util from '../Util';
export var IdentifyFeatures = Identify.extend({
setters: {
'layers': 'layers',
'precision': 'geometryPrecision',
'tolerance': 'tolerance',
'returnGeometry': 'returnGeometry'
},
params: {
sr: 4326,
layers: 'all',
tolerance: 3,
returnGeometry: true
},
on: function (map) {
var extent = Util.boundsToExtent(map.getBounds());
var size = map.getSize();
this.params.imageDisplay = [size.x, size.y, 96];
this.params.mapExtent = [extent.xmin, extent.ymin, extent.xmax, extent.ymax];
return this;
},
at: function (latlng) {
latlng = L.latLng(latlng);
this.params.geometry = [latlng.lng, latlng.lat];
this.params.geometryType = 'esriGeometryPoint';
return this;
},
layerDef: function (id, where) {
this.params.layerDefs = (this.params.layerDefs) ? this.params.layerDefs + ';' : '';
this.params.layerDefs += ([id, where]).join(':');
return this;
},
simplify: function (map, factor) {
var mapWidth = Math.abs(map.getBounds().getWest() - map.getBounds().getEast());
this.params.maxAllowableOffset = (mapWidth / map.getSize().y) * (1 - factor);
return this;
},
run: function (callback, context) {
return this.request(function (error, response) {
// immediately invoke with an error
if (error) {
callback.call(context, error, undefined, response);
return;
// ok no error lets just assume we have features...
} else {
var featureCollection = Util.responseToFeatureCollection(response);
response.results = response.results.reverse();
for (var i = 0; i < featureCollection.features.length; i++) {
var feature = featureCollection.features[i];
feature.layerId = response.results[i].layerId;
}
callback.call(context, undefined, featureCollection, response);
}
});
}
});
export function identifyFeatures (options) {
return new IdentifyFeatures(options);
}
export default identifyFeatures;