服务/制作美国各州剪影的最佳方式?

发布于 2024-12-24 21:13:09 字数 1803 浏览 1 评论 0原文

我负责提供页面来显示美国各州选举的初步结果。每个页面都需要一个带有州图像的横幅,大约 250 像素 x 250 像素。现在我需要做的就是弄清楚如何提供/生成这些图像...

  1. 我已经深入研究了 Protovis 并认为我 可能会解除州坐标轮廓 - 我必须 手动转换坐标数据以对齐和调整大小 正确地(ick)

  2. 在聪明/野蛮光谱的另一端是一个巨大的精灵 或一系列精灵。即使使用 png 8 压缩,文件大小为 由 50 个不重叠的 250x250px 精灵组成的网格是一个问题,并且 遗憾的是这样的文件似乎不存在,所以我必须创建它 从手上。也令人不愉快。

谁有更好的主意?

回答:正确的解决方案是切换到 d3。

我们现在入侵的内容:

 drawStateInBox = function(box, state, color) {
   var w = $("#" + box).width(),
           h = $("#" + box).height(),
           off_x = 0,
           off_y = 0;
           borders = us_lowres[state].borders;

   //Preserve aspect ratio
   delta_lat = pv.max(borders[0], function(b) b.lat) - pv.min(borders[0], function(b) b.lat);
   delta_lng = pv.max(borders[0], function(b) b.lng) - pv.min(borders[0], function(b) b.lng);

   if (delta_lat / h > delta_lng / w) {
     scaled_h = h;
     scaled_w = w * delta_lat / delta_lng;
     off_x = (w - scaled_w) / 2;
   } else {
     scaled_h = h * delta_lat / delta_lng;
     scaled_w = w;
     off_y = (h - scaled_h) / 2;
   }

   var scale = pv.Geo.scale()
           .domain(us_lowres[state].borders[0])
           .range({x: off_x, y: off_y},
           {x: scaled_w + off_x, y: scaled_h + off_y});


   var vis = new pv.Panel(state)
           .canvas(box)
           .width(w)
           .height(h)
           .data(borders)
           .add(pv.Line)
           .data(function(l) l)
           .left(scale.x)
           .top(scale.y)
           .fillStyle(function(d, l, c) {
             return(color);
           })
           .lineWidth(0)
           .strokeStyle(color)
           .antialias(false);

   vis.render();
 };

I'm responsible for delivering pages to display primary results for the US elections State by State. Each page needs a banner with an image of the State, approx 250px by 250px. Now all I need to do is figure out how to serve / generate those images...

  1. I've dug into the docs / examples for Protovis and think I
    could probably lift the State coordinate outlines- I would have to
    manually transform the coordinate data to be justified and sized
    properly (ick)

  2. At the other end of the clever/brute spectrum is an enormous sprite
    or series of sprites. Even with png 8 compression the file size of
    a grid of 50 non-overlapping 250x250px sprites is a concern, and
    sadly such a file doesn't seem to exist so I'd have to create it
    from hand. Also unpleasant.

Who's got a better idea?

Answered: the right solution is to switch to d3.

What we hacked in for now:

 drawStateInBox = function(box, state, color) {
   var w = $("#" + box).width(),
           h = $("#" + box).height(),
           off_x = 0,
           off_y = 0;
           borders = us_lowres[state].borders;

   //Preserve aspect ratio
   delta_lat = pv.max(borders[0], function(b) b.lat) - pv.min(borders[0], function(b) b.lat);
   delta_lng = pv.max(borders[0], function(b) b.lng) - pv.min(borders[0], function(b) b.lng);

   if (delta_lat / h > delta_lng / w) {
     scaled_h = h;
     scaled_w = w * delta_lat / delta_lng;
     off_x = (w - scaled_w) / 2;
   } else {
     scaled_h = h * delta_lat / delta_lng;
     scaled_w = w;
     off_y = (h - scaled_h) / 2;
   }

   var scale = pv.Geo.scale()
           .domain(us_lowres[state].borders[0])
           .range({x: off_x, y: off_y},
           {x: scaled_w + off_x, y: scaled_h + off_y});


   var vis = new pv.Panel(state)
           .canvas(box)
           .width(w)
           .height(h)
           .data(borders)
           .add(pv.Line)
           .data(function(l) l)
           .left(scale.x)
           .top(scale.y)
           .fillStyle(function(d, l, c) {
             return(color);
           })
           .lineWidth(0)
           .strokeStyle(color)
           .antialias(false);

   vis.render();
 };

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆里有你的影子 2024-12-31 21:13:09

d3 似乎有能力制作类似于您想要的地图。该示例显示了县和州,因此您只需省略县,然后以正确的格式提供选举结果。

d3 seems to have the capability to do maps similar to what you want. The example shows both counties and states so you would just omit the counties and then provide the election results in the right format.

拥醉 2024-12-31 21:13:09

50states.com 上有一组地图,例如 http://www.50states.com/maps /alabama.htm,大约5KB。那么,整个集合大约有 250KB。既然您提到单独使用它们,这就是您的答案。

或者你除了展示轮廓之外还做了更多的事情吗?

There is a set of maps on 50states.com, e.g. http://www.50states.com/maps/alabama.htm, which is about 5KB. Roughly, then, that's 250KB for the whole set. Since you mention using these separately, there's your answer.

Or are you doing more with this than just showing the outline?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文