Actionscript地图投影

时间:2013-06-29 00:42:41

标签: actionscript-3

按照这个例子:http://andywoodruff.com/blog/simple-shapefile-drawing-in-actionscript-3/我正在尝试创建一个世界地图,类似于jqvmap。 6 这是我的结果:http://www.prestitiprotestati.info/test/Test.html

现在我需要创建一个更逼真的地图,为这个平面世界地图添加一些投影。

我正在关注http://vis4.net/blog/posts/rendering-world-maps-in-as3/的教程,但是当我尝试创建投影时,我遇到了一个奇怪的错误,我无法理解它的来源。

这是我的尝试:

    private function onShapefile( event:Event ) : void
    {

        // use the ShpTools class to parse the shapefile into an array of records
        var records : Array = ShpTools.readRecords(event.target.data).records;

        // create a feature (point, polyline, or polygon) from each record
        /*for each( var record : ShpRecord in records ){
            var feature : ShpFeature = createFeature(record);
            if ( feature != null ) features.push( feature );
        }*/
        var record:ShpRecord, poly:ShpPolygon, coords:Array, pt:ShpPoint, o:Point;
        var polygons = [];
        var bounds = new Rectangle();

        for each (record in records) {
            if (record.shapeType == ShpType.SHAPE_POLYGON) {
                poly = record.shape as ShpPolygon;
                for each (coords in poly.rings) {
                    var out:PointSet = new PointSet;
                    for each (pt in coords){ 
                        trace("PT.X: "+ObjectUtil.toString(pt.x));
                        if (projection.testPointDeg(pt.x, pt.y)) {
                            o = projection.project(deg2rad(pt.x), deg2rad(pt.y), new Point());
                            o.y *= -1;
                            out.push(o);
                        }
                    }
                    var out_poly:Polygon = new Polygon(out);
                    polygons.push(out_poly);
                    bounds = bounds.union(out_poly.boundingBox);
                }
            }
        }

        shpLoaded = true;

        // draw the features
        drawMap();

        // to signal the completion of map loading/drawing
        dispatchEvent(new Event("map loaded",true));
    }
    public function deg2rad(deg:Number):Number
    {
        return deg * Math.PI / 180.0;
    }

我得到的错误来自这一行:

if (projection.testPointDeg(pt.x, pt.y))

错误是:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.cartogrammar.shp::ShpMap/onShapefile()
 [E:\FlashBuilder\Cartogrammar\src\com\cartogrammar\shp\ShpMap.as:96]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

你能帮帮我吗?

0 个答案:

没有答案