forked from MapComplete/MapComplete
Mapillary bugfix
This commit is contained in:
parent
895aa132ec
commit
ab2e9425c2
5 changed files with 114 additions and 111 deletions
|
@ -130,7 +130,12 @@ export class ImageSearcher extends UIEventSource<{key: string, url: string}[]> {
|
|||
}
|
||||
|
||||
if (this._tags.data.mapillary) {
|
||||
this.AddImage(undefined,"https://www.mapillary.com/map/im/" + this._tags.data.mapillary)
|
||||
let mapillary = this._tags.data.mapillary;
|
||||
const prefix = "https://www.mapillary.com/map/im/";
|
||||
if(mapillary.indexOf(prefix) < 0){
|
||||
mapillary = prefix + mapillary;
|
||||
}
|
||||
this.AddImage(undefined, mapillary)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
132
Logic/Tags.ts
132
Logic/Tags.ts
|
@ -1,4 +1,6 @@
|
|||
import {Utils} from "../Utils";
|
||||
import {Util} from "leaflet";
|
||||
import indexOf = Util.indexOf;
|
||||
|
||||
export abstract class TagsFilter {
|
||||
abstract matches(tags: { k: string, v: string }[]): boolean
|
||||
|
@ -344,20 +346,31 @@ export class TagUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Given multiple tagsfilters which can be used as answer, will take the tags with the same keys together as set.
|
||||
* E.g:
|
||||
*
|
||||
* FlattenMultiAnswer([and: [ "x=a", "y=0;1"], and: ["x=b", "y=2"], and: ["x=", "y=3"]])
|
||||
* will result in
|
||||
* ["x=a;b", "y=0;1;2;3"]
|
||||
*
|
||||
* Given two hashes of {key --> values[]}, makes sure that every neededTag is present in availableTags
|
||||
*/
|
||||
static AllKeysAreContained(availableTags: any, neededTags: any){
|
||||
for (const neededKey in neededTags) {
|
||||
const availableValues : string[] = availableTags[neededKey]
|
||||
if(availableValues === undefined){
|
||||
return false;
|
||||
}
|
||||
const neededValues : string[] = neededTags[neededKey];
|
||||
for (const neededValue of neededValues) {
|
||||
if(indexOf(availableValues, neededValue) < 0){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/***
|
||||
* Creates a hash {key --> [values]}, with all the values present in the tagsfilter
|
||||
*
|
||||
* @param tagsFilters
|
||||
* @constructor
|
||||
*/
|
||||
static FlattenMultiAnswer(tagsFilters: TagsFilter[]): And {
|
||||
if (tagsFilters === undefined) {
|
||||
return new And([]);
|
||||
}
|
||||
static SplitKeys(tagsFilters: TagsFilter[]){
|
||||
const keyValues = {} // Map string -> string[]
|
||||
tagsFilters = [...tagsFilters] // copy all
|
||||
while (tagsFilters.length > 0) {
|
||||
|
@ -384,91 +397,30 @@ export class TagUtils {
|
|||
console.error("Invalid type to flatten the multiAnswer", tagsFilter);
|
||||
throw "Invalid type to FlattenMultiAnswer"
|
||||
}
|
||||
return keyValues;
|
||||
}
|
||||
/**
|
||||
* Given multiple tagsfilters which can be used as answer, will take the tags with the same keys together as set.
|
||||
* E.g:
|
||||
*
|
||||
* FlattenMultiAnswer([and: [ "x=a", "y=0;1"], and: ["x=b", "y=2"], and: ["x=", "y=3"]])
|
||||
* will result in
|
||||
* ["x=a;b", "y=0;1;2;3"]
|
||||
*
|
||||
* @param tagsFilters
|
||||
* @constructor
|
||||
*/
|
||||
static FlattenMultiAnswer(tagsFilters: TagsFilter[]): And {
|
||||
if (tagsFilters === undefined) {
|
||||
return new And([]);
|
||||
}
|
||||
|
||||
let keyValues = TagUtils.SplitKeys(tagsFilters);
|
||||
const and: TagsFilter[] = []
|
||||
for (const key in keyValues) {
|
||||
and.push(new Tag(key, Utils.Dedup(keyValues[key]).join(";")));
|
||||
}
|
||||
return new And(and);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the actualTags onto a list of which the values are the same as the tagsFilters.
|
||||
* Leftovers are returned in the list too if there is an 'undefined' value
|
||||
*/
|
||||
static SplitMultiAnswer(actualTags: TagsFilter, possibleTags: TagsFilter[], freeformKey: string, freeformExtraTags: TagsFilter): TagsFilter[] {
|
||||
|
||||
const queue: TagsFilter[] = [actualTags]
|
||||
|
||||
const keyValues = {} // key ==> value[]
|
||||
|
||||
while (queue.length > 0) {
|
||||
const tf = queue.pop();
|
||||
if (tf instanceof And) {
|
||||
queue.push(...tf.and);
|
||||
continue;
|
||||
}
|
||||
if (tf instanceof Tag) {
|
||||
if (keyValues[tf.key] === undefined) {
|
||||
keyValues[tf.key] = []
|
||||
}
|
||||
keyValues[tf.key].push(...tf.value.split(";"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tf === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
throw "Invalid tagfilter: " + JSON.stringify(tf)
|
||||
}
|
||||
|
||||
const foundValues = [];
|
||||
for (const possibleTag of possibleTags) {
|
||||
if (possibleTag === undefined) {
|
||||
continue;
|
||||
}
|
||||
if (possibleTag instanceof Tag) {
|
||||
const key = possibleTag.key;
|
||||
const actualValues: string[] = keyValues[key] ?? [];
|
||||
const possibleValues = possibleTag.value.split(";");
|
||||
|
||||
let allPossibleValuesFound = true;
|
||||
for (const possibleValue of possibleValues) {
|
||||
if (actualValues.indexOf(possibleValue) < 0) {
|
||||
allPossibleValuesFound = false;
|
||||
}
|
||||
}
|
||||
if (!allPossibleValuesFound) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// At this point, we know that 'possibleTag' is completely present in the tagset
|
||||
// we add the possibleTag to the found values
|
||||
foundValues.push(possibleTag);
|
||||
|
||||
for (const possibleValue of possibleValues) {
|
||||
actualValues.splice(actualValues.indexOf(possibleValue), 1);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
throw "Unsupported possibletag: " + JSON.stringify(possibleTag);
|
||||
}
|
||||
|
||||
let leftoverTag = undefined;
|
||||
if (keyValues[freeformKey] !== undefined && keyValues[freeformKey].length !== 0) {
|
||||
leftoverTag = new Tag(freeformKey, keyValues[freeformKey].join(";"));
|
||||
if (freeformExtraTags !== undefined) {
|
||||
leftoverTag = new And([
|
||||
leftoverTag,
|
||||
freeformExtraTags
|
||||
])
|
||||
}
|
||||
foundValues.push(leftoverTag);
|
||||
}
|
||||
|
||||
return foundValues;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue