kartevonmorgen / kartevonmorgen.ts

Mapping-Frontend to find and add sustainable Organisations (Initiatives, Companies) and Events on Kartevonmorgen.org / MapofTomorrow.org
https://kartevonmorgen.org/
GNU General Public License v3.0
11 stars 12 forks source link

Redirections from old #filtered maps don't work #201

Closed wellemut closed 5 months ago

wellemut commented 7 months ago

Describe the bug Many Networks are using our maps in their webpages with an old iframe, like https://www.transition-initiativen.org/liste-der-transition-initiativen. But behind their iframes they use the old tag-filters with # in searchbar: https://www.kartevonmorgen.org/#/?center=51.007,6.996&zoom=5.83&search=%23transitiontown grafik

-> Problem: The part &search=%23transitiontown is completly lost!

grafik

To Reproduce Steps to reproduce the behavior:

  1. Go to https://www.transition-initiativen.org/liste-der-transition-initiativen and check the map, you should find only transitiontowns, but you finde everything
  2. Click on the link below the map Große Karte öffnen(link is external)
  3. Check, if there is any filter for "transitiontwon" acitivated.
  4. Your see this url attribute is completly lost.

Expected behavior The URL command &search=%23 or &search=# should be redirected to &tag= or at least &search=%23

So https://www.kartevonmorgen.org/#/?center=51.007,6.996&zoom=5.83&search=%23transitiontown should become

@navid-kalaei is this redirection a question of map-app or @alex0107 is this a configuration in the hosting?

Screenshots Old Version: https://v0.kartevonmorgen.org/#/?center=51.392,9.141&zoom=6.00&search=%23transitiontown&dropdowns=kvm grafik

New Verson: https://www.kartevonmorgen.org/m/main?c=51.0070%2C6.9960&z=5.83&tag=transitiontown grafik

Additional context Previous issue on this problem: https://github.com/kartevonmorgen/kartevonmorgen.ts/issues/94

wellemut commented 5 months ago

@alex0107 damit so ein link wieder funktioniert: https://kartevonmorgen.org/#/?entry=414e91009f3f4bc2813323dedb718756

Musst du da was einstellen oder muss Navid etwas programmieren? Ich meine, mit der Landingpage von Navid hatten die redirects eigentlich funktioniert. Richtige weiterleitungsziel wäre https://www.kartevonmorgen.org/m/main/e/414e91009f3f4bc2813323dedb718756

alex0107 commented 5 months ago

Das ist jetzt auf der Website hinterlegt. Das sollte eigentlich alles oder zumindest das meiste abdecken....wenn was fehlt einfach melden

if (window.location.href.indexOf("/#/") > -1) {
    var path = window.location.hash;

    const startCharsToRemove = `#/?`;
    let numberOfCharsToDrop = 0;
    for (numberOfCharsToDrop; numberOfCharsToDrop !== startCharsToRemove.length; numberOfCharsToDrop++) {
        if (startCharsToRemove[numberOfCharsToDrop] !== path[numberOfCharsToDrop]) {
            break;
        }
    }
    const trimmedPath = path.substring(numberOfCharsToDrop);

    const params = new Proxy(new URLSearchParams(trimmedPath), {
        get: (searchParams, prop) => searchParams.get(prop),
    });

    // entry
    // center
    // zoom
    // search
    // dropdowns

    let newpath = '/m/' + (params.dropdowns ? params.dropdowns : 'main');

    if (params.zoom)
        params.zoom = params.zoom.replaceAll(",", " ");

    if (params.entry) {
        newpath += '/e/' + params.entry;
        if (params.center)
            newpath += '?c=' + params.center;
        if (params.zoom)
            newpath += '&z=' + params.zoom;
    } else {
        newpath += '?c=' + params.center + '&z=' + params.zoom;
    }

    if (params.search) {
        const [newSearch, tagsFromSearchInput] = extractTagsFromSearchQuery(params.search);
        if (tagsFromSearchInput)
            newpath += '&search=' + encodeURIComponent(newSearch) + '&tag=' + tagsFromSearchInput;
        else
            newpath += '&search=' + encodeURIComponent(newSearch);

    }

    if (params.left) {
        if (params.left == "hide")
            newpath += '&sidebar=hidden';
    }

    let url = "https://www.kartevonmorgen.org" + newpath;
    console.log(url);

    window.location.href = url;
}

function extractTagsFromSearchQuery(search) {
    if (!search) {
        return [search, []];
    }

    var tokens = search.split(' ');
    var tags = [];
    var newSearch = '';
    for (var i = 0; i < tokens.length; i++) {
        var token = tokens[i];
        if (token.startsWith('#')) {
            tags.push(token.substring(1));
        } else {
            newSearch = newSearch + ' ' + token;
        }
    }

    newSearch = newSearch.trim();

    return [newSearch, tags];
}
wellemut commented 5 months ago

perfekt @alex0107 ich glaube jetzt funktioniert wieder alles!