Search in sources :

Example 6 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class ActionReaderTest method testApplyWithRole.

/**
 * You can have a role filter, so that the actions are only applied
 * to members with the given role.
 */
@Test
public void testApplyWithRole() {
    List<Action> actions = readActionsFromString("{apply role=bar {" + "add route=bike;" + "set foo=bar; }}");
    Relation rel = makeRelation();
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(rel, TypeResult.NULL_RESULT);
    List<Map.Entry<String, Element>> elements = rel.getElements();
    Element el1 = elements.get(0).getValue();
    assertEquals("route tag added to first", "bike", el1.getTag("route"));
    assertEquals("foo tag set to first", "bar", el1.getTag("foo"));
    // Wrong role, so not applied.
    Element el2 = elements.get(1).getValue();
    assertNull("route tag not added to second element (role=foo)", el2.getTag("route"));
    assertNull("foo tag not set in second element (role=foo)", el2.getTag("foo"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Example 7 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class ActionReaderTest method testName.

/**
 * The name action set the element-name (not the 'name' tag).
 * The first value to set it counts, later matches are ignored.
 */
@Test
public void testName() {
    List<Action> actions = readActionsFromString("{name '${name} (${ref})' |" + "  '${ref}' | '${name}' ; }");
    Element el = makeElement();
    el.addTag("name", "Main St");
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(el, TypeResult.NULL_RESULT);
    assertEquals("just name", "Main St", el.getName());
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Example 8 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class ActionReaderTest method testRename.

@Test
public void testRename() {
    List<Action> actions = readActionsFromString("{rename park landarea}");
    assertEquals("one action", 1, actions.size());
    Element el = stdElementRun(actions);
    assertNull("park should be gone", el.getTag("park"));
    assertEquals("park renamed", "no", el.getTag("landarea"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Test(org.junit.Test)

Example 9 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class ActionReaderTest method testApplyWithSubst.

/**
 * When an apply statement runs, then substitutions on the value use
 * the tags of the relation and not of the sub element.
 */
@Test
public void testApplyWithSubst() {
    List<Action> actions = readActionsFromString("{apply {" + "add route='${route_no}';" + "}}");
    Relation rel = makeRelation();
    rel.addTag("route_no", "66");
    Element el1 = rel.getElements().get(0).getValue();
    el1.addTag("route_no", "42");
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(rel, TypeResult.NULL_RESULT);
    assertEquals("route_no taken from relation tags", "66", el1.getTag("route"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Example 10 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class ActionReaderTest method stdElementRun.

private Element stdElementRun(List<Action> actions) {
    Rule rule = new ActionRule(null, actions);
    Element el = makeElement();
    rule.resolveType(el, TypeResult.NULL_RESULT);
    return el;
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule)

Aggregations

Element (uk.me.parabola.mkgmap.reader.osm.Element)94 Test (org.junit.Test)75 Way (uk.me.parabola.mkgmap.reader.osm.Way)48 GType (uk.me.parabola.mkgmap.reader.osm.GType)25 TestUtils.makeRuleSet (func.lib.TestUtils.makeRuleSet)23 Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)15 Rule (uk.me.parabola.mkgmap.reader.osm.Rule)8 ArrayList (java.util.ArrayList)7 Node (uk.me.parabola.mkgmap.reader.osm.Node)7 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)7 Coord (uk.me.parabola.imgfmt.app.Coord)5 StringStyleFileLoader (func.lib.StringStyleFileLoader)4 Map (java.util.Map)4 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)4 TypeResult (uk.me.parabola.mkgmap.reader.osm.TypeResult)4 HashMap (java.util.HashMap)3 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Area (uk.me.parabola.imgfmt.app.Area)2