#1 Wed 27 June 2012 14:00
- Christian Bleau
- Participant occasionnel
- Date d'inscription: 10 Jun 2012
- Messages: 22
label de fichier GPX
Bonjour,
Sur une couche openlayer, je cherche à afficher sur une trace gpx le label "name" de chacun des points,
malheureusement sans succès.
Auriez vous une piste à m'indiquer ou un exemple basique?
Avec mes remerciements.
Christian
Code:
var context = {
pointLabel: function(feature) {
return feature.attributes['name'] + " (" + feature.attributes['name'] + ")";
}
};
var lgpx = new OpenLayers.Layer.GML("GPX", "http://..... chemin/mon_fichier.gpx", {
format: OpenLayers.Format.GPX,
style: {
strokeColor: "green",
fillColor: "orange",
graphicName: "triangle",
label: "${name}",
pointRadius: 6,
strokeWidth: 2,
strokeOpacity: 0.5,
fillOpacity: 0.5},
context: context,
projection: new OpenLayers.Projection("EPSG:4326")
});
map.addLayer(lgpx);Hors ligne
#2 Wed 27 June 2012 16:40
- Tony VINCENT
- Participant actif
- Lieu: Poitiers
- Date d'inscription: 13 Jan 2010
- Messages: 86
Re: label de fichier GPX
Bonjour,
pour essayer de trouver pourquoi le label des points de ne s'affiche pas. Il faut dans un premier temps, vérifier que la balise
Code:
<name>DESCRIPTION DU POINT</name>
existe bien dans votre fichier GPX.
Sinon, il faut la rajouter pour chaque point. Et si la balise exite déjà, c'est de modifier cette ligne :
Code:
format: OpenLayers.Format.GPX,
par
Code:
format: OpenLayers.Format.GPX({
extractattributes: true
}),En espèrent que cela puisse vous aider.
Tony
Hors ligne
#3 Wed 27 June 2012 20:17
- Christian Bleau
- Participant occasionnel
- Date d'inscription: 10 Jun 2012
- Messages: 22
Re: label de fichier GPX
Merci Tony pour cette proposition,
La balise <name> existe bien.
exemple de waypoint: extrait du fichier.
Code:
<wpt lat="45.828801998868585" lon="6.773063996806741">
<time>2012-04-29T22:23:49Z</time>
<name>001</name>
<sym>Triangle, Green</sym>
<extensions>
<gpxx:WaypointExtension>
<gpxx:DisplayMode>SymbolAndName</gpxx:DisplayMode>
</gpxx:WaypointExtension>
</extensions>
</wpt>mes point s'affichent correctement, mais sans leurs labels.
A suivre .....
Christian
Hors ligne
#4 Wed 27 June 2012 20:27
- Christian Bleau
- Participant occasionnel
- Date d'inscription: 10 Jun 2012
- Messages: 22
Re: label de fichier GPX
Bonsoir à tous,
Je viens de recevoir une solution.
La voici pour ceux qui seraient en quête de code:
Code:
var gpxStyles = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
pointRadius: "5", // sized according to type attribute
label: "${name}",
labelAlign: 'cb',
fontSize: 9,
fontFamily: "Arial",
fontColor: "red",
labelYOffset: 6,
fillColor: "brown",
strokeColor: "yellow",
strokeWidth: 2,
strokeOpacity: 1
}),
"select": new OpenLayers.Style({
fillColor: "#66ccff",
strokeColor: "#3399ff",
graphicZIndex: 2
})
});
var gpx_layer = new OpenLayers.Layer.Vector("gpx", {
protocol: new OpenLayers.Protocol.HTTP({
url: "http://localhost/.... mon_fichier.gpx",
format: new OpenLayers.Format.GPX({extractWaypoints: true, extractRoutes: false, extractAttributes: true})
}),
strategies: [new OpenLayers.Strategy.Fixed()],
visibility: false,
styleMap: gpxStyles,
projection: new OpenLayers.Projection("EPSG:4326")
});
map.addLayer(gpx_layer);Christian
Hors ligne
#5 Thu 28 June 2012 14:10
- Tony VINCENT
- Participant actif
- Lieu: Poitiers
- Date d'inscription: 13 Jan 2010
- Messages: 86
Re: label de fichier GPX
Bonjour,
merci pour le retour.
Tony
Hors ligne


