1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/*******************************************************************************
Usage:
var map = new CanvasMap({
// The ID of the element being transformed into a map
id : "",
// The width of the map (in px)
width: 800,
// The height of the map (in px)
height: 800,
// The X value of the starting map position
startX: 0,
// The Y value of the starting map position
startY: 0,
// Boolean true if the map should animate to a stop
scrolling: true,
// The time (in ms) that the above scrolling lasts
scrollTime: 300,
// Boolean true if the map disallows moving past its edges
lockEdges: true,
// The CSS class attached to the wrapping map div
cssClass: ""
});
*******************************************************************************/
function CanvasMap(param) {
(...)
/***************************************************************************
* Name : AddListener()
* Description (EN) : Adds an event listener to the specified element.
* Description (FR) : Ajoute un suivi d'événement à un élément spécifique.
* Parameters (EN) : element - The element for which the listener is being added
* event - The event for which the listener is being added
* f - The function being called each time that the event occurs
* Parameters (FR) : element - L'élément pour lequel un suivi est ajouté
* event - L'événement pour lequel un suivi est ajouté
* f - La fonction appelée chaque fois que l'événement se produit
**************************************************************************/
function AddListener(element, event, f) {
if(element.attachEvent) {
element["e" + event + f] = f;
element[event + f] = function () {
element["e" + event + f](window.event)
};
element.attachEvent("on" + event, element[event + f])
} else element.addEventListener(event, f, false)
}
(...)
var m = this;
m.map = document.getElementById(param.id); //
m.width = typeof param.width == "undefined" ? 800 : param.width;
m.height = typeof param.height == "undefined" ? 800 : param.height;
m.scrolling = typeof param.scrolling == "undefined" ? true : param.scrolling;
m.scrollTime = typeof param.scrollTime == "undefined" ? 300 : param.scrollTime;
m.lockEdges = typeof param.lockEdges == "undefined" ? true : param.lockEdges;
m.viewingBox = document.createElement("div");
if(typeof param.cssClass != "undefined") m.viewingBox.className = param.cssClass;
m.mousePosition = new Coordinate;
m.mouseLocations = [];
m.velocity = new Coordinate;
m.mouseOver = true; // ajoute le curseur dndUp
m.mouseDown = false;
m.timerId = -1;
m.timerCount = 0;
m.map.parentNode.replaceChild(m.viewingBox, m.map);
m.viewingBox.appendChild(m.map);
m.viewingBox.style.overflow = "hidden";
m.viewingBox.style.width = m.width + "px";
m.viewingBox.style.height = m.height + "px";
m.viewingBox.style.position = "relative";
m.map.style.position = "absolute";
MoveMap(typeof param.startX == "undefined" ? 0 : -param.startX, typeof param.startY == "undefined" ? 0 : -param.startY);
(...)
/***************************************************************************
* click event handler / gestionnaire d'événement click
**************************************************************************/
AddListener(element.id, "click", function () {
// récupérer les coordonnées
var coordonnees = this.getAttribute('coords').split(',');
alert(coordonnees[0]+' - '+coordonnees[1]);
});
}; |
Partager