sebastianpauli / netgis-client

WebGIS-Client in development for NetGIS / Geoportal RLP.
MIT License
4 stars 0 forks source link

Externe config.json wird nicht mehr gelesen #31

Closed Rastopapola closed 2 weeks ago

Rastopapola commented 2 weeks ago

Status quo

Die demo enthält eine var config, die gleich im JS die notwendigen Konfigurationen definiert und entsprechend richtig eingelesen wird.

Bug

In der alten Version war es möglich die Konfiguration in eine config.json auszulagern, deren Pfad an den Constructor übergeben werden konnte:

var client = new netgis.Client( "container", "path/to/config.json" );

Dieses Feature scheint bei den Refactorarbeiten hops gegangen zu sein. Ich vermute es handelte sich in der alten Version um folgenden Code (unminified; Z.259-281):

netgis.Client = function (a, b) {
    this.build = "20220826";
    this.debug = !1;
    netgis.util.isString(a) && (a = document.getElementById(a));
    this.container = a;
    this.editable = !0;
    this.root = null;
    this.modules = [];
    this.callbacks = {};
    this.config = this.createDefaultConfig();
    this.create();
    if (netgis.util.isDefined(b))
        if (netgis.util.isString(b)) {
            var c = this;
            netgis.util.request(b, function (a) {
                a = JSON.parse(a);
                netgis.util.merge(c.config, a);
                c.applyConfig(c.config);
            });
        } else netgis.util.merge(this.config, b), this.applyConfig(this.config);
    else this.applyConfig(this.config);
    this.hideLoader();
};

Hier wurde meinem Verständnis nach ein angegebener Pfad noch evaluiert, der Inhalt ausgelesen und in die interne this.config Variable übernommen.

Lasse ich mir aber in der neuen Version this.config ausgeben, sehe ich lediglich den Pfad:

grafik

Hier ein Screenshot aus der alten Version:

grafik

sebastianpauli commented 2 weeks ago

Should be fixed in latest commit.

The second parameter to the Client constructor now accepts the URL to a Config JSON again.

Example:

// Create Client With Config URL
var client = new netgis.Client( "container", "../data/test_config_lanis.json" );
Rastopapola commented 1 week ago

Bestätige: Pfad wird wieder korrekt ausgelesen! :)

Rastopapola commented 9 hours ago

Just had now time to get back to this project. After the latest fetch of the code, the config.json is not read properly (again?).

I was able to trace this down as far as:

  1. Detected error on console : Uncaught TypeError: this.config.tools is undefined --> seems there is no tools attribute?
  2. Took a look on what is being processed as this.config --> seems to be just the path to the config file /static/config.json
  3. Traced back through the code to find out that
    1. line 365 following: onConfigResponse: Properly reads fetched JSON (works so far) and calls this.init(this.container, parsed_json) where parsed_json still is what one might expect it to be
    2. Client.init calls Client.initConfig using the properly parsed json
    3. initConfig seems to process the parsed json but does not set it as this.config for further global referencing?

So, what we have there is currently


netgis.Client.prototype.initConfig = function (a) {
    a.wmc && a.wmc.url && this.requestContextWMC(a.wmc.url, a.wmc.id);
    a.ows && a.ows.url && this.requestContextOWS(a.ows.url);
    };

But should there not be something like

    ...
    this.config = a;
    ...

in there? Otherwise all tries to process this.config later will fail.