次の例: 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()
私たちを手伝ってくれますか?