Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested layers, layer level comp-op and opacity #3474

Merged
merged 3 commits into from Mar 16, 2017

Conversation

talaj
Copy link
Member

@talaj talaj commented Jul 29, 2016

Enables grouped compositing and improves layer organization.

Layers are rendered recursively, creating it's own buffer if comp-op or opacity properties are set. Otherwise, rendering buffer is inherited from parent layer.

All tests are passing except some SVGs with changes in grouping SVG elements per Layer.

Here is a simple example.

<Map background-color="darkblue" srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
    <Parameters>
        <Parameter name="sizes">512,256</Parameter>
        <Parameter name="bbox">-20037508.3427892476320267,1283343.6938826972618699,20037508.3427892439067364,13365151.3630704730749130</Parameter>
    </Parameters>
    <Style name="world">
        <Rule>
            <PolygonSymbolizer fill="white"/>
        </Rule>
    </Style>
    <Style name="text">
        <Rule>
            <TextSymbolizer size="120" dy="-50" halo-radius="8" face-name="DejaVu Sans Bold" fill="white" vertical-alignment="top" placement="point">WORLD</TextSymbolizer>
        </Rule>
    </Style>

    <Layer name="world" comp-op="src-over" srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
        <StyleName>world</StyleName>
        <Datasource>
            <Parameter name="file">../../data/shp/world_merc</Parameter>
            <Parameter name="type">shape</Parameter>
        </Datasource>

        <Layer name="text" comp-op="dst-in" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
            <StyleName>text</StyleName>
            <Datasource>
                <Parameter name="type">csv</Parameter>
                <Parameter name="inline">
                    x, y
                    0, 0
                </Parameter>
            </Datasource>
        </Layer>
    </Layer>
</Map>

marker-whole-multi-polygon-512-256-1 0-agg

@talaj talaj force-pushed the nested-layers branch 2 times, most recently from 8c2b7b0 to 9585f93 Compare August 2, 2016 12:58
@talaj
Copy link
Member Author

talaj commented Aug 2, 2016

I have tried to add buffer recycling. Some performance benefit ~0.1 millisecond was measurable on the following style.

Times before and after the change:

 $ test/visual/run --agg -s 1 -d -i 1000 nested-layers-perf
.
Visual rendering: 0 failed / 1 passed / 0 overwritten / 0 errors
agg:    29675 milliseconds
total:  29675 milliseconds
 $ test/visual/run --agg -s 1 -d -i 1000 nested-layers-perf
.
Visual rendering: 0 failed / 1 passed / 0 overwritten / 0 errors
agg:    29585 milliseconds
total:  29585 milliseconds
<Map background-color="white">
    <Parameters>
        <Parameter name="sizes">256, 256</Parameter>
        <Parameter name="bbox">-1, -1, 1, 1</Parameter>
    </Parameters>

    <Datasource name="d">
        <Parameter name="type">csv</Parameter>
        <Parameter name="inline">
            x, y
            0, 0
        </Parameter>
    </Datasource>

    <Style name="s">
        <Rule>
            <MarkersSymbolizer file="../../data/images/marker.png" width="256" height="256" ignore-placement="true" />
        </Rule>
    </Style>

    <Layer comp-op="multiply"><StyleName>s</StyleName><Datasource base="d"></Datasource>
    <Layer comp-op="multiply"><StyleName>s</StyleName><Datasource base="d"></Datasource>
    <Layer comp-op="multiply"><StyleName>s</StyleName><Datasource base="d"></Datasource>
    </Layer></Layer></Layer>

    <Layer comp-op="multiply"><StyleName>s</StyleName><Datasource base="d"></Datasource>
    <Layer comp-op="multiply"><StyleName>s</StyleName><Datasource base="d"></Datasource>
    <Layer comp-op="multiply"><StyleName>s</StyleName><Datasource base="d"></Datasource>
    </Layer></Layer></Layer>
</Map>

@tds4u
Copy link

tds4u commented Feb 21, 2017

How is the progress? Would be awesome to have it. It's like object oriented layering, short OOL ;-)

@talaj
Copy link
Member Author

talaj commented Feb 21, 2017

@tds4u You can use it in downstream.

@artemp
Copy link
Member

artemp commented Mar 15, 2017

monkies

Noto Color Emoji + Nested layers

@talaj
Copy link
Member Author

talaj commented Mar 16, 2017

Cool monkeys :-). It's rebased.

I would like to add some rationale behind this. From design perspective I would prefer some component separated from Mapnik as described in this Compositing Ideas. That would also be more flexible for adding new features or optimizations like drawing layers concurrently. On the other side that requires to at least slightly modify all components using Mapnik. Given the simplicity of this implementation in Mapnik, naturalness of nested layers design and backward compatibility, I decided to do it in Mapnik. But have to say I'm still not absolutely certain whether it was a good idea.

@artemp
Copy link
Member

artemp commented Mar 16, 2017

@talaj - Lets give it a go in 3.1.x and see if this implementation plays well. I'm going to merge, thanks!

@artemp artemp merged commit 15daac2 into mapnik:master Mar 16, 2017
@artemp
Copy link
Member

artemp commented Mar 16, 2017

Hmm.. there are some serialisation issues.. WIP

@artemp
Copy link
Member

artemp commented Mar 16, 2017

a9aa1c6

talaj added a commit to mapycz/mapnik that referenced this pull request Sep 11, 2017
talaj added a commit to mapycz/mapnik that referenced this pull request Sep 11, 2017
talaj added a commit to mapycz/mapnik that referenced this pull request Nov 15, 2017
@talaj talaj mentioned this pull request Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants