Dav*_*ira 2 javascript polygon
任何人都知道如何在没有地图的情况下从谷歌地图中绘制带有GPolygon的多边形,在其他元素中?或者任何人都知道任何框架与GPolygon相同的功能吗?
我想在自定义元素上有这个" 绘制多边形 ",比如div:
<div id="MyArea"></div>
Run Code Online (Sandbox Code Playgroud)
查看Raphael,这是一个javascript库,它在IE和SVG中包含符合标准的浏览器中的VML.它使用起来相当容易并且记录完备.
当然,path元素(用于绘制多边形和折线)使用SVG路径字符串语法,这有点神秘但很容易理解.您当然可以扩展Raphael以使用更简单的语法:
Raphael.fn.polygon = function () { // supply x,y coordinates as arguments
var self = this.path();
self.coords = [];
for (var i=0;i<arguments.length;i++) self.coords.push(arguments[i]);
self.update = function () {
var pathlist = [];
// the M command moves the cursor:
pathlist.push('M'+self.coords[0]+' '+self.coords[1]);
// the L command draws a line:
pathlist.push('L');
// Now push the remaining coordinates:
for (var i=2;i<self.coords.length;i++) {
pathlist.push(self.coords[i]);
}
// the Z command closes the path:
pathlist.push('Z');
self.attr('path',pathlist.join(' '));
}
self.update();
return self;
}
Run Code Online (Sandbox Code Playgroud)
哪个应该允许你这样做:
<div id="MyArea"></div>
<script>
var paper = Raphael("MyArea",640,480);
var mypolygon = paper.polygon(
10, 10,
20, 20,
10, 30
);
// you can even modify it after creation:
mypolygon.coords.push(15,20);
mypolygon.update();
</script>
Run Code Online (Sandbox Code Playgroud)
或者如果你不喜欢我的话,可以创建自己的多边形API.
编辑:修复了一些小错误.
| 归档时间: |
|
| 查看次数: |
2725 次 |
| 最近记录: |