[mapserver-users] styling based on attribute for MapServer derived MVTiles

karsten karsten at terragis.net
Tue Feb 5 13:01:51 PST 2019


Great, Thanks Steve 
I added  "gml_include_items" "mapcolor7"
to the Metadata block and got it working. 
One quirk seems to be that when I am trying to the values as integer (from
the mapcolor7 column) specifying the style as in 1.) below did not work. 
However it I treat them as characters instead, quoted them and used "type":
"categorical" in the json file for the style as in 2.) below it is working.
 
Cheers
Karsten

1.)
----------------------------
{
    "id": "country-fill",
    "type": "fill",
    "source": "compass",
    "source-layer": "allcountries",
    "paint": {
      "fill-color": {
        "property": "mapcolor7",
        "stops": [
            [1, "#fdaf6b"],
            [2, "#fdc663"],
            [3, "#fae364"],
            [4, "#d3e46f"],
            [5, "#aadb78"],
            [6, "#a3cec5"],
            [7, "#ceb5cf"]
        ]
      }
    }
}
 
2.)
----------------------------
{
    "id": "country-fill",
    "type": "fill",
    "source": "compass",
    "source-layer": "allcountries",
    "paint": {
      "fill-color": {
        "property": "mapcolor7",
        "type": "categorical",
        "stops": [
            ["1", "#fdaf6b"],
            ["2", "#fdc663"],
            ["3", "#fae364"],
            ["4", "#d3e46f"],
            ["5", "#aadb78"],
            ["6", "#a3cec5"],
            ["7", "#ceb5cf"]
        ]
      }
    }
}

  _____  

From: Lime, Steve D (MNIT) [mailto:steve.lime at state.mn.us] 
Sent: Tuesday, February 05, 2019 21:15
To: karsten; mapserver-users at lists.osgeo.org
Subject: RE: [mapserver-users] styling based on attribute for MapServer
derived MVTiles



I believe the default WxS behavior is to expose no attributes. You need to
be explicit and I don't see the gml_include_items metadata property in the
mapfile for the layer allcountries. You'd need something like:

 

"gml_include_items"    "mapcolor7"

 

Added to the allcountries layer. The mvt-demo does this for most layers.

 

--Steve

 

From: mapserver-users [mailto:mapserver-users-bounces at lists.osgeo.org] On
Behalf Of karsten
Sent: Monday, February 04, 2019 4:33 PM
To: mapserver-users at lists.osgeo.org
Subject: [mapserver-users] styling based on attribute for MapServer derived
MVTiles

 

Dear All,

 

I was working on the configuration of MapServer generated MVT tiles for a
demo country world map and had success with MS v 7.2 outputting tiles in MVT
format ( all thanks to https://github.com/sdlime/mvt-demo
<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com
%2Fsdlime%2Fmvt-demo&data=02%7C01%7Csteve.lime%40state.mn.us%7C98620848f4584
46d1e2608d68af0c31b%7Ceb14b04624c445198f26b89c2159828c%7C0%7C1%7C63684916400
6408831&sdata=QYGGj%2FDN87pFfCjzP0CHZBoomTp38zRhupXy2%2BjGyi8%3D&reserved=0>
).

I am trying to work on the client side style for my demo map (using
mapbox-gl.js) and defined them in a similar way as JSON as in Steve's
mvt-demo above. The whole thing is later intended to be used in a benchmark
for MapServer MVT rendering speed versus T-Rex ( see
http://blog.sourcepole.ch/2018/09/06/the-tale-of-a-vector-tile-benchmark/
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fblog.source
pole.ch%2F2018%2F09%2F06%2Fthe-tale-of-a-vector-tile-benchmark%2F&data=02%7C
01%7Csteve.lime%40state.mn.us%7C98620848f458446d1e2608d68af0c31b%7Ceb14b0462
4c445198f26b89c2159828c%7C0%7C1%7C636849164006418845&sdata=F7kfmr8XBKaraOdKc
glqApDt%2BSuWAHSJ7x%2BTI6GJCHw%3D&reserved=0>  ) .

 

For now I am struggling with specifying the correct style syntax for the
client side and it seem that I missing something as I was not yet able to
successfully use attribute properties to render Countries as different
colors based on an attribute field of my PostGIS source.

Below is the configuration of my 'allcountries' layer. The mapcolor7 filed
is an integer field (in the input PostGIS source) but my set-up fails to
output multiple colors , instead I am getting all default black for the
country fill color. A second layer where I specified only Italy as one
Country 'country-italy' to show up renders fine -  see
https://github.com/karstenv/mvt-benchmark/blob/master/MapServer/countries_mv
t.png
<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com
%2Fkarstenv%2Fmvt-benchmark%2Fblob%2Fmaster%2FMapServer%2Fcountries_mvt.png&
data=02%7C01%7Csteve.lime%40state.mn.us%7C98620848f458446d1e2608d68af0c31b%7
Ceb14b04624c445198f26b89c2159828c%7C0%7C1%7C636849164006428858&sdata=1XeorZJ
2Tf%2FeYSD2Cs5N3JcvszoU1nplrtrqDMc%2BqXw%3D&reserved=0> 

 

My complete style JSON is at
https://github.com/karstenv/mvt-benchmark/blob/master/MapServer/ms_ne_simple
.json
<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com
%2Fkarstenv%2Fmvt-benchmark%2Fblob%2Fmaster%2FMapServer%2Fms_ne_simple.json&
data=02%7C01%7Csteve.lime%40state.mn.us%7C98620848f458446d1e2608d68af0c31b%7
Ceb14b04624c445198f26b89c2159828c%7C0%7C1%7C636849164006438854&sdata=O4%2F91
Tdg2%2BCCiHCJr1hvWqc9f4K%2B%2FBa%2FJAW4vBHbY58%3D&reserved=0> 

and the corresponding map file is here
https://github.com/karstenv/mvt-benchmark/blob/master/MapServer/ne.map
<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com
%2Fkarstenv%2Fmvt-benchmark%2Fblob%2Fmaster%2FMapServer%2Fne.map&data=02%7C0
1%7Csteve.lime%40state.mn.us%7C98620848f458446d1e2608d68af0c31b%7Ceb14b04624
c445198f26b89c2159828c%7C0%7C1%7C636849164006448867&sdata=CJawtbiFdYOcG2fa1P
xgWHHfqV1Hz18tSz71k4N59ws%3D&reserved=0> 

 

Would anyone know what I need to change in order to render the countries
with different colors according to the 'mapcolor7' attribute ?

To me it seems that somehow the attribute is not available to the renderer
even though in the MapServer map file I am selecting all fields in the
sub-query ...

 

Thanks

Karsten

 

--------------------------------------------

{
    "id": "country-fill",
    "type": "fill",
    "source": "compass",
    "source-layer": "allcountries",
    "paint": {
      "fill-color": {
        "property": "mapcolor7",
        "stops": [
            [1, "#fdaf6b"],
            [2, "#fdc663"],
            [3, "#fae364"],
            [4, "#d3e46f"],
            [5, "#aadb78"],
            [6, "#a3cec5"],
            [7, "#ceb5cf"]
        ]
      }
    }
},{
    "id": "country-italy",
    "type": "fill",
    "source": "compass",
    "source-layer": "italy",
    "paint": {
      "fill-color": "#fdc663"
      }
  }

 

Karsten Vennemann
Terra GIS 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20190205/8c60b821/attachment.htm>


More information about the MapServer-users mailing list