Hi,

I am trying to load a set of tiles when the user selects a checkbox.
The tiles are determined based on the zoom level of the map and should
change automatically if the user changes the zoom.

My swf file runs ok until the checkbox is selected and then I get the
following error:
ReferenceError: Error #1037: Cannot assign to a method loadTile on
com.google.maps.TileLayerBase.  Although I can continue to use other
aspects of the application the ward tiles are not loaded.

I'm pretty new to Flash and unsure as to why things are going wrong.

I've not include everything in the code here as it gets quite long!

Any help much appreciated.

Thanks,
Hannah


// Section from main code block:

// Ward
checkWard.addEventListener(MouseEvent.CLICK, Wardchecked);
function Wardchecked(event:MouseEvent):void {
        if (checkWard.selected==true) {
                trace("You want to display the Ward boundaries");
                basicWards();
        } else {
                trace("You have selected not to display Ward boundaries");
        }
}

// Section of code dealing with basic loading of GoogleMaps

import com.google.maps.LatLng;
import com.google.maps.LatLngBounds;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.MapOptions;
import com.google.maps.Copyright;
import com.google.maps.CopyrightCollection;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.ControlPosition;

// declare a new map variable
var map:Map = new Map();

// set the API key attached to this project
map.key="ABQIAAAAbhc_fYYl7ciPrwzHkX-PrRRoRdfcHiXn-
hQpM1jLAfPsa9abhhSIzWMjZx_XLdDEI4mUcc-lBy_J3A";

// set the size (pixels) of the map to fit in right square
map.setSize(new Point(460, 459));//x then y
// set the position of the map
map.x=330;
map.y=38;
// add event listeners for before map is drawn and once map is ready
map.addEventListener(MapEvent.MAP_PREINITIALIZE, onMapStart);
map.addEventListener(MapEvent.MAP_READY, onMapReady);
// attach map to Flash movie
this.addChild(map);

/* FUNCTION: onMapStart
open the map centred on Keele, Staffordshire
*/
function onMapStart(event:Event):void {
        var myMapOptions:MapOptions = new MapOptions();
        // set the initial zoom (12 includes most of N-u-L)
        myMapOptions.zoom=12;
        myMapOptions.center=new LatLng(53,-2.28);
        myMapOptions.mapType=MapType.NORMAL_MAP_TYPE;
        this.map.setInitOptions(myMapOptions);
}

/* FUNCTION: onMapReady
when the map is ready add a zoom control in the top right
*/
function onMapReady(event:Event):void {
        // (Control Position.AnchorPoint, padding x, padding y)
        var topRight:ControlPosition=new
ControlPosition(ControlPosition.ANCHOR_TOP_RIGHT,5,5);
        var myZoomControl:ZoomControl = new ZoomControl();
        myZoomControl.setControlPosition(topRight);
        map.addControl(myZoomControl);
}

// Section of code loading custom tiles

//import com.google.maps.MapZoomEvent;
import com.google.maps.TileLayerBase

var centreLat=52.52265718516376;
var centreLon=-2.2052859033287735;
var initialZoomLevel=5;

// mapBounds set to West Midlands area
var mapBounds=new LatLngBounds(new
LatLng(51.82169354137137,-3.256512464788894),new
LatLng(53.22362082895615,-1.154059341868653));

var opacity=0.5;
var fileDIR="C:/Users/Hannah/Documents/Masters/Dissertation/GISdata/";

function customGetTileURL(a,b) {
        //doesn't reach this point
        trace("I've called the customGetTileURL function");

        //converts tile x,y into keyhole string
        if (b>11) {
                return fileDIR + "wardbasic/blank-tile.png";
        }

        var c=Math.pow(2,b);
        var x=360/c*a.x-180;
        var y=180-360/c*a.y;
        var x2=x+360/c;
        var y2=y-360/c;
        var lon=x;//Math.toRadians(x); //would be lon=x+lon0, but lon0=0
degrees
        var lat=(2.0*Math.atan(Math.exp(y/180*Math.PI))-Math.PI/2.0)*180/
Math.PI;//in degrees
        var lon2=x2;
        var lat2=(2.0*Math.atan(Math.exp(y2/180*Math.PI))-Math.PI/2.0)*180/
Math.PI;//in degrees

        // Calculate size of tile on map
        var tileBounds=new LatLngBounds(new LatLng(lat2,lon),new
LatLng(lat,lon2));

        // Check whether tile and map are the same area
        // Return blank tile where map is not in area covered by tiles
        if (! tileBounds.intersects(mapBounds)) {
                return fileDIR + "wardbasic/blank-tile.png";
        }
        // Work out which tile to get
        var d=a.x;
        var e=a.y;
        var f="t";
        for (var g=0; g<b; g++) {
                c=c/2;
                if (e<c) {
                        if (d<c) {
                                f+="q";
                        } else {
                                f+="r";
                                d-=c;
                        }
                } else {
                        if (d<c) {
                                f+="t";
                                e-=c;
                        } else {
                                f+="s";
                                d-=c;
                                e-=c;
                        }
                }
        }
        return fileDIR + "wardbasic/"+f+".png";
}

function basicWards() {
        //if (BrowserIsCompatible()) {
        //resizeMapDiv();

        var copyrightCollection=new CopyrightCollection("GMapCreator");
        copyrightCollection.addCopyright(new Copyright("CASA", new
LatLngBounds(new LatLng(-90,-180), new LatLng(90,180)), 0, "<a href=
\"http://www.casa.ucl.ac.uk\";>CASA</a>") );

        trace("I've set the copyright information");

        //TileLayerBase(copyrightCollection:ICopyrightCollection,
minResolution?:Number, maxResolution?:Number, alpha?:Number)
        //loadTile(tilePos:Point, zoom:Number): DisplayObject

        var n_tileLayers = [MapType.NORMAL_MAP_TYPE.getTileLayers()[0], new
TileLayerBase(copyrightCollection , 0, 17)];

        trace(n_tileLayers.value);

        n_tileLayers[1].loadTile = customGetTileURL;

        // call Function:customGetTileURL, need to pass in parameters:
        // a - not sure what this is
        // b - zoom level of map
        //var zoom=map.zoomLevel;

        n_tileLayers[1].isPng=function() { return false; };
        // set layer to be semi see-through (actual opacity level set by
variable at top)
        n_tileLayers[1].getOpacity=function() { return opacity; };

        //MapType(tileLayers:Array, projection:IProjection, name:String,
options?:MapTypeOptions)
        var n_customMap=new
MapType(n_tileLayers,n_tileLayers[0].maxResolution()+1,"wards");//,
         //{maxResolution: 11,minResolution: 0,errorMessage:"Data not
available"}

        map.addOverlay(n_customMap);

        // the remove the layer use: map.removeOverlay(n_customMap);

}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API For Flash" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api-for-flash?hl=en.

Reply via email to