Hey!
We are using the graphhopper-core (4.0) in a spring/boot application.
Our data has custom way tags that we would like to load into the cache.
For this purpose we have created a StringEncodedValue that is not shared.
This value is set in a our custom encoder:
public class CustomFlagEncoder extends Bike2WeightFlagEncoder {
private StringEncodedValue encodedValue;
@Override
public void applyWayTags(ReaderWay way, EdgeIteratorState edge) {
super.applyWayTags(way, edge);
edge.set(encodedValue, way.getTag(CustomTag.DATA_KEY, ""));
}
@Override
public void createEncodedValues(List<EncodedValue> registerNewEncodedValue, String prefix, int index) {
super.createEncodedValues(registerNewEncodedValue, prefix, index);
encodedValue = getStringEncodedValue(CustomTag.ENCODED_VALUE_KEY);
}
}
This value is then used in our custom weighting, by getting it using the given FlagEncoder.
The graphhopper instance is initialized with a CustomEncodedValueFactory:
public class CustomEncodedValueFactory implements EncodedValueFactory {
private final EncodedValueFactory baseEncodedValueFactory;
public CustomEncodedValueFactory(EncodedValueFactory baseEncodedValueFactory) {
this.baseEncodedValueFactory = baseEncodedValueFactory;
}
@Override
public EncodedValue create(String encodedValueString) {
if (encodedValueString.contains(CustomTag.ENCODED_VALUE_KEY)) {
return CustomTag.create();
}
return baseEncodedValueFactory.create(encodedValueString);
}
}
and a TagParser is added to the EncodingManagerBuilder prior to the load or process:
public class CustomTagParser implements TagParser {
private StringEncodedValue encodedValue;
CustomTagParser() {
this.encodedValue = CustomTag.create();
}
@Override
public void createEncodedValues(EncodedValueLookup lookup, List<EncodedValue> registerNewEncodedValue) {
registerNewEncodedValue.add(encodedValue = CustomTag.create());
}
@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, boolean ferry, IntsRef relationFlags) {
if (way.hasTag(CustomTag.DATA_KEY)) {
encodedValue.setString(false, edgeFlags, way.getTag(CustomTag.DATA_KEY));
}
return edgeFlags;
}
}
The issue im getting after loading the cache again when I restart the application is: java.lang.IllegalStateException: Encoded values do not match
What isnt matching is that our CustomTag doesnt seem to be shifted correctly.
Im sitting at this problem since a long time now and unfortunately switching to the server version of graphhopper is no option anymore.
Hope you can help me!
Cheers!