kopia lustrzana https://github.com/FacilMap/facilmap
Only sending points for bbox difference
rodzic
797eede8bc
commit
806a936705
|
@ -104,12 +104,9 @@ function deleteView(viewId, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPadMarkers(padId, bbox) {
|
function getPadMarkers(padId, bbox) {
|
||||||
var bboxCondition = _makeBboxCondition(bbox);
|
var condition = { $and: [ _makeBboxCondition(bbox, "position."), {
|
||||||
var condition = {
|
"_pad" : padId
|
||||||
"_pad" : padId,
|
} ] };
|
||||||
"position.lat" : bboxCondition.lat,
|
|
||||||
"position.lon" : bboxCondition.lon
|
|
||||||
};
|
|
||||||
|
|
||||||
return _fixIdStream(Marker.find(condition).stream());
|
return _fixIdStream(Marker.find(condition).stream());
|
||||||
}
|
}
|
||||||
|
@ -153,13 +150,10 @@ function deleteLine(lineId, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLinePointsByBbox(lineId, bboxWithZoom, callback) {
|
function getLinePointsByBbox(lineId, bboxWithZoom, callback) {
|
||||||
var bboxCondition = _makeBboxCondition(bboxWithZoom);
|
var condition = { $and: [ _makeBboxCondition(bboxWithZoom), {
|
||||||
var condition = {
|
|
||||||
"_line" : lineId,
|
"_line" : lineId,
|
||||||
"zoom" : { $lte: bboxWithZoom.zoom },
|
"zoom" : { $lte: bboxWithZoom.zoom }
|
||||||
"lat" : bboxCondition.lat,
|
} ] };
|
||||||
"lon" : bboxCondition.lon
|
|
||||||
};
|
|
||||||
|
|
||||||
LinePoints.find(condition, "idx zoom", { sort: "idx" }).exec(callback);
|
LinePoints.find(condition, "idx zoom", { sort: "idx" }).exec(callback);
|
||||||
}
|
}
|
||||||
|
@ -209,17 +203,35 @@ function _fixIdStream(stream) {
|
||||||
return utils.filterStream(stream, _fixId);
|
return utils.filterStream(stream, _fixId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _makeBboxCondition(bbox) {
|
function _makeBboxCondition(bbox, prefix) {
|
||||||
var condition = {
|
prefix = prefix || "";
|
||||||
"lat" : { $lte: bbox.top, $gte: bbox.bottom }
|
|
||||||
};
|
function cond(key, value) {
|
||||||
|
var ret = { };
|
||||||
|
ret[prefix+key] = value;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
var conditions = [ ];
|
||||||
|
conditions.push(cond("lat", { $lte: bbox.top, $gte: bbox.bottom }));
|
||||||
|
|
||||||
if(bbox.right < bbox.left) // Bbox spans over lon=180
|
if(bbox.right < bbox.left) // Bbox spans over lon=180
|
||||||
condition["lon"] = { $or: [ { $gte: bbox.left }, { $lte: bbox.right } ] };
|
conditions.push({ $or: [ cond("lon", { $gte: bbox.left }), cond("lon", { $lte: bbox.right }) ] });
|
||||||
else
|
else
|
||||||
condition["lon"] = { $gte: bbox.left, $lte: bbox.right };
|
conditions.push(cond("lon", { $gte: bbox.left, $lte: bbox.right }));
|
||||||
|
|
||||||
return condition;
|
if(bbox.except) {
|
||||||
|
var exceptConditions = [ ];
|
||||||
|
exceptConditions.push({ $or: [ cond("lat", { $gt: bbox.except.top }), cond("lat", { $lt: bbox.except.bottom }) ] });
|
||||||
|
|
||||||
|
if(bbox.except.right < bbox.except.left)
|
||||||
|
exceptConditions.push(cond("lon", { $lt: bbox.except.left, $gt: bbox.except.right }));
|
||||||
|
else
|
||||||
|
exceptConditions.push({ $or: [ cond("lon", { $lt: bbox.except.left }), cond("lon", { $gt: bbox.except.right }) ] });
|
||||||
|
conditions.push({ $or: exceptConditions });
|
||||||
|
}
|
||||||
|
|
||||||
|
return { $and : conditions };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -40,12 +40,14 @@ database.connect(function(err) {
|
||||||
},
|
},
|
||||||
|
|
||||||
updateBbox : function(bbox) {
|
updateBbox : function(bbox) {
|
||||||
|
var bboxWithExcept = utils.extend({ }, bbox);
|
||||||
|
if(socket.bbox && bbox.zoom == socket.bbox.zoom)
|
||||||
|
bboxWithExcept.except = socket.bbox;
|
||||||
|
|
||||||
socket.bbox = bbox;
|
socket.bbox = bbox;
|
||||||
|
|
||||||
// TODO: Only get objects for difference to last bbox
|
_sendStreamData(socket, "marker", database.getPadMarkers(socket.padId, bboxWithExcept));
|
||||||
|
_sendStreamData(socket, "linePoints", database.getLinePoints(socket.padId, bboxWithExcept));
|
||||||
_sendStreamData(socket, "marker", database.getPadMarkers(socket.padId, socket.bbox));
|
|
||||||
_sendStreamData(socket, "linePoints", database.getLinePoints(socket.padId, socket.bbox));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
disconnect : function() {
|
disconnect : function() {
|
||||||
|
|
Ładowanie…
Reference in New Issue