systemapic / systemapic.js

Systemapic Javascript API
https://systemapic.com
0 stars 3 forks source link

Update Style stops retriving tiles #59

Closed strk closed 8 years ago

strk commented 8 years ago

Continues from https://github.com/systemapic/pile/issues/13

After clicking on "Update Style" all my data tiles disappear and no further tiles are loaded, even on navigating the map.

It might be related, I see a POST going to: https://localhost/api/error/log -- the payload is an absurd JSON with an array with a letter of the message in each element.

"{\"message\":\"Error: No value provided for variable {layerUuid}\",\"file\":\"https://localhost/js/lib
/leaflet.js/leaflet-0.7.3-src.js\",\"line\":141,\"user\":\"Sandro Santilli\",\"stack\":\"L.Util.template
/<@https://localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:141:11\\nL.Util.template@https://localhost
/js/lib/leaflet.js/leaflet-0.7.3-src.js:138:1\\nL.TileLayer<.getTileUrl@https://localhost/js/lib/leaflet
.js/leaflet-0.7.3-src.js:2898:1\\nL.TileLayer<._loadTile@https://localhost/js/lib/leaflet.js/leaflet-0
.7.3-src.js:2972:18\\nL.TileLayer<._addTile@https://localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js
:2866:3\\nL.TileLayer<._addTilesFromCenterOut@https://localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js
:2773:4\\nL.TileLayer<._update@https://localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:2730:3\\nL.TileLayer
<.redraw@https://localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:2608:4\\n.setOptions@https://localhost
/js/src/models/model.layers.js:1408:3\\nWu.PostGISLayer<._refreshLayer@https://localhost/js/src/models
/model.layers.js:733:1\\nWu.PostGISLayer<.updateStyle@https://localhost/js/src/models/model.layers.js
:699:3\\nWu.Styler<._updateLayer/<@https://localhost/js/src/chrome/settings/styler.js:1170:4\\nWu.Api
<.post/<@https://localhost/js/src/core/api.js:284:12\\nWu.Api<._post/http.onreadystatechange@https:/
/localhost/js/src/core/api.js:302:14\\n\",\"project\":\"test\"}"
knutole commented 8 years ago

Are you running in prod mode on localhost (ie. minified js)?

knutole commented 8 years ago

Somewhat prettified:

{  
   "message":   "Error:No value provided for variable {layerUuid}",
   "file": "https://localhost/js/libleaflet.js/leaflet-0.7.3-src.js",
   "line":141,
   "user":"Sandro Santilli",
   "project":"test"
   "stack":   
       "L.Util.template <@https://localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:141:11   
        L.Util.template@https:localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:138:1   
        L.TileLayer<.getTileUrl@https:localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:2898:1   
        L.TileLayer<._loadTile@https:localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:2972:18   
        L.TileLayer<._addTile@https:localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:2866:3
        L.TileLayer<._addTilesFromCenterOut@https:localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:2773:4
        L.TileLayer<._update@https:localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:2730:3
        L.TileLayer <.redraw@https:localhost/js/lib/leaflet.js/leaflet-0.7.3-src.js:2608:4   
        setOptions@https:localhost/js/src/models/model.layers.js:1408:3   
        Wu.PostGISLayer<._refreshLayer@https:localhost/js/src/models/model.layers.js:733:1   
        Wu.PostGISLayer<.updateStyle@https:localhost/js/src/models/model.layers.js:699:3   
        Wu.Styler<._updateLayer/<@https:localhost/js/src/chrome/settings/styler.js:1170:4   
        Wu.Api<.post/<@https:localhost/js/src/core/api.js:284:12 
        Wu.Api<._post/http.onreadystatechange@https://localhost/js/src/core/api.js:302:14",
}
knutole commented 8 years ago

This https://github.com/systemapic/systemapic.js/blob/master/js/src/chrome/settings/styler.js#L1170 is the function that triggers the error. Can you console.log the args returned in this function https://github.com/systemapic/systemapic.js/blob/master/js/src/chrome/settings/styler.js#L1153 (err, newLayerJSON).

knutole commented 8 years ago

And console log this: https://github.com/systemapic/systemapic.js/blob/master/js/src/chrome/settings/styler.js#L1161

strk commented 8 years ago

app.api.createLayer doesn't seem to be hit at all

strk commented 8 years ago

(running in dev mode, no minified)

knutole commented 8 years ago

The last line of the stack api.js:302 is the callback from app.api.createLayer. You could try to console log before and after that function, incl. in api.js.

strk commented 8 years ago

I see a lot of these in the console output:

Strict-Transport-Security: The connection to the site is untrustworthy, so the specified header was ignored.

Dunno if related..

You meant js/src/core/api.js:68, right ?

knutole commented 8 years ago

Not sure if related, doubt it. Seems to be an issue with missing layerUuid (see top of stack trace).

I mean these two lines, bottom of stack-trace,

Wu.Api<.post/<@https:localhost/js/src/core/api.js:284:12 Wu.Api<._post/http.onreadystatechange@https://localhost/js/src/core/api.js:302:14",

They show the beginning of the stack trace that ended in error. api.js:284 is the callback from xmlhttprequest, and is fired by app.api.createLayer function in api.js:68, as you specified.

strk commented 8 years ago
XXXXX err: null
styler.js (line 1154)

XXXXX newLayerJSON: {
  "__v": 0,
  "lastUpdated": "2016-02-12T12:04:08.779Z",
  "created": "2016-02-12T12:04:08.779Z",
  "legend": "",
  "description": "",
  "uuid": "layer-bafe76ec-0305-4039-a741-10a2ddebd0b0",
  "_id": "56bdca38f79ea52c33eb8740"
}
styler.js (line 1155)

I found there are 2 "createLayer" methods in core/api.js: one around line 68 and one around line 189

The seem to be equal so shouldn't matter, but worth cleaning up, I guess

knutole commented 8 years ago

Could be a bug, ie. should be two different routes, will check.

knutole commented 8 years ago

This should already have been fixed with 43c60937ec1b758b8a67ab329bed43c2317f9a5c. Can you check if you have latest?

strk commented 8 years ago

In app.api.createLayer:

XXXXX newLayerStyle: {"__v":0,"lastUpdated":"2016-02-12T12:13:34.590Z","created":"2016-02-12T12:13:34.590Z","legend":"","description":"","uuid":"layer-7a0fab4e-f6be-4a3f-823a-d3478d4b1187","_id":"56bdcc6ef79ea52c33eb8743"}

Then the code calls layer.updateStyle(newLayerStyle)

But I just saw another error being printed to console:

no styloe to set!
Wu.PostGISLayer<.setStyle(postgis=undefined)model.layers.js (line 684)
Wu.PostGISLayer<.updateStyle(style=Object { type="object"})model.layers.js (line 696)
Wu.Styler<._updateLayer/<(err=null, newLayerJSON="{\n "__v": 0,\n "lastUpd...cc6ef79ea52c33eb8743"\n}")styler.js (line 1173)
Wu.Api<.post/<(err=null, response="{\n "__v": 0,\n "lastUpd...cc6ef79ea52c33eb8743"\n}")api.js (line 287)
Wu.Api<._post/http.onreadystatechange()api.js (line 305)

if (!postgis) return console.error('no styloe to set!');

model.layers.js (line 684)
strk commented 8 years ago

I have 6d64d71d1ae73fe9b9f4d0489911a29b30ab5225 (one after 43c60937ec1b758b8a67ab329bed43c2317f9a5c) and the duplicated createLayer is still there

Besides, it's two different routes indeed, the first goges to /api/db/createLayer and the second goes to api/layers/new.

strk commented 8 years ago

My browser (firefox) goes to the second (/api/layers/new) route.

knutole commented 8 years ago

Yes, should go to /api/db/, which is tileserver.

Found the bug, will push asap.

knutole commented 8 years ago

@strk Please check now.

strk commented 8 years ago

Yep, now it works. Thanks!

PS: there are still two distinct "createLayer" method implementation in Wu.Api class, doesnt' the secodn override the first ? Sounds confusing to have 2 ( on line 66 and 186 ).

knutole commented 8 years ago

Great!

Yes, second overrides first. Will clean up.