maptoolkit
Version:
Utilidades para trabajar con el mapa de google web.
142 lines • 5.21 kB
JavaScript
import * as Collections from 'typescript-collections';
var MtMarkerGroupCollection = (function () {
function MtMarkerGroupCollection() {
this._defGroup = "defaultGroup";
this._markersDic = new Collections.Dictionary();
}
Object.defineProperty(MtMarkerGroupCollection.prototype, "defaultGroup", {
get: function () {
return this._defGroup;
},
enumerable: true,
configurable: true
});
MtMarkerGroupCollection.prototype.addMarker = function (marker, group) {
if (group === void 0) { group = this._defGroup; }
this.addAllMarkers([marker], group);
return this;
};
/**
* Adiciona los markers que no existen en la coleccion y retorna los markers adicionados.
* @param markers
* @param group
* @return MtMarker[]
*/
MtMarkerGroupCollection.prototype.addAllMarkers = function (markers, group) {
if (group === void 0) { group = this._defGroup; }
if (markers) {
var added = [];
var groupDict = this._ensureGroup(group);
markers.forEach(function (mk) {
if (mk != void 0 && !groupDict.containsKey(mk.getId())) {
groupDict.setValue(mk.getId(), mk);
added.push(mk);
}
});
return added;
}
};
MtMarkerGroupCollection.prototype.removeMarkerById = function (id, group) {
if (group === void 0) { group = this._defGroup; }
if (this._markersDic.containsKey(group)) {
return this._markersDic.getValue(group).remove(id);
}
};
MtMarkerGroupCollection.prototype.removeMarker = function (marker, group) {
return this.removeMarkerById(marker.getId(), group);
};
MtMarkerGroupCollection.prototype.removeMarkers = function (markers, group) {
if (markers) {
var ids = markers.map(function (mk) {
return mk.getId();
});
return this.removeMarkersById(ids, group);
}
return [];
};
MtMarkerGroupCollection.prototype.removeMarkersById = function (ids, group) {
var _this = this;
if (group === void 0) { group = this._defGroup; }
if (!ids || !(ids instanceof Array)) {
throw Error("removeMarkersById: The first argument must be an array with the marker ids.");
}
var removed = [];
ids.forEach(function (id) {
removed.push(_this.removeMarkerById(id, group));
});
return removed;
};
MtMarkerGroupCollection.prototype.removeGroup = function (group) {
if (!group || typeof group != 'string') {
throw new Error("removeGroup: The group argument must be an string.");
}
var resp;
if (this.getGroup(group)) {
resp = this.getGroup(group).values();
this.getGroup(group).clear();
}
else {
resp = [];
}
return resp;
};
MtMarkerGroupCollection.prototype.clear = function () {
this._markersDic.clear();
};
MtMarkerGroupCollection.prototype.getMarker = function (id, group) {
if (group != void 0) {
if (this._markersDic.getValue(group) != void 0) {
return this._markersDic.getValue(group).getValue(id);
}
}
else {
var dicts = this._markersDic.values();
for (var i = 0; i < dicts.length; i++) {
var d = dicts[i];
if (d.containsKey(id)) {
return d.getValue(id);
}
}
}
};
MtMarkerGroupCollection.prototype.getCount = function (group) {
if (group != void 0) {
if (!this._markersDic.containsKey(group))
throw new Error("The marker group " + group + "doesn't exist.");
return this._markersDic.size();
}
else {
return this._markersDic.values().reduce(function (sum, dic) {
return sum + dic.size();
}, 0);
}
};
MtMarkerGroupCollection.prototype.getGroup = function (group) {
if (group === void 0) { group = this._defGroup; }
return this._ensureGroup(group);
};
MtMarkerGroupCollection.prototype.contains = function (id) {
var groups = this._markersDic.values();
for (var i = 0; i < groups.length; i++) {
var g = groups[i];
if (g.containsKey(id)) {
return true;
}
}
return false;
};
MtMarkerGroupCollection.prototype.toArray = function () {
return this._markersDic.values().reduce(function (acum, current) {
return acum.concat(current.values());
}, []);
};
MtMarkerGroupCollection.prototype._ensureGroup = function (group) {
if (!this._markersDic.getValue(group)) {
this._markersDic.setValue(group, new Collections.Dictionary());
}
return this._markersDic.getValue(group);
};
return MtMarkerGroupCollection;
}());
export { MtMarkerGroupCollection };
//# sourceMappingURL=mkcollection.js.map