Retour à la documentation
define([
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/_base/array',
'spw/api/GeometryUtils',
'spw/api/MapService',
'spw/api/DataBaseMapService',
'esri/graphic'
],
function(declare, lang, array, GeometryUtils, MapService, DataBaseMapService, Graphic) {
/**
* @class spw.api.GraphicsMapService
* @classdesc Classe abstraite définissant le traitement des erreurs d'un DataLayer
* @extends {spw.api.MapService}
*/
var GraphicsMapService = declare('spw.api.GraphicsMapService', [DataBaseMapService], /** @lends spw.api.GraphicsMapService.prototype */ {
layerError: function(err) {
if (err.type && err.type === 'loadError') {
if (err.message) {
this.set('errorMessage', err.message);
}
this.set('inError', true);
this.emit(MapService.events.MapServiceError, this, err);
return;
}
console.error(err);
},
identify: function(opts, success, error) {
opts = opts || {};
opts.ignoreFields = opts.ignoreFields || [];
opts.ignoreFields = opts.ignoreFields.concat(this.ignoreAttributes);
opts.tolerance = opts.tolerance || 5;
var identifiableLayers = [];
if (this.layer.visible && this.layer.isVisibleAtScale(this.spwMap.getCurrentScale())) {
identifiableLayers.push(this.layer);
}
var pt = GeometryUtils.buffer(opts.mapPoint, this.getBuffer(opts.mapPoint, opts.tolerance), 'meters', true);
var results = [];
var data = [];
array.forEach(identifiableLayers, lang.hitch(this, function(layer) {
array.forEach(layer.graphics, lang.hitch(this, function(graph) {
if (GeometryUtils.intersects(graph.geometry, pt)) {
var attrs = {};
var feature = new Graphic(graph.toJson()); // clone
for (var key in feature.attributes) {
if (feature.attributes.hasOwnProperty(key)) {
if (opts.ignoreFields && opts.ignoreFields.indexOf(key) > -1) {
continue;
}
attrs[key] = feature.attributes[key];
}
}
results.push({
feature: feature
});
data.push({
layerId: layer.id,
data: attrs
});
}
}));
}));
success(results, this, data);
},
getBuffer: function(point, tolerance) {
var screenPt = this.spwMap.get('esriMap').toScreen(point);
screenPt.x += tolerance;
return Math.abs(this.spwMap.get('esriMap').toMap(screenPt).x - point.x);
}
});
return GraphicsMapService;
});