kopia lustrzana https://github.com/FacilMap/facilmap
commit
ca7ba85ea0
|
@ -113,34 +113,6 @@ export interface BboxWithExcept extends Bbox {
|
|||
except?: Bbox;
|
||||
}
|
||||
|
||||
export function makeBboxCondition(bbox: BboxWithExcept | null | undefined, posField = "pos"): WhereOptions {
|
||||
if(!bbox)
|
||||
return { };
|
||||
|
||||
const conditions = [ ];
|
||||
conditions.push(
|
||||
Sequelize.fn(
|
||||
"MBRContains",
|
||||
Sequelize.fn("LINESTRING", Sequelize.fn("POINT", bbox.left, bbox.bottom), Sequelize.fn("POINT", bbox.right, bbox.top)),
|
||||
Sequelize.col(posField)
|
||||
)
|
||||
);
|
||||
|
||||
if(bbox.except) {
|
||||
conditions.push({
|
||||
[Op.not]: Sequelize.fn(
|
||||
"MBRContains",
|
||||
Sequelize.fn("LINESTRING", Sequelize.fn("POINT", bbox.except.left, bbox.except.bottom), Sequelize.fn("POINT", bbox.except.right, bbox.except.top)),
|
||||
Sequelize.col(posField)
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
[Op.and]: conditions
|
||||
};
|
||||
}
|
||||
|
||||
export default class DatabaseHelpers {
|
||||
|
||||
_db: Database;
|
||||
|
@ -280,6 +252,7 @@ export default class DatabaseHelpers {
|
|||
condition.include = [ ...(condition.include ? (Array.isArray(condition.include) ? condition.include : [ condition.include ]) : [ ]), this._db._conn.model(type + "Data") ];
|
||||
}
|
||||
|
||||
|
||||
const Pad = this._db.pads.PadModel.build({ id: padId } satisfies Partial<CreationAttributes<PadModel>> as any);
|
||||
const objs: Array<Model> = await (Pad as any)["get" + this._db._conn.model(type).getTableName()](condition);
|
||||
|
||||
|
@ -397,6 +370,54 @@ export default class DatabaseHelpers {
|
|||
await model.bulkCreate(this._dataToArr(data, idObj));
|
||||
}
|
||||
|
||||
makeBboxCondition(bbox: BboxWithExcept | null | undefined, posField = "pos"): WhereOptions {
|
||||
const dbType = this._db._conn.getDialect()
|
||||
if(!bbox)
|
||||
return { };
|
||||
|
||||
const conditions = [ ];
|
||||
if(dbType == 'postgres') {
|
||||
conditions.push(
|
||||
Sequelize.where(
|
||||
Sequelize.fn("ST_MakeLine", Sequelize.fn("St_Point", bbox.left, bbox.bottom), Sequelize.fn("St_Point", bbox.right, bbox.top)),
|
||||
"~",
|
||||
Sequelize.col(posField))
|
||||
);
|
||||
} else {
|
||||
conditions.push(
|
||||
Sequelize.fn(
|
||||
"MBRContains",
|
||||
Sequelize.fn("LINESTRING", Sequelize.fn("POINT", bbox.left, bbox.bottom), Sequelize.fn("POINT", bbox.right, bbox.top)),
|
||||
Sequelize.col(posField)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(bbox.except) {
|
||||
if(dbType == 'postgres') {
|
||||
conditions.push({
|
||||
[Op.not]: Sequelize.where(
|
||||
Sequelize.fn("St_MakeLine", Sequelize.fn("St_Point", bbox.except.left, bbox.except.bottom), Sequelize.fn("St_Point", bbox.except.right, bbox.except.top)),
|
||||
"~",
|
||||
Sequelize.col(posField)
|
||||
)
|
||||
});
|
||||
} else {
|
||||
conditions.push({
|
||||
[Op.not]: Sequelize.fn(
|
||||
"MBRContains",
|
||||
Sequelize.fn("LINESTRING", Sequelize.fn("POINT", bbox.except.left, bbox.except.bottom), Sequelize.fn("POINT", bbox.except.right, bbox.except.top)),
|
||||
Sequelize.col(posField)
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
[Op.and]: conditions
|
||||
};
|
||||
}
|
||||
|
||||
renameObjectDataField(padId: PadId, typeId: ID, rename: Record<string, { name?: string; values?: Record<string, string> }>, isLine: boolean): Promise<void> {
|
||||
const objectStream = (isLine ? this._db.lines.getPadLinesByType(padId, typeId) : this._db.markers.getPadMarkersByType(padId, typeId)) as Highland.Stream<Marker | Line>;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { CreationAttributes, CreationOptional, DataTypes, ForeignKey, HasManyGetAssociationsMixin, InferAttributes, InferCreationAttributes, Model, Op } from "sequelize";
|
||||
import { BboxWithZoom, ID, Latitude, Line, LineCreate, ExtraInfo, LineUpdate, Longitude, PadId, Point, Route, TrackPoint } from "facilmap-types";
|
||||
import Database from "./database";
|
||||
import { BboxWithExcept, createModel, dataDefinition, DataModel, getDefaultIdType, getLatType, getLonType, getPosType, getVirtualLatType, getVirtualLonType, makeBboxCondition, makeNotNullForeignKey, validateColour } from "./helpers";
|
||||
import { BboxWithExcept, createModel, dataDefinition, DataModel, getDefaultIdType, getLatType, getLonType, getPosType, getVirtualLatType, getVirtualLonType, makeNotNullForeignKey, validateColour } from "./helpers";
|
||||
import { groupBy, isEqual, mapValues, omit } from "lodash";
|
||||
import { wrapAsync } from "../utils/streams";
|
||||
import { calculateRouteForLine } from "../routing/routing";
|
||||
|
@ -279,7 +279,7 @@ export default class DatabaseLines {
|
|||
zoom: { [Op.lte]: bboxWithZoom.zoom },
|
||||
lineId: { [Op.in]: lineIds }
|
||||
},
|
||||
makeBboxCondition(bboxWithZoom)
|
||||
this._db.helpers.makeBboxCondition(bboxWithZoom)
|
||||
]
|
||||
},
|
||||
attributes: ["pos", "lat", "lon", "ele", "zoom", "idx", "lineId"]
|
||||
|
@ -300,4 +300,4 @@ export default class DatabaseLines {
|
|||
return points.map((point) => omit(point.toJSON(), ["pos"]) as TrackPoint);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model } from "sequelize";
|
||||
import { BboxWithZoom, ID, Latitude, Longitude, Marker, MarkerCreate, MarkerUpdate, PadId } from "facilmap-types";
|
||||
import { BboxWithExcept, createModel, dataDefinition, DataModel, getDefaultIdType, getPosType, getVirtualLatType, getVirtualLonType, makeBboxCondition, makeNotNullForeignKey, validateColour } from "./helpers";
|
||||
import { BboxWithExcept, createModel, dataDefinition, DataModel, getDefaultIdType, getPosType, getVirtualLatType, getVirtualLonType, makeNotNullForeignKey, validateColour } from "./helpers";
|
||||
import Database from "./database";
|
||||
import { getElevationForPoint } from "../elevation";
|
||||
import { PadModel } from "./pad";
|
||||
|
@ -69,7 +69,7 @@ export default class DatabaseMarkers {
|
|||
}
|
||||
|
||||
getPadMarkers(padId: PadId, bbox?: BboxWithZoom & BboxWithExcept): Highland.Stream<Marker> {
|
||||
return this._db.helpers._getPadObjects<Marker>("Marker", padId, { where: makeBboxCondition(bbox) });
|
||||
return this._db.helpers._getPadObjects<Marker>("Marker", padId, { where: this._db.helpers.makeBboxCondition(bbox) });
|
||||
}
|
||||
|
||||
getPadMarkersByType(padId: PadId, typeId: ID): Highland.Stream<Marker> {
|
||||
|
@ -125,4 +125,4 @@ export default class DatabaseMarkers {
|
|||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { generateRandomId } from "../utils/utils";
|
|||
import { DataTypes, InferAttributes, InferCreationAttributes, Model, Op, WhereOptions } from "sequelize";
|
||||
import Database from "./database";
|
||||
import { BboxWithZoom, ID, Latitude, Longitude, PadId, Point, Route, RouteMode, TrackPoint } from "facilmap-types";
|
||||
import { BboxWithExcept, createModel, getPosType, getVirtualLatType, getVirtualLonType, makeBboxCondition } from "./helpers";
|
||||
import { BboxWithExcept, createModel, getPosType, getVirtualLatType, getVirtualLonType } from "./helpers";
|
||||
import { calculateRouteForLine } from "../routing/routing";
|
||||
import { omit } from "lodash";
|
||||
import { Point as GeoJsonPoint } from "geojson";
|
||||
|
@ -56,7 +56,7 @@ export default class DatabaseRoutes {
|
|||
routeId,
|
||||
...(!bboxWithZoom ? {} : {
|
||||
[Op.or]: [
|
||||
{ [Op.and]: [ makeBboxCondition(bboxWithZoom), { zoom: { [Op.lte]: bboxWithZoom.zoom } } ] },
|
||||
{ [Op.and]: [ this._db.helpers.makeBboxCondition(bboxWithZoom), { zoom: { [Op.lte]: bboxWithZoom.zoom } } ] },
|
||||
...(!getCompleteBasicRoute ? [] : [
|
||||
{ zoom: { [Op.lte]: 5 } }
|
||||
])
|
||||
|
@ -210,4 +210,4 @@ export default class DatabaseRoutes {
|
|||
return data.map((d) => omit(d.toJSON(), ["pos"]) as TrackPoint);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue