Lien en fonction de l'url

Eléphant du PHP | 372 Messages

21 juil. 2014, 17:32

Salut voilà mon petit problème today,
J'ai créer une map interactive et je souhaite maintenant enfait faire un lien au clik et être redirigé en fonction de l'url,
en gros:
J'ai une url du genre: http://monsite.php?region=22 ( région 22 correspond à Rhone-alpes pour cette exemple ).

et coté JS:
intégrer les fameux lien pour l'instant j'ai ça mais à marches po :/
[javascript]
<script type="text/javascript">
jQuery(function($){
var regions = [
{name : 'Rhônes Alpes', slug:'22'},
{name : 'Martinique', slug: 'martinique'},
{name : 'Réunion', slug: 'reunion'},
{name : 'Guadeloupe', slug: 'guadeloupe' }
];

// redirection en fonction de la région choisi
$('.francemap').each(function(){
var index = $(this).index();
$(this).attr('href','sortie.php?region='+regions[index].slug);
});

});
</script>

</head>
<body>
<div class="francemap" style="width: 700px; height: 600px;"></div>
</body>
[/javascript]

Merci pour votre aide ;)

Voici coté js.vector.map, un exemple d'une balise dirons nous:
[javascript]"12":{"path":"M589.04,68.5l4.75-8.4l5.3-3l13.7-11.4l4.04-0.4v-3.45l1.96-2.25l5.9,2.1l1,1.2l1.6-2.7l5.1-3l3.2,0.9l4.27,3.85l2.73-0.25l8.5,1.3l8.2-6.2l6.4-8.8l4.1-1.7l4.5,2.9l0.89,4.04l-2.69,3.46l6.04,10.25l-0.84,5.15l-0.1,5.42l-6.36,6.56l1.56,6.02l3.95,0.3l-2.61,3.38l4.4,11.33l-1.3,9.73l-0.14,1.07l3.7,2.4l1.55,3.58l-3.31,0.19l0.35,3.04l-2.39,2.08l1.38,3.64l-5.23,6.94l0.64,5.18l-8.74-3.68l-3.44-8.44l-7.46,1.44l-4.6,3.6l-2.2-3l-5.2,2.3l-0.7-2.5l-4.9,1.8l-3.3-2.4l-0.09-4.93l-3.11,1.63l-5.69-3l-1.25-0.56l-3.16,6.56l-4.94-3.03l-1.47-5.61c0,0-8.25-3.28-8.79-5.26l-0.5-2.1l-2.32-0.95l-2.48-4.15L594.64,91l-0.11-5.23l-3.3,0.5l-3.18-7.24l2.78-3.36l-1.84-6.57",
"name" : 'Rhônes Alpes', slug:'22'},[/javascript]

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

21 juil. 2014, 17:58

salut,

document.location.href ?


@+
Il en faut peu pour être heureux ......

Eléphant du PHP | 372 Messages

21 juil. 2014, 18:03

merci pour l'intervention mais je le substitue a quoi exactement et surtout que dois je supprimer afin d'éviter toute sorte de conflit au niveau du code, dsl je débute :)

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

21 juil. 2014, 18:09

dans la fonction appelée sur le onclick tu utilise ce que j'ai mis plus haut.

si tu sais pas ce que c'est google va te trouver la solution rapidement (c'est courant) ;)

@+
Il en faut peu pour être heureux ......

Eléphant du PHP | 372 Messages

21 juil. 2014, 20:18

Ui alors effectivement ça marche j'ai fait le test en mettant en dur l'adresse url:
[javascript]
onRegionClick: function(element, code, region)
{
location.href='http://monsite.php?region=22'
}
[/javascript]

Mais j'aimerais que ça varie en fonction de la région sur laquelle il clik:
la l'utilisateur arrive à chaque fois sur la région Rhone alpes ( l'url correspond à cette région ).

J'aimerais que si il click par exemple sur alsace il arrive sur la page :http://monsite.php?region=1
et ainsi de suite mais comment procéder à ses variante svp.

J'ai quelque chose comme çeci que j'ai trouvé mais bien entendu tel quel ça ne pas marcher je pense, j'aimerais savoir ce qu'il faut faire et une explication svp, merci encore

ViPHP
xTG
ViPHP | 7331 Messages

21 juil. 2014, 20:32

Tu as region en paramètre.
Il te faut donc la concaténer avec l'url.
Pour cela il existe 36 méthodes comme on dit.
http://b-le-roux.developpez.com/tutorie ... /jsconcat/

Eléphant du PHP | 372 Messages

22 juil. 2014, 11:47

Salut, me revoilà ayant solutionner mon problème

j'ai donc maitenant:
[javascript]
onRegionClick: function(element, code, name)
{
window.location.href = '/monsite.php?region=' + name;
}
[/javascript]

J'aimerais rajouté par exemple, bourgone pas en commentaire mais ainsi à la suite de name mais d'une autre couleur en gros remplacer
"name":"4 "},//bourgone
par quelque chose du genre:
"name":"4" #FFF bourgone},//bourgone

Comment procéder svp, merci

coté jquery.vmap.france.js
"07":{"path":"M531.69,303 526.14,299.88 520.89,301.44 515.59,299.5 510.19,321.33 503.56,312 503.56,315.2 500.44,313.83 497.69,315.1 495.49,313.4 494.06,313.7 493.19,315.3 492.89,318.67 487.19,322.1 485.09,320 477.09,321.5 471.89,318.2 471.89,315.2 475.01,311.33 476.09,305.1 474.49,302.7 466.59,299.8 459.89,286.3 453.99,292.3 449.59,288.6 446.79,290.3 439.49,290 434.69,283.8 435.99,274.9 436.19,269.1 433.99,267.1 433.77,262.8 430.59,253.6 427.89,251.5 429.59,245.7 427.59,239.2 428.73,237.38 431.44,236.21 429.69,229.2 426.69,226.4 432.88,221.77 433.59,220.7 432.49,217.8 436.53,213.5 436.69,207.1 429.99,199.6 433.89,194.2 434.09,188.4 449.49,185.4 453.09,186.9 457.59,192.4 460.09,200.7 462.09,198.5 465.69,202.6 470.69,213.5 483.29,211.9 486.19,213.3 489.25,211.17 494.49,210.4 499.19,206.5 505.73,207.15 507.09,210.4 509.69,212.2 509.69,215.3 512.29,214.6 515.09,219.9 512.29,222.3 514.59,227.1 523.79,229.1 526.79,230.7 526.79,233.5 531.69,231.6 532.09,230.7 534.86,230.7 536.39,233 535.74,236.87 531.29,240 534.49,241.7 538.39,249.9 537.19,251.2 535.39,259.4 529.7,265.64 528.09,270.3 528.49,273.2 536.79,277.6 531.29,281.8 534.29,282.9 536.49,291.6 533.69,296.6 534.49,301.9z",
"name":"4 "},//bourgone

ViPHP
xTG
ViPHP | 7331 Messages

22 juil. 2014, 13:00

Euh attention... Ce que tu tentes de modifier c'est un tableau sérialisé en fait.
C'est lors de l'exploitation de ce tableau que tu veux que name soit écrit en blanc ?

Eléphant du PHP | 372 Messages

22 juil. 2014, 13:14

Enfait nan name doit rester comme ça
Il faut que je rajoute par exemple:"bourgogne" à part du name.
Si je le met à la suite va s'envoyer dans l'url et tout faire foiré.

[javascript]
"name":"4"},//correspond à l'id de ma région et ainsi faire la redirection
[/javascript]

et je penser faire quelque chose comme"infobulle":"bourgogne" pour le hover et l'écrire en blanc,
Pour l'instant au hover j'ai l'id donc 4 pour l'exemple

ViPHP
xTG
ViPHP | 7331 Messages

22 juil. 2014, 16:39

Donc :

Code : Tout sélectionner

"07":{"path":"M531.69,303 526.14,299.88 520.89,301.44 515.59,299.5 510.19,321.33 503.56,312 503.56,315.2 500.44,313.83 497.69,315.1 495.49,313.4 494.06,313.7 493.19,315.3 492.89,318.67 487.19,322.1 485.09,320 477.09,321.5 471.89,318.2 471.89,315.2 475.01,311.33 476.09,305.1 474.49,302.7 466.59,299.8 459.89,286.3 453.99,292.3 449.59,288.6 446.79,290.3 439.49,290 434.69,283.8 435.99,274.9 436.19,269.1 433.99,267.1 433.77,262.8 430.59,253.6 427.89,251.5 429.59,245.7 427.59,239.2 428.73,237.38 431.44,236.21 429.69,229.2 426.69,226.4 432.88,221.77 433.59,220.7 432.49,217.8 436.53,213.5 436.69,207.1 429.99,199.6 433.89,194.2 434.09,188.4 449.49,185.4 453.09,186.9 457.59,192.4 460.09,200.7 462.09,198.5 465.69,202.6 470.69,213.5 483.29,211.9 486.19,213.3 489.25,211.17 494.49,210.4 499.19,206.5 505.73,207.15 507.09,210.4 509.69,212.2 509.69,215.3 512.29,214.6 515.09,219.9 512.29,222.3 514.59,227.1 523.79,229.1 526.79,230.7 526.79,233.5 531.69,231.6 532.09,230.7 534.86,230.7 536.39,233 535.74,236.87 531.29,240 534.49,241.7 538.39,249.9 537.19,251.2 535.39,259.4 529.7,265.64 528.09,270.3 528.49,273.2 536.79,277.6 531.29,281.8 534.29,282.9 536.49,291.6 533.69,296.6 534.49,301.9z", "name":"4 ", "infobulle":"Bourgogne"},
Mais après comme on ne sait pas comment tu récupères toutes ces informations... :roll:

Mammouth du PHP | 643 Messages

22 juil. 2014, 17:09

Est il possible sinan de faire par exemple affiche le 4 en noir et Bourgogne en blanc à l'intérieur de "name":.......
merci pour votre aide.

[javascript]
"name":"4 ",
[/javascript]

ViPHP
xTG
ViPHP | 7331 Messages

22 juil. 2014, 17:18

C'est quoi ces multicomptes. O_o

Et toujours la même réponse : sans ma boule de cristal je ne sais pas comment tu récupères ces informations donc...

Eléphant du PHP | 372 Messages

22 juil. 2014, 18:17

Avec cette page
[javascript](function ($){

var apiParams = {
colors: 1,
values: 1,
backgroundColor: 1,
scaleColors: 1,
normalizeFunction: 1,
enableZoom: 1,
showTooltip: 1,
infobulle: 1,
borderColor: 1,
borderWidth: 1,
borderOpacity: 1,
selectedRegion: 1
};

var apiEvents = {
onLabelShow: 'labelShow',
onRegionOver: 'regionMouseOver',
onRegionOut: 'regionMouseOut',
onRegionClick: 'regionClick'
};

$.fn.vectorMap = function (options){

var defaultParams = {
map: 'world_en',
backgroundColor: '#a5bfdd',
color: '#000',
hoverColor: '#c9dfaf',
selectedColor: '#c9dfaf',
scaleColors: ['#b6d6ff', '#005ace'],
normalizeFunction: 'linear',
enableZoom: true,
showTooltip: false,
borderColor: '#818181',
borderWidth: 1,
borderOpacity: 0.25,
selectedRegion: null
}, map;

if (options === 'addMap')
{
WorldMap.maps[arguments[1]] = arguments[2];
}
else if (options === 'set' && apiParams[arguments[1]])
{
this.data('mapObject')['set' + arguments[1].charAt(0).toUpperCase() + arguments[1].substr(1)].apply(this.data('mapObject'), Array.prototype.slice.call(arguments, 2));
}
else
{
$.extend(defaultParams, options);
defaultParams.container = this;
this.css({ position: 'relative', overflow: 'hidden' });

map = new WorldMap(defaultParams);

this.data('mapObject', map);

for (var e in apiEvents)
{
if (defaultParams[e])
{
this.bind(apiEvents[e] + '.jqvmap', defaultParams[e]);
}
}
}
};

var VectorCanvas = function (width, height, params)
{
this.mode = window.SVGAngle ? 'svg' : 'vml';
this.params = params;

if (this.mode == 'svg')
{
this.createSvgNode = function (nodeName)
{
return document.createElementNS(this.svgns, nodeName);
};
}
else
{
try {
if (!document.namespaces.rvml)
{
document.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
}
this.createVmlNode = function (tagName)
{
return document.createElement('<rvml:' + tagName + ' class="rvml">');
};
}
catch (e)
{
this.createVmlNode = function (tagName)
{
return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
};
}

document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
}

if (this.mode == 'svg')
{
this.canvas = this.createSvgNode('svg');
}
else
{
this.canvas = this.createVmlNode('group');
this.canvas.style.position = 'absolute';
}

this.setSize(width, height);
};

VectorCanvas.prototype = {
svgns: "http://www.w3.org/2000/svg",
mode: 'svg',
width: 0,
height: 0,
canvas: null,

setSize: function (width, height)
{
if (this.mode == 'svg')
{
this.canvas.setAttribute('width', width);
this.canvas.setAttribute('height', height);
}
else
{
this.canvas.style.width = width + "px";
this.canvas.style.height = height + "px";
this.canvas.coordsize = width + ' ' + height;
this.canvas.coordorigin = "0 0";
if (this.rootGroup)
{
var pathes = this.rootGroup.getElementsByTagName('shape');
for (var i = 0, l = pathes.length; i < l; i++)
{
pathes.coordsize = width + ' ' + height;
pathes.style.width = width + 'px';
pathes.style.height = height + 'px';
}
this.rootGroup.coordsize = width + ' ' + height;
this.rootGroup.style.width = width + 'px';
this.rootGroup.style.height = height + 'px';
}
}
this.width = width;
this.height = height;
},

createPath: function (config)
{
var node;
if (this.mode == 'svg')
{
node = this.createSvgNode('path');
node.setAttribute('d', config.path);

if(this.params.borderColor !== null)
{
node.setAttribute('stroke', this.params.borderColor);
}
if(this.params.borderWidth > 0)
{
node.setAttribute('stroke-width', this.params.borderWidth);
node.setAttribute('stroke-linecap', 'round');
node.setAttribute('stroke-linejoin', 'round');
}
if(this.params.borderOpacity > 0)
{
node.setAttribute('stroke-opacity', this.params.borderOpacity);
}

node.setFill = function (color)
{
this.setAttribute("fill", color);
if(this.getAttribute("original") === null)
{
this.setAttribute("original", color);
}
};

node.getFill = function (color)
{
return this.getAttribute("fill");
};

node.getOriginalFill = function ()
{
return this.getAttribute("original");
};

node.setOpacity = function (opacity)
{
this.setAttribute('fill-opacity', opacity);
};
}
else
{
node = this.createVmlNode('shape');
node.coordorigin = "0 0";
node.coordsize = this.width + ' ' + this.height;
node.style.width = this.width + 'px';
node.style.height = this.height + 'px';
node.fillcolor = WorldMap.defaultFillColor;
node.stroked = false;
node.path = VectorCanvas.pathSvgToVml(config.path);

var scale = this.createVmlNode('skew');
scale.on = true;
scale.matrix = '0.01,0,0,0.01,0,0';
scale.offset = '0,0';

node.appendChild(scale);

var fill = this.createVmlNode('fill');
node.appendChild(fill);

node.setFill = function (color)
{
this.getElementsByTagName('fill')[0].color = color;
};

node.getFill = function (color)
{
return this.getElementsByTagName('fill')[0].color;
};

node.setOpacity = function (opacity)
{
this.getElementsByTagName('fill')[0].opacity = parseInt(opacity * 100, 10) + '%';
};
}
return node;
},

createGroup: function (isRoot)
{
var node;
if (this.mode == 'svg')
{
node = this.createSvgNode('g');
}
else
{
node = this.createVmlNode('group');
node.style.width = this.width + 'px';
node.style.height = this.height + 'px';
node.style.left = '0px';
node.style.top = '0px';
node.coordorigin = "0 0";
node.coordsize = this.width + ' ' + this.height;
}

if (isRoot)
{
this.rootGroup = node;
}
return node;
},

applyTransformParams: function (scale, transX, transY)
{
if (this.mode == 'svg')
{
this.rootGroup.setAttribute('transform', 'scale(' + scale + ') translate(' + transX + ', ' + transY + ')');
}
else
{
this.rootGroup.coordorigin = (this.width - transX) + ',' + (this.height - transY);
this.rootGroup.coordsize = this.width / scale + ',' + this.height / scale;
}
}
};

VectorCanvas.pathSvgToVml = function (path)
{
var result = '';
var cx = 0, cy = 0, ctrlx, ctrly;

return path.replace(/([MmLlHhVvCcSs])((?:-?(?:\d+)?(?:\.\d+)?,?\s?)+)/g, function (segment, letter, coords, index)
{
coords = coords.replace(/(\d)-/g, '$1,-').replace(/\s+/g, ',').split(',');
if (!coords[0])
{
coords.shift();
}

for (var i = 0, l = coords.length; i < l; i++)
{
coords = Math.round(100 * coords);
}

switch (letter)
{
case 'm':
cx += coords[0];
cy += coords[1];
return 't' + coords.join(',');
break;

case 'M':
cx = coords[0];
cy = coords[1];
return 'm' + coords.join(',');
break;

case 'l':
cx += coords[0];
cy += coords[1];
return 'r' + coords.join(',');
break;

case 'L':
cx = coords[0];
cy = coords[1];
return 'l' + coords.join(',');
break;

case 'h':
cx += coords[0];
return 'r' + coords[0] + ',0';
break;

case 'H':
cx = coords[0];
return 'l' + cx + ',' + cy;
break;

case 'v':
cy += coords[0];
return 'r0,' + coords[0];
break;

case 'V':
cy = coords[0];
return 'l' + cx + ',' + cy;
break;

case 'c':
ctrlx = cx + coords[coords.length - 4];
ctrly = cy + coords[coords.length - 3];
cx += coords[coords.length - 2];
cy += coords[coords.length - 1];
return 'v' + coords.join(',');
break;

case 'C':
ctrlx = coords[coords.length - 4];
ctrly = coords[coords.length - 3];
cx = coords[coords.length - 2];
cy = coords[coords.length - 1];
return 'c' + coords.join(',');
break;

case 's':
coords.unshift(cy - ctrly);
coords.unshift(cx - ctrlx);
ctrlx = cx + coords[coords.length - 4];
ctrly = cy + coords[coords.length - 3];
cx += coords[coords.length - 2];
cy += coords[coords.length - 1];
return 'v' + coords.join(',');
break;

case 'S':
coords.unshift(cy + cy - ctrly);
coords.unshift(cx + cx - ctrlx);
ctrlx = coords[coords.length - 4];
ctrly = coords[coords.length - 3];
cx = coords[coords.length - 2];
cy = coords[coords.length - 1];
return 'c' + coords.join(',');
break;

default:
return false;
break;
}

return '';

}).replace(/z/g, '');
};

var WorldMap = function (params)
{
params = params || {};
var map = this;
var mapData = WorldMap.maps[params.map];

this.container = params.container;

this.defaultWidth = mapData.width;
this.defaultHeight = mapData.height;

this.color = params.color;
this.hoverColor = params.hoverColor;
this.setBackgroundColor(params.backgroundColor);

this.width = params.container.width();
this.height = params.container.height();

this.resize();

jQuery(window).resize(function ()
{
map.width = params.container.width();
map.height = params.container.height();
map.resize();
map.canvas.setSize(map.width, map.height);
map.applyTransform();
});

this.canvas = new VectorCanvas(this.width, this.height, params);
params.container.append(this.canvas.canvas);

this.makeDraggable();

this.rootGroup = this.canvas.createGroup(true);

this.index = WorldMap.mapIndex;
this.label = jQuery('<div/>').addClass('jqvmap-label').appendTo(jQuery('body'));

if(params.enableZoom)
{
jQuery('<div/>').addClass('jqvmap-zoomin').text('+').appendTo(params.container);
jQuery('<div/>').addClass('jqvmap-zoomout').html('&#x2212;').appendTo(params.container);
}

map.countries = [];

for (var key in mapData.pathes)
{
var path = this.canvas.createPath({
path: mapData.pathes[key].path
});

path.setFill(this.color);
path.id = 'jqvmap' + map.index + '_' + key;
map.countries[key] = path;

jQuery(this.rootGroup).append(path);

path.setAttribute('class', 'jqvmap-region');

if(params.selectedRegion !== null)
{
if(key.toLowerCase() == params.selectedRegion.toLowerCase())
{
path.setFill(params.selectedColor);
}
}
}

jQuery(params.container).delegate(this.canvas.mode == 'svg' ? 'path' : 'shape', 'mouseover mouseout', function (e){
var path = e.target,
code = e.target.id.split('_').pop(),
labelShowEvent = $.Event('labelShow.jqvmap'),
regionMouseOverEvent = $.Event('regionMouseOver.jqvmap');

if (e.type == 'mouseover')
{
jQuery(params.container).trigger(regionMouseOverEvent, [code, mapData.pathes

Code : Tout sélectionner

.name]); if (!regionMouseOverEvent.isDefaultPrevented()) { if (params.hoverOpacity) { path.setOpacity(params.hoverOpacity); } else if (params.hoverColor) { path.currentFillColor = path.getFill() + ''; path.setFill(params.hoverColor); } } if(params.showTooltip) { map.label.text(mapData.pathes[code].name); jQuery(params.container).trigger(labelShowEvent, [map.label, code]); if (!labelShowEvent.isDefaultPrevented()) { map.label.show(); map.labelWidth = map.label.width(); map.labelHeight = map.label.height(); } } } else { path.setOpacity(1); if (path.currentFillColor) { path.setFill(path.currentFillColor); } map.label.hide(); jQuery(params.container).trigger('regionMouseOut.jqvmap', [code, mapData.pathes[code].name]); } }); jQuery(params.container).delegate(this.canvas.mode == 'svg' ? 'path' : 'shape', 'click', function (e){ for (var key in mapData.pathes) { map.countries[key].currentFillColor = map.countries[key].getOriginalFill(); map.countries[key].setFill(map.countries[key].getOriginalFill()); } var path = e.target; var code = e.target.id.split('_').pop(); jQuery(params.container).trigger('regionClick.jqvmap', [code, mapData.pathes[code].name]); path.currentFillColor = params.selectedColor; path.setFill(params.selectedColor); }); if(params.showTooltip) { params.container.mousemove(function (e){ if (map.label.is(':visible')) { map.label.css({ left: e.pageX - 15 - map.labelWidth, top: e.pageY - 15 - map.labelHeight }); } }); } this.setColors(params.colors); this.canvas.canvas.appendChild(this.rootGroup); this.applyTransform(); this.colorScale = new ColorScale(params.scaleColors, params.normalizeFunction, params.valueMin, params.valueMax); if (params.values) { this.values = params.values; this.setValues(params.values); } this.bindZoomButtons(); WorldMap.mapIndex++; }; WorldMap.prototype = { transX: 0, transY: 0, scale: 1, baseTransX: 0, baseTransY: 0, baseScale: 1, width: 0, height: 0, countries: {}, countriesColors: {}, countriesData: {}, zoomStep: 1.4, zoomMaxStep: 4, zoomCurStep: 1, setColors: function (key, color) { if (typeof key == 'string') { this.countries[key].setFill(color); this.countries[key].setAttribute("original", color); } else { var colors = key; for (var code in colors) { if (this.countries[code]) { this.countries[code].setFill(colors[code]); this.countries[code].setAttribute("original", colors[code]); } } } }, setValues: function (values) { var max = 0, min = Number.MAX_VALUE, val; for (var cc in values) { val = parseFloat(values[cc]); if (val > max) { max = values[cc]; } if (val && val < min) { min = val; } } this.colorScale.setMin(min); this.colorScale.setMax(max); var colors = {}; for (cc in values) { val = parseFloat(values[cc]); if (val) { colors[cc] = this.colorScale.getColor(val); } else { colors[cc] = this.color; } } this.setColors(colors); this.values = values; }, setBackgroundColor: function (backgroundColor) { this.container.css('background-color', backgroundColor); }, setScaleColors: function (colors) { this.colorScale.setColors(colors); if (this.values) { this.setValues(this.values); } }, setNormalizeFunction: function (f) { this.colorScale.setNormalizeFunction(f); if (this.values) { this.setValues(this.values); } }, resize: function () { var curBaseScale = this.baseScale; if (this.width / this.height > this.defaultWidth / this.defaultHeight) { this.baseScale = this.height / this.defaultHeight; this.baseTransX = Math.abs(this.width - this.defaultWidth * this.baseScale) / (2 * this.baseScale); } else { this.baseScale = this.width / this.defaultWidth; this.baseTransY = Math.abs(this.height - this.defaultHeight * this.baseScale) / (2 * this.baseScale); } this.scale *= this.baseScale / curBaseScale; this.transX *= this.baseScale / curBaseScale; this.transY *= this.baseScale / curBaseScale; }, reset: function () { this.countryTitle.reset(); for (var key in this.countries) { this.countries[key].setFill(WorldMap.defaultColor); } this.scale = this.baseScale; this.transX = this.baseTransX; this.transY = this.baseTransY; this.applyTransform(); }, applyTransform: function () { var maxTransX, maxTransY, minTransX, minTransY; if (this.defaultWidth * this.scale <= this.width) { maxTransX = (this.width - this.defaultWidth * this.scale) / (2 * this.scale); minTransX = (this.width - this.defaultWidth * this.scale) / (2 * this.scale); } else { maxTransX = 0; minTransX = (this.width - this.defaultWidth * this.scale) / this.scale; } if (this.defaultHeight * this.scale <= this.height) { maxTransY = (this.height - this.defaultHeight * this.scale) / (2 * this.scale); minTransY = (this.height - this.defaultHeight * this.scale) / (2 * this.scale); } else { maxTransY = 0; minTransY = (this.height - this.defaultHeight * this.scale) / this.scale; } if (this.transY > maxTransY) { this.transY = maxTransY; } else if (this.transY < minTransY) { this.transY = minTransY; } if (this.transX > maxTransX) { this.transX = maxTransX; } else if (this.transX < minTransX) { this.transX = minTransX; } this.canvas.applyTransformParams(this.scale, this.transX, this.transY); }, makeDraggable: function () { var mouseDown = false; var oldPageX, oldPageY; var self = this; this.container.mousemove(function (e){ if (mouseDown) { var curTransX = self.transX; var curTransY = self.transY; self.transX -= (oldPageX - e.pageX) / self.scale; self.transY -= (oldPageY - e.pageY) / self.scale; self.applyTransform(); oldPageX = e.pageX; oldPageY = e.pageY; } return false; }).mousedown(function (e){ mouseDown = true; oldPageX = e.pageX; oldPageY = e.pageY; return false; }).mouseup(function (){ mouseDown = false; return false; }); }, bindZoomButtons: function () { var map = this; var sliderDelta = (jQuery('#zoom').innerHeight() - 6 * 2 - 15 * 2 - 3 * 2 - 7 - 6) / (this.zoomMaxStep - this.zoomCurStep); this.container.find('.jqvmap-zoomin').click(function () { if (map.zoomCurStep < map.zoomMaxStep) { var curTransX = map.transX; var curTransY = map.transY; var curScale = map.scale; map.transX -= (map.width / map.scale - map.width / (map.scale * map.zoomStep)) / 2; map.transY -= (map.height / map.scale - map.height / (map.scale * map.zoomStep)) / 2; map.setScale(map.scale * map.zoomStep); map.zoomCurStep++; jQuery('#zoomSlider').css('top', parseInt(jQuery('#zoomSlider').css('top'), 10) - sliderDelta); } }); this.container.find('.jqvmap-zoomout').click(function () { if (map.zoomCurStep > 1) { var curTransX = map.transX; var curTransY = map.transY; var curScale = map.scale; map.transX += (map.width / (map.scale / map.zoomStep) - map.width / map.scale) / 2; map.transY += (map.height / (map.scale / map.zoomStep) - map.height / map.scale) / 2; map.setScale(map.scale / map.zoomStep); map.zoomCurStep--; jQuery('#zoomSlider').css('top', parseInt(jQuery('#zoomSlider').css('top'), 10) + sliderDelta); } }); }, setScale: function (scale) { this.scale = scale; this.applyTransform(); }, getCountryPath: function (cc) { return jQuery('#' + cc)[0]; } }; WorldMap.xlink = "http://www.w3.org/1999/xlink"; WorldMap.mapIndex = 1; WorldMap.maps = {}; var ColorScale = function (colors, normalizeFunction, minValue, maxValue) { if (colors) { this.setColors(colors); } if (normalizeFunction) { this.setNormalizeFunction(normalizeFunction); } if (minValue) { this.setMin(minValue); } if (minValue) { this.setMax(maxValue); } }; ColorScale.prototype = { colors: [], setMin: function (min) { this.clearMinValue = min; if (typeof this.normalize === 'function') { this.minValue = this.normalize(min); } else { this.minValue = min; } }, setMax: function (max) { this.clearMaxValue = max; if (typeof this.normalize === 'function') { this.maxValue = this.normalize(max); } else { this.maxValue = max; } }, setColors: function (colors) { for (var i = 0; i < colors.length; i++) { colors[i] = ColorScale.rgbToArray(colors[i]); } this.colors = colors; }, setNormalizeFunction: function (f) { if (f === 'polynomial') { this.normalize = function (value) { return Math.pow(value, 0.2); }; } else if (f === 'linear') { delete this.normalize; } else { this.normalize = f; } this.setMin(this.clearMinValue); this.setMax(this.clearMaxValue); }, getColor: function (value) { if (typeof this.normalize === 'function') { value = this.normalize(value); } var lengthes = []; var fullLength = 0; var l; for (var i = 0; i < this.colors.length - 1; i++) { l = this.vectorLength(this.vectorSubtract(this.colors[i + 1], this.colors[i])); lengthes.push(l); fullLength += l; } var c = (this.maxValue - this.minValue) / fullLength; for (i = 0; i < lengthes.length; i++) { lengthes[i] *= c; } i = 0; value -= this.minValue; while (value - lengthes[i] >= 0) { value -= lengthes[i]; i++; } var color; if (i == this.colors.length - 1) { color = this.vectorToNum(this.colors[i]).toString(16); } else { color = (this.vectorToNum(this.vectorAdd(this.colors[i], this.vectorMult(this.vectorSubtract(this.colors[i + 1], this.colors[i]), (value) / (lengthes[i]))))).toString(16); } while (color.length < 6) { color = '0' + color; } return '#' + color; }, vectorToNum: function (vector) { var num = 0; for (var i = 0; i < vector.length; i++) { num += Math.round(vector[i]) * Math.pow(256, vector.length - i - 1); } return num; }, vectorSubtract: function (vector1, vector2) { var vector = []; for (var i = 0; i < vector1.length; i++) { vector[i] = vector1[i] - vector2[i]; } return vector; }, vectorAdd: function (vector1, vector2) { var vector = []; for (var i = 0; i < vector1.length; i++) { vector[i] = vector1[i] + vector2[i]; } return vector; }, vectorMult: function (vector, num) { var result = []; for (var i = 0; i < vector.length; i++) { result[i] = vector[i] * num; } return result; }, vectorLength: function (vector) { var result = 0; for (var i = 0; i < vector.length; i++) { result += vector[i] * vector[i]; } return Math.sqrt(result); } }; ColorScale.arrayToRgb = function (ar) { var rgb = '#'; var d; for (var i = 0; i < ar.length; i++) { d = ar[i].toString(16); rgb += d.length == 1 ? '0' + d : d; } return rgb; }; ColorScale.rgbToArray = function (rgb) { rgb = rgb.substr(1); return [parseInt(rgb.substr(0, 2), 16), parseInt(rgb.substr(2, 2), 16), parseInt(rgb.substr(4, 2), 16)]; }; })(jQuery); [/javascript] et avec cette page j'affiche ma carte: [javascript]<script type="text/javascript"> $(document).ready(function() { $('#francemap').vectorMap({ map: 'france_fr', hoverOpacity: 0.5, hoverColor: "#EC0000", backgroundColor: "#ffffff", color: "#a0dddb", borderColor: "#000000", infobulle: "#FFF", selectedColor: "#4ec0b9", enableZoom: false, showTooltip: true, onRegionClick: function(element, code, region) { window.location.href = '/sortie.php?region=' + region; } }); }); </script> </head> <body> <div id="francemap" style="width: 500px; height: 500px;"></div> </body>[/javascript]

ViPHP
xTG
ViPHP | 7331 Messages

22 juil. 2014, 18:43

Le code du tooltip contient ceci :
[javascript]map.label.text(mapData.pathes

Code : Tout sélectionner

.name);[/javascript] Elle t'affiche actuellement uniquement le champ name. Donc bestialement : [javascript]map.label.text(mapData.pathes[code].name + '<span style="color:white;">' + mapData.pathes[code].infobulle + '</span>');[/javascript]

Eléphant du PHP | 372 Messages

22 juil. 2014, 20:56

Ca marche je reçois bien que la valeur 4 en url c'est ce que je voulais,
par contre tout s'affiche au hover c'est à dire, par exemple:

4<span style="color:white;">Bourgogne</span>

J'ai essayé ceçi ( au hover ca m'affiche Bourgogne peut importe la région survollé :/ )
[javascript]
map.label.text(mapData.pathes

Code : Tout sélectionner

.infobulle); [/javascript] Si en + on pouvais supprimer le 4 au hover ça serait cool d'avoir que: bourgogne, merci encore et désolé pour mon peu de connaissance :roll: