@@ -117,12 +117,14 @@ Feature Mvt::getFeature(ParserContext& _ctx, protobuf::message _featureIn) {
117117 }
118118
119119 auto valueKey = tagsMsg.varint ();
120-
120+ // Check if the property should be dropped
121+ if (_ctx.keys [tagKey].empty ()) {
122+ continue ;
123+ }
121124 if ( _ctx.values .size () <= valueKey ) {
122125 LOGE (" accessing out of bound values" );
123126 return feature;
124127 }
125-
126128 _ctx.featureTags [tagKey] = valueKey;
127129 }
128130 break ;
@@ -215,7 +217,8 @@ Feature Mvt::getFeature(ParserContext& _ctx, protobuf::message _featureIn) {
215217 return feature;
216218}
217219
218- Layer Mvt::getLayer (ParserContext& _ctx, protobuf::message _layerIn) {
220+ Layer Mvt::getLayer (ParserContext& _ctx, protobuf::message _layerIn,
221+ const TileSource::PropertyFilter& filter) {
219222
220223 Layer layer (" " );
221224
@@ -245,7 +248,29 @@ Layer Mvt::getLayer(ParserContext& _ctx, protobuf::message _layerIn) {
245248 continue ;
246249 }
247250 case LAYER_KEY : {
248- _ctx.keys .push_back (_layerIn.string ());
251+ std::string key = _layerIn.string ();
252+ // Check whether the key must be kept
253+ if (std::find (std::begin (filter.keep ), std::end (filter.keep ), key) == std::end (filter.keep )) {
254+ // Check whether the key should be dropped
255+ if (std::find_if (std::begin (filter.drop ), std::end (filter.drop ),
256+ [&](auto & k) {
257+ if (k.back () == ' *' && key.length () >= k.length ()-1 ) {
258+ int n = std::strncmp (key.c_str (), k.c_str (), k.length ()-1 );
259+ // LOG("check %s / %d / %d", k.c_str(), n, k.length()-1);
260+ return n == 0 ;
261+ } else {
262+ return key == k;
263+ }}) != std::end (filter.drop )) {
264+
265+ LOG (" drop key: %s" , key.c_str ());
266+ key = " " ;
267+ // } else {
268+ // LOG("keep key: %s", key.c_str());
269+ }
270+ // } else {
271+ // LOG("keep key: %s", key.c_str());
272+ }
273+ _ctx.keys .emplace_back (std::move (key));
249274 break ;
250275 }
251276 case LAYER_VALUE : {
@@ -321,7 +346,8 @@ Layer Mvt::getLayer(ParserContext& _ctx, protobuf::message _layerIn) {
321346 return layer;
322347}
323348
324- std::shared_ptr<TileData> Mvt::parseTile (const TileTask& _task, int32_t _sourceId) {
349+ std::shared_ptr<TileData> Mvt::parseTile (const TileTask& _task, int32_t _sourceId,
350+ const TileSource::PropertyFilter& filter) {
325351
326352 auto tileData = std::make_shared<TileData>();
327353
@@ -333,7 +359,7 @@ std::shared_ptr<TileData> Mvt::parseTile(const TileTask& _task, int32_t _sourceI
333359 try {
334360 while (item.next ()) {
335361 if (item.tag == LAYER ) {
336- tileData->layers .push_back (getLayer (ctx, item.getMessage ()));
362+ tileData->layers .push_back (getLayer (ctx, item.getMessage (), filter ));
337363 } else {
338364 item.skip ();
339365 }
0 commit comments