ActionScript:如何推送到多维数组并稍后检索一行“行”

发布于 2024-08-18 13:15:04 字数 919 浏览 12 评论 0原文

我正在阅读一组纬度和纬度定义多边形区域的经度坐标。它们与区域 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 技术交流群。

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

发布评论

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

评论(1

就此别过 2024-08-25 13:15:04

看起来您的加载代码很接近,但又不完全一样。在你的 for 循环中,你正在做:

polyArray[item.AREA_ID].push(/*...*/)

但你实际上从未在数组中放入任何东西。

因此,您的负载可能是这样的:

var polyArray:Array = []

for each(var item:COORDINATES in coordsFromSql)
{
    // add coordinates to the array for each Area id                
    var id:Number = item.AREA_ID;
    if(polyArray[id] == null) { polyArray[id] = [] }
    polyArray[id].push( new LatLng(item.LATITUDE, item.LONGITUDE) );
}

获取单个位置之一的副本将像您一样工作:

var polyArraySlice:Array = polyArray[77].slice();                   
drawPolygon(color,  polyArraySlice );         

It looks like your loading code is close, but not quite. In your for loop you're doing:

polyArray[item.AREA_ID].push(/*...*/)

but you never actually put anything in the array there.

So your load would probably be something like this:

var polyArray:Array = []

for each(var item:COORDINATES in coordsFromSql)
{
    // add coordinates to the array for each Area id                
    var id:Number = item.AREA_ID;
    if(polyArray[id] == null) { polyArray[id] = [] }
    polyArray[id].push( new LatLng(item.LATITUDE, item.LONGITUDE) );
}

Getting a copy of the one of the individual locations would work just like you had:

var polyArraySlice:Array = polyArray[77].slice();                   
drawPolygon(color,  polyArraySlice );         
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文