[OpenLayers-Dev] Vector Layer, GPX and context

"Álvaro Monares G." amonares at dcc.uchile.cl
Sat Mar 5 05:24:14 EST 2011


Hello everybody, I try this question in the user list, but
without any answer. So I try it here, I'm displaying a GPX
tracks with some waypoints. I'm using this:

var myStyleMap = new OpenLayers.StyleMap({
                 "default": new OpenLayers.Style({
                     pointRadius: 5,
                     fillColor: "darkred",
                     strokeColor: "red",
                     strokeWidth: 4
                 })
             });

var lgpx = new OpenLayers.Layer.Vector("Ruta", {
                 protocol: new OpenLayers.Protocol.HTTP({
                     url: "my.gpx",
                     format: new 
OpenLayers.Format.GPX({extractWaypoints: true, extractRoutes: true, 
extractAttributes: true})
                 }),
                 strategies: [new OpenLayers.Strategy.Fixed()],
                 styleMap: myStyleMap,
                 projection: new OpenLayers.Projection("EPSG:4326")
             });
map.addLayer(lgpx);

This show tracks and waypoints, nice. But now I want something a bit 
complex,
that is have a different color to each track. So first i try to use this
var context = {
                 getColor: function(feature) {
                     return "red";
                 }
             };
    var myStyleMap = new OpenLayers.StyleMap({
             "default": new OpenLayers.Style({
                 pointRadius: 5,
                 fillColor: "darkred",
                 strokeColor: "${getColor}",
                 strokeWidth: 4
             },{context: context})
         });

var lgpx = new OpenLayers.Layer.Vector("Ruta", {
                 protocol: new OpenLayers.Protocol.HTTP({
                     url: "my.gpx",
                     format: new 
OpenLayers.Format.GPX({extractWaypoints: true, extractRoutes: true, 
extractAttributes: true})
                 }),
                 strategies: [new OpenLayers.Strategy.Fixed()],
                 styleMap: myStyleMap,
                 projection: new OpenLayers.Projection("EPSG:4326")
             });
map.addLayer(lgpx);

But now, only the inside of the waypoints are rendered. So the 
"$getColor" is not working. This should work also here ?

Best regards
Álvaro Monares G.


More information about the Dev mailing list