Search in sources :

Example 1 with MapEncodingRule

use of net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapEncodingRule in project OsmAnd-tools by osmandapp.

the class BinaryMapIndexWriter method writeMapEncodingRules.

public void writeMapEncodingRules(TIntObjectMap<TagValuePair> decodingRules) throws IOException {
    for (int i = 1; i <= decodingRules.size(); i++) {
        TagValuePair value = decodingRules.get(i);
        MapEncodingRule.Builder builder = OsmandOdb.OsmAndMapIndex.MapEncodingRule.newBuilder();
        if (value == null) {
            break;
        }
        builder.setTag(value.tag);
        if (value.value != null) {
            builder.setValue(value.value);
        }
        builder.setType(value.additionalAttribute);
        MapEncodingRule rulet = builder.build();
        codedOutStream.writeMessage(OsmandOdb.OsmAndMapIndex.RULES_FIELD_NUMBER, rulet);
    }
}
Also used : MapEncodingRule(net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapEncodingRule) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair)

Example 2 with MapEncodingRule

use of net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapEncodingRule in project OsmAnd-tools by osmandapp.

the class BinaryMapIndexWriter method writeMapEncodingRules.

public void writeMapEncodingRules(Map<String, MapRulType> types) throws IOException {
    checkPeekState(MAP_INDEX_INIT);
    ArrayList<MapRulType> out = new ArrayList<MapRulType>();
    int highestTargetId = types.size();
    // 1. prepare map rule type to write
    for (MapRulType t : types.values()) {
        if (t.getFreq() == 0 || !t.isMap()) {
            t.setTargetId(highestTargetId++);
        } else {
            out.add(t);
        }
    }
    // 2. sort by frequency and assign ids
    Collections.sort(out, new Comparator<MapRulType>() {

        @Override
        public int compare(MapRulType o1, MapRulType o2) {
            return o2.getFreq() - o1.getFreq();
        }
    });
    for (int i = 0; i < out.size(); i++) {
        MapEncodingRule.Builder builder = OsmandOdb.OsmAndMapIndex.MapEncodingRule.newBuilder();
        MapRulType rule = out.get(i);
        rule.setTargetId(i + 1);
        builder.setTag(rule.getTag());
        if (rule.getValue() != null) {
            builder.setValue(rule.getValue());
        }
        builder.setMinZoom(rule.getMinzoom());
        if (rule.isAdditional()) {
            builder.setType(1);
        } else if (rule.isText()) {
            builder.setType(2);
        }
        MapEncodingRule rulet = builder.build();
        codedOutStream.writeMessage(OsmandOdb.OsmAndMapIndex.RULES_FIELD_NUMBER, rulet);
    }
}
Also used : MapEncodingRule(net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapEncodingRule) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TByteArrayList(gnu.trove.list.array.TByteArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) MapRulType(net.osmand.osm.MapRenderingTypes.MapRulType)

Aggregations

MapEncodingRule (net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapEncodingRule)2 TByteArrayList (gnu.trove.list.array.TByteArrayList)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 ArrayList (java.util.ArrayList)1 TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)1 MapRulType (net.osmand.osm.MapRenderingTypes.MapRulType)1