WTS - Apt node

by Paulo Ávila

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<div id="apt-nodes"></div>

JavaScript

var radius = 100,
    r = Raphael("apt-nodes", radius * 2, radius * 2),
    angle = 0;

houses = 10;


function createAptNode (x, y) {
    aptNode = r.image('http://sbs.waytostay.com/ITC/map-marker-house.png', x, y, 32, 32);

    aptNode.mouseover(function () {
        console.log("house over", x, y);
    });

    aptNode.mouseout(function () {
        console.log("house out", x, y);
    });

    aptNode.click(function () {
        console.log("house clicked", x, y);
    });
}

for (var i = 0; i < houses; i++) {
    x = radius + (radius * Math.cos(2 * Math.PI * i / houses));
    y = radius + (radius * Math.sin(2 * Math.PI * i / houses));
    createAptNode(x, y);

    r.path('M' + radius + ',' + radius + 'L,' + x + ',' + y).attr({fill: "none", "stroke-width": 2})
}

var s = r.set();
s.push(r.path("M320,240L,320,430").attr({fill: "none", "stroke-width": 2}));

//s.push(r.circle(320, 450, 20).attr({fill: "none", "stroke-width": 2}));
//s.push(r.circle(320, 240, 5).attr({fill: "none", "stroke-width": 10}));

s.attr({stroke: Raphael.getColor()});