AnsweredAssumed Answered

'map' is null or undefined

Question asked by geonetadmin on Oct 13, 2010
Latest reply on Mar 1, 2011 by mflawton
Original User: ereed

I have an application, and I want to be able to show a point, and zoom to that area. I have a function that uses the global variable "map" that is defined in the init procedure. When I call this variable, it gives me the message 'map' is null or undefined.

map.setExtent(newExt);

I have a textbox and button, the user will type in the textbox, and click the button.

<asp:TextBox ID="txtLocation" runat="server" style="left: 800px; position: absolute;width:200px; height:18px; top: 55px" />

<asp:Button ID="cmdAddress" runat="server" Text="Find" OnClick="cmdAddress_Click" style="left: 1110px; position: absolute;width:52px; height:24px; top: 55px"/>

In the  code behind I have a procedure that calls a web service, finds the address, and returns the coordinates. I then call the javascript function.

Code behind:

                Dim sb As New System.Text.StringBuilder()
                sb.Append("<script language='javascript'>")
                sb.Append("addAddressPointToMap(" & dblX & ", " & dblY & ");")
                sb.Append("</script>")

                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ajax", sb.ToString(), False)

Javascript Fuction:

    function addAddressPointToMap(xloc, yloc) {
        var pt = new esri.geometry.Point(xloc, yloc, new esri.SpatialReference({ wkid: 26985 }));
        var sms = new esri.symbol.SimpleMarkerSymbol().setStyle(
     esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE).setColor(
     new dojo.Color([255, 0, 0, 0.5]));
        var attr = { "XCoord": xloc, "YCoord": yloc, "Address": "XXXXX" };
        var infoTemplate = new esri.InfoTemplate();
        var newExt = new esri.geometry.Extent(xloc - 100, yloc - 100, xloc + 100, yloc + 100, new esri.SpatialReference({ wkid: 26985 }));
        var graphic = new esri.Graphic(pt, sms, attr, infoTemplate);
        map.setExtent(newExt);
        var GraphicsLayer = new esri.layers.GraphicsLayer();
        GraphicsLayer.id = "ADDRESS";
        infoTemplate.setTitle("");
        infoTemplate.setContent("<b>Address: </b>" + xloc);
        GraphicsLayer.add(graphic);
        graphic = null;
        sms = null;
        map.addLayer(GraphicsLayer);
        map.centerAt(pt);
    }    

map here is undefined. It is used in other functions without error.

Any help would be greatly appreciated.

Attachments

Outcomes