Can't understand why Konva text do not hide - html

I want hide and show a Konva.text when I drag a rect -> show text and drag end hide the text but I can't understand why when I drag end the Konva.text do not hide.
var stage = new Konva.Stage({ container: 'container', width: 400, height: 250 });
var layer2 = new Konva.Layer(); var groupe = new Konva.Group({})
var lineV = new Konva.Rect({ x: 50, y: 50, width: 70, height: 50, draggable: true, stroke: 'black'}); groupe.add(lineV)
var info = new Konva.Text({
text: 'info',
visible: false,
stroke: '#fff', fontSize: 35, fontFamily: 'Calibri', fill: '#000', align: 'center', name: "infoBulle"});
layer2.add(info);
groupe.on('dragstart', function () {
console.log("drag")
info.visible(true);
});
groupe.on('dragend', function () {
console.log("drop");
info.visible(false)
console.log(info.isVisible());
});
stage.add(layer2.add(groupe))
stage.draw();
<script src="https://unpkg.com/konva#2.4.2/konva.min.js"></script>
<div id="container" width="400" height="250" style="border: 2px solid red;"></div>

You need to redraw a layer every time you update something on it. The first time you show the text update is visible, because Konva updates layer automatically on dragmove action.
var stage = new Konva.Stage({ container: 'container', width: 400, height: 250 });
var layer2 = new Konva.Layer(); var groupe = new Konva.Group({})
var lineV = new Konva.Rect({ x: 50, y: 50, width: 70, height: 50, draggable: true, stroke: 'black'}); groupe.add(lineV)
var info = new Konva.Text({
text: 'info',
visible: false,
stroke: '#fff', fontSize: 35, fontFamily: 'Calibri', fill: '#000', align: 'center', name: "infoBulle"});
layer2.add(info);
groupe.on('dragstart', function () {
console.log("drag")
info.visible(true);
layer2.batchDraw();
});
groupe.on('dragend', function () {
console.log("drop");
info.visible(false)
layer2.batchDraw();
console.log(info.isVisible());
});
stage.add(layer2.add(groupe))
stage.draw();
<script src="https://unpkg.com/konva#2.4.2/konva.min.js"></script>
<div id="container" width="400" height="250" style="border: 2px solid red;"></div>

Related

Can't implement two infoboxes with google maps api

I'm using the infobox plugin in the google maps api to create customized infoboxes for places, yet it's only working for the first one (the one named "west").
When I replicate the code for it using different coordinates and names, it doesn't open when I click the marker.
Here's the code:
function initMap() {
var west = {
lat: 39.288682,
lng: -74.565635
};
var firststreetbeach = {
lat: 39.2807806,
lng: -74.5575138
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 14,
center: west,
mapTypeId: google.maps.MapTypeId.HYBRID,
styles: [
{ featureType: "poi",
elementType: "labels",
stylers: [
{ visibility: "off" }]}]
});
var marker = new google.maps.Marker({
map: map,
draggable: false,
position: west,
visible: true
});
marker.setTitle("west");
var firststreetbeachMARKER = new google.maps.Marker({
position: firststreetbeach,
map: map
});
firststreetbeachMARKER.setTitle("First Street Beach");
var boxText = document.createElement("div");
boxText.style.cssText = "border: 4px solid black; margin-top: 8px; background: deepskyblue; padding: 3px;";
boxText.innerHTML =
`<h1><div style="font-family: 'Permanent Marker', cursive;">
west</div></h1><p>
<b>Sick Place</b></p>`
var firststreetbeachBOX = document.createElement("div");
firststreetbeachBOX.style.cssText = "border: 4px solid black; margin-top: 8px; background: deepskyblue; padding: 3px;";
firststreetbeachBOX.innerHTML =
`<h1><div style="font-family: 'Permanent Marker', cursive;">
First Street Beach</div></h1><p>
<b>Guarded Beach, Can Only Be Surfed Before The Life Guards Show Up, Or After.(Life Guards On Duty 10Am-5:30PM Starting May 25-End Of Summer)</b></p>`
var myOptions = {
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-120, 0),
zIndex: null,
boxStyle: {
background: "url('tipbox.gif') no-repeat",
opacity: 0.90,
width: "235px"
},
closeBoxMargin: "10px 2px 2px 2px",
closeBoxURL: "https://lh3.google.com/u/0/d/1vBKI8gNIslaOItFoenaRADfZ3Mh4hrM5=w50-h48-p-k-nu-iv1",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
google.maps.event.addListener(marker, "click", function(e) {
ib.open(map, this);
});
var ib = new InfoBox(myOptions);
ib.open(map, this);
map.panTo(ib.getPosition())
var myOptionsa = {
content: firststreetbeachBOX,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-120, 0),
zIndex: null,
boxStyle: {
background: "url('tipbox.gif') no-repeat",
opacity: 0.90,
width: "235px"
},
closeBoxMargin: "10px 2px 2px 2px",
closeBoxURL: "https://lh3.google.com/u/0/d/1vBKI8gNIslaOItFoenaRADfZ3Mh4hrM5=w50-h48-p-k-nu-iv1",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
google.maps.event.addListener(firststreetbeachBOX, "click", function(e) {
ib.open(map, this);
});
var id = new InfoBox(myOptionsa);
id.open(map, this);
map.panTo(id.getPosition())
}
google.maps.event.addDomListener(window, 'load', initMap);
JSFIDDLE: https://jsfiddle.net/kaidemarco/06wpx75j/228/
I get a javascript error on your fiddle: Uncaught TypeError: anchor.getPosition is not a function. You have a number of typos in your code:
firststreetbeachBOX is an InfoBox, not a google.maps.Marker. That should be firststreetbeachMARKER.
google.maps.event.addListener(firststreetbeachMARKER, "click", function(e) {
ib.open(map, this);
});
should be:
google.maps.event.addListener(firststreetbeachBOX, "click", function(e) {
ib.open(map, this);
});
Currently there is only one InfoBox reference ib. If you only want one to open on clicks, that is fine, but if you want the correct content, you need to reset the options in the onclick function:
google.maps.event.addListener(firststreetbeachMARKER, "click", function(e) {
ib.open(map, this);
});
should be:
google.maps.event.addListener(firststreetbeachMARKER, "click", function(e) {
ib.setOptions(myOptionsa);
ib.open(map, this);
});
In the ib.open(map, this) calls that are outside of the onclick function, the this is not a valid anchor. That should be the appropriate google.maps.Marker object:
// the first should be:
ib.open(map, marker);
// the second should be:
id.open(map, firststreetbeachMARKER);
proof of concept fiddle
code snippet:
function initMap() {
var west = {
lat: 39.288682,
lng: -74.565635
};
var firststreetbeach = {
lat: 39.2807806,
lng: -74.5575138
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 14,
center: west,
mapTypeId: google.maps.MapTypeId.HYBRID,
styles: [{
featureType: "poi",
elementType: "labels",
stylers: [{
visibility: "off"
}]
}]
});
var marker = new google.maps.Marker({
map: map,
draggable: false,
position: west,
visible: true
});
marker.setTitle("west");
var firststreetbeachMARKER = new google.maps.Marker({
position: firststreetbeach,
map: map
});
firststreetbeachMARKER.setTitle("First Street Beach");
var boxText = document.createElement("div");
boxText.style.cssText = "border: 4px solid black; margin-top: 8px; background: deepskyblue; padding: 3px;";
boxText.innerHTML =
`<h1><div style="font-family: 'Permanent Marker', cursive;">
west</div></h1><p>
<b>Sick Place</b></p>`
var firststreetbeachBOX = document.createElement("div");
firststreetbeachBOX.style.cssText = "border: 4px solid black; margin-top: 8px; background: deepskyblue; padding: 3px;";
firststreetbeachBOX.innerHTML =
`<h1><div style="font-family: 'Permanent Marker', cursive;">
First Street Beach</div></h1><p>
<b>Guarded Beach, Can Only Be Surfed Before The Life Guards Show Up, Or After.(Life Guards On Duty 10Am-5:30PM Starting May 25-End Of Summer)</b></p>`
var myOptions = {
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-120, 0),
zIndex: null,
boxStyle: {
background: "url('tipbox.gif') no-repeat",
opacity: 0.90,
width: "235px"
},
closeBoxMargin: "10px 2px 2px 2px",
closeBoxURL: "https://lh3.google.com/u/0/d/1vBKI8gNIslaOItFoenaRADfZ3Mh4hrM5=w50-h48-p-k-nu-iv1",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
google.maps.event.addListener(marker, "click", function(e) {
ib.setOptions(myOptions);
ib.open(map, this);
});
var ib = new InfoBox(myOptions);
ib.open(map, marker);
map.panTo(ib.getPosition())
var myOptionsa = {
content: firststreetbeachBOX,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-120, 0),
zIndex: null,
boxStyle: {
background: "url('tipbox.gif') no-repeat",
opacity: 0.90,
width: "235px"
},
closeBoxMargin: "10px 2px 2px 2px",
closeBoxURL: "https://lh3.google.com/u/0/d/1vBKI8gNIslaOItFoenaRADfZ3Mh4hrM5=w50-h48-p-k-nu-iv1",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
google.maps.event.addListener(firststreetbeachMARKER, "click", function(e) {
ib.setOptions(myOptionsa);
ib.open(map, this);
});
var id = new InfoBox(myOptionsa);
id.open(map, firststreetbeachMARKER);
map.panTo(id.getPosition())
}
google.maps.event.addDomListener(window, 'load', initMap);
html,
body,
#map {
height: 100%;
margin: 0;
padding: 0;
}
.action-btns {
float: left;
width: 70px;
overflow: hidden;
position: relative;
top: 12px;
left: 6px;
}
<div id="map"></div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/googlemaps/v3-utility-library#master/infobox/src/infobox.js"></script>
<link href="https://fonts.googleapis.com/css?family=Permanent+Marker" rel="stylesheet">

Google charts candlestick strip out every thing but the candle bar

I find that the google documents are i bit limited in explaining if this is possible
how would you strip out all the empty space in a google candlestick chart.
Then fit the candlestick over a background element
code
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
//label,low,opening,closing,high
['09', 1.14799, 1.15027, 1.14848, 1.15275],
//['15', 1.14775, 1.15027, 1.14776, 1.15275],
//['20', 1.14772, 1.15027, 1.14807, 1.15275],
//1.15275 1.14799 1.15027 1.14
// Treat first row as data as well.
], true);
var options = {
legend:'none',
backgroundColor: { fill:'#515151' },
'width': 100,
'height': 340,
chartArea:{left:50,top:20,width:'50%',height:'75%'},
candlestick: {
risingColor: {stroke: '#4CAF50', fill: '#4CAF50'},
fallingColor: {stroke: '#F44336', fill: '#F44336'}
},
colors: ['white'],
hAxis: {title: 'get rid of this space', textPosition: 'none', gridlines: {color: '#515151', count: 0}},
vAxis: {title: 'get rid of this space', textPosition: 'none', gridlines: {color: '#515151', count: 0}},
title: 'get rid of this space'
};
var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<style>
.background01{background-image: url("../img/Candle_Box_Tag.png")}
</style>
</head>
<body>
<div class="background01" id="chart_div"></div>
</body>
</html>
use the chartArea option to stretch the chart to the edges of the container
chartArea: {
backgroundColor: 'transparent',
top: 0,
left: 0,
bottom: 0,
right: 0,
height: '100%',
width: '100%',
},
set the background and various other colors to 'transparent',
then you can apply any background to the <div> element
see following working snippet...
google.charts.load('current', {
packages:['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
//label,low,opening,closing,high
['09', 1.14799, 1.15027, 1.14848, 1.15275],
//['15', 1.14775, 1.15027, 1.14776, 1.15275],
//['20', 1.14772, 1.15027, 1.14807, 1.15275],
//1.15275 1.14799 1.15027 1.14
// Treat first row as data as well.
], true);
var options = {
chartArea: {
backgroundColor: 'transparent',
top: 0,
left: 0,
bottom: 0,
right: 0,
height: '100%',
width: '100%',
},
backgroundColor: { fill:'transparent' },
legend:'none',
width: 50,
height: 340,
candlestick: {
risingColor: {stroke: '#4CAF50', fill: '#4CAF50'},
fallingColor: {stroke: '#F44336', fill: '#F44336'}
},
colors: ['white'],
hAxis: {textPosition: 'none'},
vAxis: {
textPosition: 'none',
gridlines: {color: 'transparent', count: 0},
minorGridlines: {color: 'transparent', count: 0}
}
};
var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
#chart_div {
background: #515151;
display: inline-block;
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

how to place infowindow for the label on google map

I am plotting the markers on google map using infobox.js not using https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple which is working fine the code is as shown below
<!DOCTYPE html>
<html>
<head lang="en">
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<style>
html,
body,
#map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
</style>
<script>
var map;
var AutoCircle = [
{
"latitude": '21.170931',
"longitude": '72.855607',
},
{
"latitude": '21.192533',
"longitude": '72.848750',
},
{
"latitude": '21.190178',
"longitude": '72.797578',
}
];
function initMap() {
// Create the map.
map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: {lat:21.181272, lng:72.835066},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
addLabel(AutoCircle);
}
// Construct the circle for each value in citymap.
// Note: We scale the area of the circle based on the population.
function addLabel(circleArray){
for (var i=0;i<circleArray.length;i++) {
var circleData = circleArray[i]
var circleLatlng = new google.maps.LatLng(circleData.latitude, circleData.longitude);
// Add the circle for this city to the map.
var myOptions = {
content: 300+"*"+"<br>autos",
boxStyle: {
background: '#FFFFFF',
color: 'red',
textAlign: "center",
fontSize: "8pt",
width: "50px"
},
disableAutoPan: true,
pixelOffset: new google.maps.Size(-25, -10), // left upper corner of the label
position: new google.maps.LatLng(circleArray[i].latitude,
circleArray[i].longitude),
closeBoxURL: "",
isHidden: false,
pane: "floatPane",
zIndex: 100,
enableEventPropagation: true
};
var ib = new InfoBox(myOptions);
ib.open(map);
}
}
google.maps.event.addDomListener(window, "load", initMap);
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
how to add the infowindow which we click on the label
Please help
I couldn't make it work with a dynamically rendered div from a text string (if you use the domready event, you should be able to access the node by its id, not sure why that doesn't work), If I create the <div> as a DOM node, I can add a listener to it.
code snippet:
function addLabel(circleArray) {
for (var i = 0; i < circleArray.length; i++) {
var circleData = circleArray[i]
var circleLatlng = new google.maps.LatLng(circleData.latitude, circleData.longitude);
// Create div for infoBubble
var div = document.createElement("div");
// create text node
var text = document.createTextNode(300 + "*" + "\nautos\n" + circleData.content);
// append text to div
div.appendChild(text);
// add click listener to div
google.maps.event.addDomListener(div, 'click', (function(i, latLng) {
return function() {
infowindow.setContent('clicked on ' + i);
infowindow.setPosition(latLng);
infowindow.open(map);
}
}(i, circleLatlng)));
var myOptions = {
content: div, // use DOM node for content
boxStyle: {
background: '#FFFFFF',
color: 'red',
textAlign: "center",
fontSize: "8pt",
width: "50px"
},
disableAutoPan: true,
pixelOffset: new google.maps.Size(-25, -10), // left upper corner of the label
position: new google.maps.LatLng(circleArray[i].latitude,
circleArray[i].longitude),
closeBoxURL: "",
isHidden: false,
pane: "floatPane",
zIndex: 100,
enableEventPropagation: true
};
var ib = new InfoBox(myOptions);
ib.open(map);
}
}
var map;
var infowindow = new google.maps.InfoWindow();
function initMap() {
// Create the map.
map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: {
lat: 21.181272,
lng: 72.835066
},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
addLabel(AutoCircle);
}
google.maps.event.addDomListener(window, "load", initMap);
var AutoCircle = [{
"latitude": '21.170931',
"longitude": '72.855607',
"content": "content0"
}, {
"latitude": '21.192533',
"longitude": '72.848750',
"content": "content1"
}, {
"latitude": '21.190178',
"longitude": '72.797578',
"content": "content2"
}];
html,
body,
#map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry,places&ext=.js"></script>
<script src="https://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<div id="map"></div>
If I understand your code correctly, the 'label' you refer to is an instance of the InfoBox class, which according to its docs, "fires the same events as a google.maps.InfoWindow":
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html
So you should be able to do something like:
var infowindow = new google.maps.InfoWindow({
content: 'foo'
});
ib.addListener('click', function() {
infowindow.open(map, this);
});

KineticJS Group

I am making an interactive world map in HTML5. I am using KineticJS to create the polygons of the countries, I currently have Australia and New Zealand. However I want it so if the mouse is over either Australia or New Zealand, they both will be highlighted. I don't know how to use Groups in KineticJS but this is how I tried (i used ellipses for the points because there are a lot of coordinates):
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
#container {
background-image: url('world_map.png');
width: 1026px;
height: 540px;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.2.min.js"> </script>
<script defer="defer">
var stage = new Kinetic.Stage({
container: 'container',
width: 1026,
height: 540
});
var layer = new Kinetic.Layer();
var nznorth = new Kinetic.Polygon({
points: [...],
fill: '#ffffff',
stroke: 'black',
strokeWidth: 1
});
var nzsouth = new Kinetic.Polygon({
points: [...],
fill: '#ffffff',
stroke: 'black',
strokeWidth: 1
});
var ausmain = new Kinetic.Polygon({
points: [...],
fill: '#ffffff',
stroke: 'black',
strokeWidth: 1
});
var aus = new Kinetic.Group();
aus.add(ausmain);
aus.add(nznorth);
aus.add(nzsouth);
aus.on('mouseover', function() {
this.setFill('blue');
layer.draw();
});
aus.on('mouseout', function() {
this.setFill('#ffffff');
layer.draw();
});
layer.add(aus);
stage.add(layer);
</script>
</body>
</html>
How should I implement the group in KineticJS?
You just about have it !
When you handle your mouse events, set the fill on both Australia and New Zealand—not on the group.
group.on("mouseover",function(){
australia.setFill("blue");
newzealand.setFill("blue");
layer.draw();
console.log("over");
});
group.on("mouseout",function(){
australia.setFill("skyblue");
newzealand.setFill("skyblue");
layer.draw();
console.log("out");
});
Here is code and a Fiddle: http://jsfiddle.net/m1erickson/LXvkg/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Prototype</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.1.min.js"></script>
<style>
#container{
border:solid 1px #ccc;
margin-top: 10px;
}
</style>
<script>
$(function(){
var stage = new Kinetic.Stage({
container: 'container',
width: 400,
height: 400
});
var layer = new Kinetic.Layer();
stage.add(layer);
stage.draw();
var group=new Kinetic.Group();
layer.add(group);
var australia = new Kinetic.Rect({
x: 20,
y: 20,
width: 150,
height: 100,
fill: "skyblue",
stroke: "lightgray",
strokeWidth: 3
});
group.add(australia);
var newzealand = new Kinetic.Rect({
x: 250,
y: 110,
width: 20,
height: 50,
fill: "skyblue",
stroke: "lightgray",
strokeWidth: 3
});
group.add(newzealand);
layer.draw();
group.on("mouseover",function(){
australia.setFill("blue");
newzealand.setFill("blue");
layer.draw();
console.log("over");
});
group.on("mouseout",function(){
australia.setFill("skyblue");
newzealand.setFill("skyblue");
layer.draw();
console.log("out");
});
}); // end $(function(){});
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
This tutorial should help you to implement Kinetic groups.
http://www.html5canvastutorials.com/kineticjs/html5-canvas-complex-shapes-using-groups-with-kineticjs/

transitionTo method of kineticJs not working on click event

I am using transitionTo method of kineticJS to show animated rotation of a shape on click event of mouse. It works fine if we click the shape first time but then on subsequent clicks it does not rotate the shape. I want to show transition(rotation) of the shape by some angle every time I click on it. Please let me know the mistake I am making and how can I correct it??
This is the code I am using
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
canvas {
border: 1px solid #9C9898;
}
</style>
<script src="http://www.html5canvastutorials.com/libraries/kinetic-v3.9.6.js"></script>
<script>
window.onload = function() {
var stage = new Kinetic.Stage({
container: "container",
width: 578,
height: 200
});
var layer = new Kinetic.Layer({
x:stage.getWidth()/3 ,
y: stage.getHeight()/3
});
var rect = new Kinetic.Rect({
x: 239,
y: 75,
width: 100,
height: 50,
fill: "#00D2FF",
stroke: "black",
strokeWidth: 4,
centerOffset: [50, 100]
});
// add the shape to the layer
layer.add(rect);
// add the layer to the stage
stage.add(layer);
rect.on("click", function() {
rect.transitionTo({
rotation:2*Math.PI,
duration:1
});
stage.draw();
});
};
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
Try this:
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
canvas {
border: 1px solid #9C9898;
}
</style>
<script src="http://www.html5canvastutorials.com/libraries/kinetic-v3.10.0.js"></script>
<script>
window.onload = function() {
var angle = 0;
var stage = new Kinetic.Stage({
container: "container",
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var rect = new Kinetic.Rect({
x: 239,
y: 75,
width: 100,
height: 50,
fill: "#00D2FF",
stroke: "black",
strokeWidth: 4
});
layer.add(rect);
stage.add(layer);
rect.on("click", function() {
angle += 2;
rect.transitionTo({
rotation: Math.PI * angle,
duration:1
});
});
};
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
The click was working just fine, however you were telling it to rotate to the same angel every time (why it only animates on the first click). I added a variable so that the angle increases 360 degrees every time you click on it.