I want to show the tooltip on the dynamic images inside the canvas. Here is path of the image on which I want to show the tooltip.(I want to show the tooltip on the Green and Gray images). enter link description here
Here is my code I am using to do the so with the help of kinetic.js.
$("#tabs li").each(function () {
$(this).live("click", function () {
var tabname = $(this).find("a").attr('name');
tabname = $.trim(tabname.replace("#tab", ""));
var tabId = $(this).find("a").attr('href');
tabId = $.trim(tabId.replace("#", ""));
$.ajax({
url: "/Home/GetTabsDetail",
dataType: 'json',
type: 'GET',
data: { tabId: tabId },
cache: false,
success: function (data) {
var bayStatus = [];
var i = 0;
var image_array = [];
var BayExist = false;
var BayCondition;
var imgSrc;
var CanvasBacgroundImage;
var _X;
var _bayNumber;
var _Y;
var _ZoneName;
$(data).each(function (i, val) {
i = i + 1;
if (!BayExist) {
bayStatus = val.BayStatus;
CanvasBacgroundImage = val.TabImageLocation;
BayExist = true;
}
$.each(val, function (k, v) {
if (k == "BayNumber") {
BayCondition = bayStatus[v];
_bayNumber = v;
if (BayCondition == "O")
imgSrc = "../../images/Parking/OccupiedCar.gif"
else if (BayCondition == "N")
imgSrc = "../../images/Parking/OpenCar.gif";
}
if (k == "BayX")
_X = v;
if (k == "BayY")
_Y = v;
if (k == "ZoneName")
_ZoneName = v;
});
image_array.push({ img: imgSrc, xAxis: _X, yAxis: _Y, toolTip: _bayNumber, ZoneName: _ZoneName });
});
var imageUrl = CanvasBacgroundImage;
$('#tab' + tabId).css('background-image', 'url("../../images/Parking/' + imageUrl + '")');
var _timer = setInterval(function () {
var stage = new Kinetic.Stage({
container: 'tab' + tabId,
width: 700,
height: 308
});
var layer = new Kinetic.Layer();
var planetOverlay;
function writeMessage(message) {
text.setText(message);
layer.draw();
}
var text = new Kinetic.Text({
x: 140,
y: 0,
fontFamily: 'Arial',
fontSize: 20,
text: '',
fill: '#000',
width: 740,
height: 60,
align: 'left',
padding: 40,
});
for (i = 0; i < image_array.length; i++) {
img = new Image();
debugger;
img.src = image_array[i].img;
planetOverlay = new Kinetic.Image({
x: image_array[i].xAxis,
y: image_array[i].yAxis,
image: img,
height: 18,
width: 18,
id: image_array[i].toolTip,
name: image_array[i].ZoneName
});
planetOverlay.on('mouseover', function () {
writeMessage("Bay: " + this.getId() + " , Zone: " + this.getName());
});
planetOverlay.on('mouseout', function () {
writeMessage('');
});
planetOverlay.createImageHitRegion(function () {
layer.draw();
});
layer.add(planetOverlay);
layer.add(text);
stage.add(layer);
}
clearInterval(_timer);
//$("#tab3 .kineticjs-content").find("canvas").css('background-image', 'url("' + imageUrl + '")');
}, 1000)
},
error: function (result) {
alert('error');
}
});
});
});
Here is the html section for this.
<div style="background-position: center center; margin: 0px auto; padding-top: 50px; background-repeat: no-repeat; width: 700px; height: 308px; display: block; background-image: url("../../images/Parking/Garage-Floor-Plan.png");" id="tab3"><div style="position: relative; display: inline-block; width: 700px; height: 308px;" class="kineticjs-content" role="presentation"><canvas style="padding: 0px; margin: 0px; border: 0px none; background: none repeat scroll 0% 0% transparent; position: absolute; top: 0px; left: 0px; width: 700px; height: 308px;" width="700" height="308"></canvas></div></div>
This above mentioned code is working now for single message to be shown on every image mouseover but on the mentioed co-oridinates , Here I want to show the unique message on mouseover of every single image(Green/Gray in the pic) as in given pic and just above the images I want to show the tooltip.
Moreover it takes double clicks to bind the images to canvas of the tab.
Thanks for any help in advance.