Merge pull request #42 from stevage/train-routes
authorRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 18:07:10 +0000 (11:07 -0700)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 18:07:10 +0000 (11:07 -0700)
Add train routes

net/systemeD/potlatch2/mapfeatures/Feature.as
resources/map_features.xml
resources/map_features/transport.xml

index 8ae89c8ed5c33fa7bad87a6034ca2fcc14691426..a1d7c31effe9684f479664c501ea20044358743b 100644 (file)
@@ -1,5 +1,4 @@
 package net.systemeD.potlatch2.mapfeatures {
-
     import flash.events.Event;
     import flash.events.EventDispatcher;
     import flash.net.*;
@@ -11,13 +10,15 @@ package net.systemeD.potlatch2.mapfeatures {
     import net.systemeD.halcyon.FileBank;
     import net.systemeD.halcyon.connection.Entity;
 
-        /** A "map feature" is sort of a template for a map entity. It consists of a few crucial key/value pairs that define the feature, so that
-         * entities can be recognised. It also contains optional keys, with associated editing controls, that are defined as being appropriate
-         * for the feature. */
+
+    /** A "map feature" is sort of a template for a map entity. It consists of a few crucial key/value pairs that define the feature, so that
+     * entities can be recognised. It also contains optional keys, with associated editing controls, that are defined as being appropriate
+     * for the feature. */
        public class Feature extends EventDispatcher {
         private var mapFeatures:MapFeatures;
         private var _xml:XML;
-        private static var variablesPattern:RegExp = /[$][{]([^}]+)[}]/g;
+        // match ${foo|bar|baz|...} - see makeHTMLIcon()
+        private static var variablesPattern:RegExp = /\$\{([^|}]+)\|?([^|}]+)?\|?([^|}]+)?\|?([^|}]+)?\|?([^|}]+)?\|?([^}]+)?\}/g;
         private var _tags:Array;
         private var _withins:Array;
         private var _editors:Array;
@@ -188,17 +189,30 @@ package net.systemeD.potlatch2.mapfeatures {
             return makeHTMLIcon(icon, entity);
         }
 
-        /** Convert the contents of the "icon" tag as an HTML string, with variable substitution. */
+        /** Convert the contents of the "icon" tag as an HTML string, with variable substitution:
+        *   ${highway} shows the value of the highway key
+        *   ${name|operator|network} - if there's no name value, show operator, or network, or nothing.
+        *   (${ref}) - renders as nothing if $ref is valueless.
+        */
         public static function makeHTMLIcon(icon:XMLList, entity:Entity):String {
             if ( icon == null )
                 return "";
 
             var txt:String = icon.children().toXMLString();
+            // Args to this function: "string matched", "substring 1", "substring 2"..., index of match, whole string
             var replaceTag:Function = function():String {
-                var value:String = entity.getTag(arguments[1]);
+               var matchnum=0;
+               var args=arguments;
+               var value:String = null;
+               while ((value == null || value == "") && matchnum < args.length - 3  ) {
+                  value = entity.getTag(args[matchnum + 1]);
+                  matchnum++;
+               }
                 return value == null ? "" : htmlEscape(value);
             };
             txt = txt.replace(variablesPattern, replaceTag);
+            // a slightly hacky way of making "${name} (${ref})" look ok even if ref is undefined.
+            txt = txt.replace("()", ""); 
             return txt;
         }
 
index bfcdc4d45bcab7b2294cbfffb66e6a7bb632575f..fbc4a39864913cedb4698693a3b41a38e47b75c3 100644 (file)
     </input>
   </inputSet>
 
+  <inputSet id="train-route">
+    <input type="route" name="Train Route" description="Train route" category="Transport" priority="low" presence="onTagMatch">
+      <match k="type" v="route"/>
+      <match k="route" v="train"/>
+      <icon image="features/transport__railway.png">
+        <font size="12pt">${name|operator} <b>(${ref})</b></font>
+      </icon>
+    </input>
+  </inputSet>
+
   <inputSet id="cycle">
     <inputSet ref="bicycle-permission"/>
     <input type="route" name="National Cycle Routes" description="A signposted route in a National Cycle Network, or nearest equivalent." category="Cycle" priority="low">
       <choice value="volleyball" text="Volleyball"/>
     </input>
   </inputSet>
+  
+  <inputSet id="wheelchair-basic">
+    <input type="choice" name="Wheelchair" key="wheelchair" presence="onTagMatch" category="Details">
+      <choice value="yes" text="Yes: ramps/elevators/etc" />
+      <choice value="no" text="No: inaccessible to wheelchairs" />
+      <choice value="limited" text="Limited accessibility" />
+    </input>
+  </inputSet>      
 
 <!-- Features -->
 
index 483ee8eb6c8532d598db7290a7cad00ed10c6358..a6462be6d90e6bffd3b64ba2a290318fb377eb28 100755 (executable)
@@ -14,6 +14,8 @@
         <inputSet ref="embankment-cutting"/>
         <inputSet ref="rail-electrification"/>
         <inputSet ref="common"/>
+        <inputSet ref="train-route"/>
+        
       </feature>
     
     
@@ -29,6 +31,7 @@
         <tag k="railway" v="rail"/>
         <tag k="service" v="spur"/>
         <inputSet ref="common"/>
+        <inputSet ref="train-route"/>
       </feature>
     
     
@@ -44,6 +47,7 @@
         <tag k="railway" v="rail"/>
         <tag k="service" v="siding"/>
         <inputSet ref="common"/>
+        <inputSet ref="train-route"/>
       </feature>
     
     
@@ -56,6 +60,7 @@
         <line/>
         <tag k="railway" v="preserved"/>
         <inputSet ref="common"/>
+        <inputSet ref="train-route"/>
       </feature>
     
     
@@ -70,6 +75,7 @@
         <line/>
         <tag k="railway" v="disused"/>
         <inputSet ref="common"/>
+        <inputSet ref="train-route"/>
       </feature>
     
     
@@ -82,6 +88,7 @@
         <line/>
         <tag k="railway" v="abandoned"/>
         <inputSet ref="common"/>
+        <inputSet ref="train-route"/>
       </feature>
     
     
         <inputSet ref="embankment-cutting"/>
         <inputSet ref="rail-electrification"/>
         <inputSet ref="common"/>
+        <inputSet ref="tram-route"/>
+        <inputSet ref="train-route"/>
       </feature>
     
     
         <inputSet ref="embankment-cutting"/>
         <inputSet ref="rail-electrification"/>
         <inputSet ref="common"/>
+        <inputSet ref="train-route"/>
       </feature>
     
     
     <input type="freetext" presence="onTagMatch" category="Details" name="Operator" key="operator" description="The provider of the service" priority="low"/>
     <input type="number" minimum="1" maximum="99999" stepSize="1" presence="onTagMatch" category="Details" name="Platforms" key="platforms" description="The number of passenger platforms at the station" priority="low"/>
     <inputSet ref="common"/>
+    <inputSet ref="train-route"/>
+    
   </feature>
 
 
     <inputSet ref="common"/>
   </feature>
 
+  <feature name="Train Route">
+    <category>transport</category>
+    <icon image="features/transport__railway.png">
+      <font size="12pt">
+        ${name|operator} <b>(${ref})</b>
+      </font>
+    </icon>
+
+    <relation/>
+    <tag k="type" v="route"/>
+    <tag k="route" v="train"/>
+    <input type="freetext" presence="always" category="Details" name="Name" priority="high" key="name" description="Official route name"/>
+    <input type="freetext" presence="always" category="Details" name="Reference" priority="high" key="ref" description="The official reference number"/>
+    <input type="freetext" presence="always" category="Details" name="Network" key="network" description="The network of the train service" priority="high"/>
+    <input type="freetext" presence="always" category="Details" name="Operator" key="operator" description="The provider of the train service" priority="low"/>
+    <input type="freetext" presence="onTagMatch" category="Details" name="Colour code" key="colour" description="Official colour designation for the route, if any." priority="low" />
+    <inputSet ref="source"/>
+    <inputSet ref="wheelchair-basic" />
+  </feature>
+
       
 </featureGroup>