All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.ext.vectortiles.PropertyMapper Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package org.opentripplanner.ext.vectortiles;

import com.wdtinc.mapbox_vector_tile.VectorTile;
import com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter;
import com.wdtinc.mapbox_vector_tile.adapt.jts.UserDataKeyValueMapConverter;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerProps;
import java.util.Collection;
import org.opentripplanner.common.model.T2;

/**
 * This class is used for adding data for each object in the vector layer from the userData in the
 * geometry.
 *
 * @param  is type of userData in the geometry.
 * @see UserDataKeyValueMapConverter
 */
public abstract class PropertyMapper implements IUserDataConverter {

  public void addTags(
    Object userData,
    MvtLayerProps layerProps,
    VectorTile.Tile.Feature.Builder featureBuilder
  ) {
    if (userData != null) {
      for (T2 e : map((T) userData)) {
        final String key = e.first;
        final Object value = e.second;

        if (key != null && value != null) {
          final int valueIndex = layerProps.addValue(value);

          if (valueIndex >= 0) {
            featureBuilder.addTags(layerProps.addKey(key));
            featureBuilder.addTags(valueIndex);
          }
        }
      }
    }
  }

  /**
   * The return type is to allow null values.
   */
  protected abstract Collection> map(T input);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy