Is it possible to capture an item from a json array to change an attribute from a rect in raphaels.js?

Asked

Viewed 150 times

3

I would like to make an array that can serve as a database for my map represented by these 3 rectangles. The array will contain numbers that will serve as indicators for rectangle colors, If item 1 of the array is 0 the rectangle 1 will be red, if item 2 of the array is 1 the rectangle 2 will be blue and if item 3 of the array is 2 the rectangle 3 will be yellow. I know the code may get a little complicated, but can someone tell me if it is possible to use this array as DB of my application?

var r = Raphael('map', '2048', '1024');
var set = r.set();

set.push(
  r.rect(1757.6, 39.4, 18.1, 44.9),
  r.rect(1736.5, 39.4, 18.1, 44.9),
  r.rect(1715.3, 39.4, 18.1, 44.9)
);

set.attr({
  fill: '#3953A4',
  stroke: 'none'
});

var glow;
set.hover(
  function() {
    glow = this.glow({
      width: 7,
      fill: true,
      opacity: 1,
      color: '#24d'
    });
}, function() {
     glow.remove();
});

ta here the json array

var quadra_a = {[
  "lote0" : "RED",
  "lote1" : "BLUE",
  "lote2" : "YELLOW"
]};

would like to know how to modify the map attr Fill in rapaheljs with the array item in json.

  • I don’t understand very well, you want to save this data in the browser itself?

  • If you feel safe with your "DB" in memory, why not?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.