ActionScript:如何推送到多维数组并稍后检索一行“行”
我正在阅读一组纬度和纬度定义多边形区域的经度坐标。它们与区域 ID 相关联,我从 SQL 数据库中检索它们。例如,区域 ID 153 可能有 20 个坐标,区域 ID 77 可能有 11 个坐标。我希望将它们保存在一个由区域 ID 索引的二维数组中,并且每个坐标对都组合成一个 Google LatLng 对象。稍后,我希望只检索一行,即一个区域的一组坐标,并将它们发送到一个接受坐标数组并在地图上绘制多边形的函数。这就是我所拥有的:
private var coordsFromSql:ArrayCollection = new ArrayCollection();
var polyArray:Array = new Array();
for each(var item:COORDINATES in coordsFromSql)
{
// add coordinates to the array for each Area id
polyArray[item.AREA_ID].push( new LatLng(item.LATITUDE, item.LONGITUDE) );
}
所以这就是第一个问题发生的地方。我不知道如何将可变数量的新项目添加到二维数组到已知索引中。即考虑像二维电子表格一样的polyArray,例如,我如何将值添加到“row”77,即polyArray[77]? 如果我运行上面的代码,我会收到运行时错误#1010“术语未定义且没有属性”
问题的第二部分是如何提取一个“行”作为新数组? 使用上面的例子调用drawPolygon函数,我可以这样做吗?
var polyArraySlice:Array = polyArray[77].slice();
drawPolygon(color, polyArraySlice );
I am reading a set of latitude & Longitude Coordinates that define a polygone area. They are keyed to an area ID and I retrieve them from a SQL database. So for example, Area ID 153 might have 20 coordinates and area ID 77 might have 11 coordinates. I wish to save these in a 2-D array indexed by the area ID, and where each coordinate pair is combined into one Google LatLng object. At a later point I wish to retrieve just one row i.e. the set of coordinates for one area, and send them to a function that accepts an array of coordinates and draws the polygon on a map. Here's what I have:
private var coordsFromSql:ArrayCollection = new ArrayCollection();
var polyArray:Array = new Array();
for each(var item:COORDINATES in coordsFromSql)
{
// add coordinates to the array for each Area id
polyArray[item.AREA_ID].push( new LatLng(item.LATITUDE, item.LONGITUDE) );
}
So this is where the first problem ocurrs. I don't know how to add a variable number of new items to a 2-D array into a known index. i.e considering polyArray like a 2-D spreadsheet how do I for example add values to 'row' 77 i.e. polyArray[77] ?
If I run the above code, I get runtime error #1010 'A term is undefined and has no properties'
The second part of the question is how do you extract one 'row' as a new array?
Using the above example to call a drawPolygon function, can I do this?
var polyArraySlice:Array = polyArray[77].slice();
drawPolygon(color, polyArraySlice );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您的加载代码很接近,但又不完全一样。在你的 for 循环中,你正在做:
但你实际上从未在数组中放入任何东西。
因此,您的负载可能是这样的:
获取单个位置之一的副本将像您一样工作:
It looks like your loading code is close, but not quite. In your for loop you're doing:
but you never actually put anything in the array there.
So your load would probably be something like this:
Getting a copy of the one of the individual locations would work just like you had: