Skip to content

Commit

Permalink
* Fix jump to Mapget tile id
Browse files Browse the repository at this point in the history
* Fix space characters in mapId and layerId for search menu entry
* Allow using layerName instead of layerId
  • Loading branch information
Waguramu committed Nov 4, 2024
1 parent f68e011 commit 511fd50
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 34 deletions.
2 changes: 1 addition & 1 deletion erdblick_app/app/inspection.panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class InspectionPanelComponent
if (map) {
this.layerMenuItems = Array.from(map.layers.values()).filter(item => item.type == "SourceData").map(item => {
return {
label: SourceDataPanelComponent.layerNameForLayerId(item.layerId),
label: this.inspectionService.layerNameForLayerId(item.layerId),
disabled: item.layerId === selection.layerId,
command: () => {
let sourceData = {...selection};
Expand Down
33 changes: 33 additions & 0 deletions erdblick_app/app/inspection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,39 @@ export class InspectionService {
});
}

/**
* Returns a human-readable layer name for a layer id.
*
* @param layerId Layer id to get the name for
*/
layerNameForLayerId(layerId: string) {
const match = layerId.match(/^SourceData-([^.]+\.)*(.*)-([\d]+)/);
if (match)
return `${match[2]}.${match[3]}`;
return layerId;
}

/**
* Returns an internal layerId for a human-readable layer name.
*
* @param layerId Layer id to get the name for
*/
layerIdForLayerName(layerName: string) {
for (const [_, mapInfo] of this.mapService.maps.getValue().entries()) {
for (const [_, layerInfo] of mapInfo.layers.entries()) {
if (layerInfo.type == "SourceData") {
console.log(layerInfo.layerId, this.layerNameForLayerId(layerInfo.layerId), layerName)
if (this.layerNameForLayerId(layerInfo.layerId) == layerName ||
this.layerNameForLayerId(layerInfo.layerId) == layerName.replace('-', '.') ||
layerInfo.layerId == layerName) {
return layerInfo.layerId;
}
}
}
}
return null;
}

protected readonly InspectionValueType = coreLib.ValueType;
protected readonly GeometryType = coreLib.GeomType;
}
59 changes: 42 additions & 17 deletions erdblick_app/app/jump.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class JumpTargetService {
try {
let wgs84TileId = BigInt(value);
let position = coreLib.getTilePosition(wgs84TileId);
return [position.x, position.y, position.z]
return [position.y, position.x, position.z]
} catch (e) {
this.messageService.showError("Possibly malformed TileId: " + (e as Error).message.toString());
}
Expand All @@ -136,28 +136,38 @@ export class JumpTargetService {
let label = "tileId = ? | (mapId = ?) | (sourceLayerId = ?)";

const matchSourceDataElements = (value: string) => {
const regex = /^\s*(\d+)\s*(?:[,\s;]+)?\s*([^\s,;]*)\s*(?:[,\s;]+)?\s*([^\s,;]*)?\s*$/;
const regex = /^\s*(\d+)\s+(?:"([^"]+)"|([^\s,;"]+(?:\\\s[^\s,;"]+)*))\s+(?:"([^"]+)"|([^\s,;"]+(?:\\\s[^\s,;"]+)*))?\s*$/;
const match = value.match(regex);
let tileId: bigint | null = null;
let mapId = null;
let sourceLayerId = null;
let valid = true;

if (match) {
const [_, bigintStr, str1, str2] = match;
const [_, bigintStr, quoted1, unquoted1, quoted2, unquoted2] = match;
try {
tileId = BigInt(bigintStr);
valid = this.validateMapgetTileId(tileId.toString());
} catch {
valid = false;
}

// TODO: check whether the mapId and layerId are valid
if (str1) {
mapId = str1;
if (quoted1 || unquoted1) {
mapId = (quoted1 ? quoted1 : unquoted1).replace(/\\ /g, ' ');
if (mapId.startsWith('"') || mapId.startsWith("'")) {
mapId = mapId.slice(1, -1);
}
if (mapId.endsWith('"') || mapId.endsWith("'")) {
mapId = mapId.slice(1, -1);
}
}
if (str2) {
sourceLayerId = str2;
if (quoted2 || unquoted2) {
sourceLayerId = (quoted2 ? quoted2 : unquoted2).replace(/\\ /g, ' ');
if (sourceLayerId.startsWith('"') || sourceLayerId.startsWith("'")) {
sourceLayerId = sourceLayerId.slice(1, -1);
}
if (sourceLayerId.endsWith('"') || sourceLayerId.endsWith("'")) {
mapId = sourceLayerId.slice(1, -1);
}
}
} else {
valid = false;
Expand Down Expand Up @@ -199,18 +209,27 @@ export class JumpTargetService {
execute: (value: string) => {
const matches = matchSourceDataElements(value);
if (matches) {
const [tileId, mapId, sourceLayerId] = matches;
let [tileId, mapId, sourceLayerId] = matches;
try {
if (tileId) {
if (mapId) {
mapId = String(mapId);
if (sourceLayerId) {
this.inspectionService.loadSourceDataInspection(
Number(tileId),
String(mapId),
String(sourceLayerId)
)
sourceLayerId = String(sourceLayerId);
if (!sourceLayerId.startsWith("SourceData")) {
sourceLayerId = this.inspectionService.layerIdForLayerName(sourceLayerId);
}
if (sourceLayerId) {
this.inspectionService.loadSourceDataInspection(
Number(tileId),
String(mapId),
sourceLayerId
)
} else {
this.menuService.customTileAndMapId.next([String(tileId), mapId]);
}
} else {
this.menuService.customTileAndMapId.next([String(tileId), String(mapId)]);
this.menuService.customTileAndMapId.next([String(tileId), mapId]);
}
} else {
this.menuService.customTileAndMapId.next([String(tileId), ""]);
Expand All @@ -223,7 +242,13 @@ export class JumpTargetService {
},
validate: (value: string) => {
const matches = matchSourceDataElements(value);
return matches && matches.length && matches[0];
// TODO: check whether the mapId and layerId are valid
if (matches?.length == 3 && matches[2]) {
if (!this.inspectionService.layerIdForLayerName(String(matches[2]))) {
return false;
}
}
return matches && matches.length && matches[0] && this.validateMapgetTileId(matches[0].toString());
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions erdblick_app/app/sourcedata.panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,6 @@ export class SourceDataPanelComponent implements OnInit, AfterViewInit, OnDestro
inspectionContainerHeight: number;
containerSizeSubscription: Subscription;

/**
* Returns a human-readable layer name for a layer id.
*
* @param layerId Layer id to get the name for
*/
public static layerNameForLayerId(layerId: string) {
const match = layerId.match(/^SourceData-([^.]+\.)*(.*)-([\d]+)/);
if (match)
return `${match[2]}.${match[3]}`;
return layerId;
}

constructor(private inspectionService: InspectionService,
public parameterService: ParametersService,
private renderer: Renderer2,
Expand Down
9 changes: 5 additions & 4 deletions erdblick_app/app/sourcedataselection.dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ export class SourceDataLayerSelectionDialogComponent {

*findMapsForTileId(tileId: bigint): Generator<SourceDataDropdownOption> {
const level = coreLib.getTileLevel(tileId);
for (const [mapId, mapInfo] of this.mapService.maps.getValue().entries()) {
for (const [_, mapInfo] of this.mapService.maps.getValue().entries()) {
for (const [_, layerInfo] of mapInfo.layers.entries()) {
if (layerInfo.type == "SourceData") {
if (layerInfo.zoomLevels.includes(level)) {
yield { id: mapId, name: mapId };
yield { id: mapInfo.mapId, name: mapInfo.mapId };
break;
} else {
for (const featureTile of this.mapService.loadedTileLayers.values()) {
if (featureTile.tileId == tileId) {
yield { id: mapId, name: mapId };
yield { id: mapInfo.mapId, name: mapInfo.mapId };
break;
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ export class SourceDataLayerSelectionDialogComponent {
}
return [...dataLayers].map(layerId => ({
id: layerId,
name: SourceDataPanelComponent.layerNameForLayerId(layerId)
name: this.inspectionService.layerNameForLayerId(layerId)
}));
}
return [];
Expand All @@ -254,6 +254,7 @@ export class SourceDataLayerSelectionDialogComponent {
mapId: String(this.selectedMapId.id),
layerId: String(this.selectedSourceDataLayer.id)
});
// TODO: TBR
// const tileId = this.customTileId ? this.customTileId : this.selectedTileId?.id;
// this.inspectionService.loadSourceDataInspection(
// Number(tileId),
Expand Down

0 comments on commit 511fd50

Please sign in to comment.