mobile-sdk icon indicating copy to clipboard operation
mobile-sdk copied to clipboard

[feature-request] style json `extends` fields

Open farfromrefug opened this issue 4 years ago • 7 comments

In an effort to reduce style size and since most "sub-styles" (voyager, positron...) share the same json data it would nice to be able to use something like "extends":"./voyager.json" just like it works in most config files like tsconfig.json

Right now in my style it would reduce the style by 30kb

farfromrefug avatar Aug 13 '21 09:08 farfromrefug

Good idea, I have included this in develop branch (in mobile-carto-libs).

mtehver avatar Aug 14 '21 09:08 mtehver

@mtehver awesome! Didnot have time to test it but looking at the code the merge is done the wrong way. You are applying the extend to the original picojson. It should be the other way around.if extends it become the original and for every property in the "non extends" you overwrite the property from the "extends" picojson

farfromrefug avatar Aug 14 '21 09:08 farfromrefug

No, the file referenced by 'extends' field is taken as a base and fields from current file overwrite base fields. So it should work the same way as 'extends' in tsconfig.json works.

mtehver avatar Aug 14 '21 12:08 mtehver

Sorry my bad must have read it wrong !

farfromrefug avatar Aug 14 '21 16:08 farfromrefug

@mtehver saw one last thing which should be nice. Here https://github.com/CartoDB/mobile-carto-libs/blob/master/cartocss/src/cartocss/CartoCSSMapLoader.cpp#L166 when you "override" the extended style, if the "value" is an object it should be a "merge". This is what tsconfig does for compilerOptions for example. The really nice thing in our case is that it could allow to "override" or add some nutiparameters

farfromrefug avatar Aug 18 '21 09:08 farfromrefug

I would rather keep the current behavior, as merging objects would not allow deleting keys in 'extended' styles. It is also more uniform approach, treating all types equally.

mtehver avatar Aug 27 '21 17:08 mtehver

@mtehver i understand. Now it makes the new theme i create difficult to maintain. Let me explain. As you know i handle "icons" with font icons to reduce size and allow coloring of icon. So i store icons unicode chars in nutiparameters. With the extends all styles get the icons from the extends. Now i would like to enable/disable some feature based on the style. Like the streets style should have contours disabled by default. I dont see any other to do that than with nutiparameters. But then i need to be able to override some nutiparameters while keeping the icons. Will see if i can do it differently

farfromrefug avatar Aug 27 '21 17:08 farfromrefug