Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 2
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET MVC 2
This is the forum to discuss the Wrox book Professional ASP.NET MVC 2 by Jon Galloway, Scott Hanselman, Phil Haack, Scott Guthrie, Rob Conery; ISBN: Professional ASP.NET MVC 2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 25th, 2011, 09:18 PM
Registered User
 
Join Date: Jan 2011
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default odd problem with map.js on details.aspx

Hi All: Just working through pages 127-135 with the Ajax Virtual Earth maps.

Using the original source code in the book, I was able to get it to work on the create/edit pages, but in the details.aspx view, I'm getting a weird behavior: The coordinates are being passed to the map, but the setZoomLevel and LoadPin functions never seem to fire.

If I view source, I see the correct data being passed to the JS function:

Code:
   <div id="mapDiv">
<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2" type="text/javascript"></script>
<script src="/Scripts/Map.js" type="text/javascript"></script>
<div id="theMap">
</div>
<script type="text/javascript">
    $(document).ready(function() {
        var latitude = 37.798683;
        var longitude = -122.258263;

        if ((latitude == 0) || (longitude==0))
            LoadMap();
        else
            LoadMap(latitude, longitude, mapLoaded);
        });

        function mapLoaded() {
            var title = "geeks 1";
            var address = "71 Stevenson, San Francisco, CA";
            LoadPin(center, title, address);
            map.SetZoomLevel(16);
        }
</script>

    </div>
The map is being centered on the Lat/Long coordinates properly, but it's like the mapLoaded function never fires. I've been staring at the code for awhile but can't see what the problem is?
  #2 (permalink)  
Old January 25th, 2011, 10:02 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Dig into LoadMap function and see if you have something like this:

map.onLoadMap = onMapLoaded;
  #3 (permalink)  
Old January 25th, 2011, 11:19 PM
Registered User
 
Join Date: Jan 2011
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by flyinhawaiian View Post
Dig into LoadMap function and see if you have something like this:

map.onLoadMap = onMapLoaded;
Thanks Flyin: Here's what I have in map.js (it looks like it's there?).
Code:
function LoadMap(latitude, longitude, onMapLoaded) {
    map = new VEMap('theMap');
    options = new VEMapOptions();
    options.EnableBirdseye = false;

    //Makes the control bar less obtrusive.
    map.SetDashboardSize(VEDashboardSize.Small);

    if (onMapLoaded != null)
        map.OnLoadMap = onMapLoaded;

    if (latitude != null && longitude != null) {
        center = new VELatLong(latitude, longitude);
    }

    map.LoadMap(center, null, null, null, null, null, null, options);
}
I think LoadMap is firing, because the map is centering on the lat/long coordinates, it's the "LoadPin" that doesn't seem to be firing. Here's my LoadPin JS while I'm at it:

Code:
function LoadPin(LL, name, description) {
    var shape = new VEShape(VEShapeType.Pushpin, LL);

    //make a nice pushpin shape w/title/desc
    shape.SetTitle("<span class=\"pinTitle\"> " + escape(name) + "</span>");
    if (description !== undefined) {
        shape.SetDescription("<p class=\"pinDetails\">" + escape(description) + "</p>");
    }
    map.AddShape(shape);
    points.push(LL);
    shapes.push(shape);
}
  #4 (permalink)  
Old January 25th, 2011, 11:48 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Hmmm everything appears to be in place. Have you ever debugged javascript with firefox + firebug? http://getfirebug.com/javascript

IE has similar debugging feature.
  #5 (permalink)  
Old January 26th, 2011, 12:17 AM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

I think you are missing the var in this line:

var center = new VELatLong(latitude, longitude);
  #6 (permalink)  
Old January 26th, 2011, 12:43 AM
Registered User
 
Join Date: Jan 2011
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by flyinhawaiian View Post
I think you are missing the var in this line:

var center = new VELatLong(latitude, longitude);
hmmm...I'm not sure about that. The script on the map.ascx sets the lat/long vars from the model, then calls LoadMap which is in Map.js.

LoadMap sets the center var, and this is working on dinnerform partial view.

I put an alert in LoadPin in Map.js, and it fires on the dinnerForm partial view, but not in the details.aspx, so LoadPin is not being called from map.ascx.

In map.ascx my code is as in the book:
Code:
<script type="text/javascript">
    $(document).ready(function() {
        var latitude = <%: Model.Latitude %>;
        var longitude = <%: Model.Longitude %>;
        if ((latitude == 0) || (longitude==0))
            LoadMap();
        else
            LoadMap(latitude, longitude, mapLoaded);
        });

        function mapLoaded() {
            var title = "<%: Model.Title %>";
            var address = "<%: Model.Address %>";
            LoadPin(center, title, address);
            map.SetZoomLevel(16);
        }
</script>
I notice, however, that there's a green "syntax error" squiggle under the closing brace right after the "LoadMap" line...I'm not sure what the problem is but Intellisense doesn't like something there, and it might be what's blocking "mapLoaded" from firing altogether?

I just put an alert directly instead mapLoaded, and it's not firing either, so there's a syntax problem in the code above (which is verbatim from the book as well as the sample text in example 1-90.)
  #7 (permalink)  
Old January 26th, 2011, 01:14 AM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Can you paste the entire map.ascx? I want to see the reference to the Map.js and the id for the div tag.
  #8 (permalink)  
Old January 26th, 2011, 01:38 AM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Mine looks like this (ignore my NerdDinner namespace). I noticed slight difference in that there's a Convert.ToString in mine. I borrowed this from codeplex version so expect some differences (such as _map).

Code:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.Dinner>" %>

<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2" type="text/javascript"></script>


<div id="theMap" style="width:520px"></div>

<script src="../../Scripts/Map.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[   
    $(document).ready(function() {
        var latitude = <%: Convert.ToString(Model.Latitude) %>;
        var longitude = <%: Convert.ToString(Model.Longitude) %>;
                
        if ((latitude == 0) || (longitude == 0))
            NerdDinner.LoadMap();
        else
            NerdDinner.LoadMap(latitude, longitude, mapLoaded);
    });
      
    function mapLoaded() {
        var title = "<%: Model.Title %>";
        var address = "<%: Model.Address %>";
    
        NerdDinner.LoadPin(NerdDinner._map.GetCenter(), title, address);
        NerdDinner._map.SetZoomLevel(14);
    } 
//]]>
</script>

Last edited by flyinhawaiian; January 26th, 2011 at 01:42 AM..
  #9 (permalink)  
Old January 26th, 2011, 10:45 AM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

I have the green "syntax error" squiggle as well. But apparently that's not the problem.
  #10 (permalink)  
Old January 26th, 2011, 10:49 AM
Registered User
 
Join Date: Jan 2011
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by flyinhawaiian View Post
Can you paste the entire map.ascx? I want to see the reference to the Map.js and the id for the div tag.
Thanks Flyin...I tried the convert.tostring but it made no difference.

Code:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.Dinner>" %>
<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2" type="text/javascript"></script>
<script src="/Scripts/Map.js" type="text/javascript"></script>
<div id="theMap">
</div>
<script type="text/javascript">
     $(document).ready(function() {
        var latitude = <%: Convert.ToString(Model.Latitude) %>;
        var longitude = <%: Convert.ToString(Model.Longitude) %>;
                
        if ((latitude == 0) || (longitude == 0))
            LoadMap();
        else
            LoadMap(latitude, longitude, mapLoaded);
    });
    
           function mapLoaded() {
        alert("mapLoaded fired");
            var title = "<%: Model.Title %>";
            var address = "<%: Model.Address %>";
            LoadPin(center, title, address);
            map.SetZoomLevel(16);
        }
</script>
Note: my "alert" call in the mapLoaded()...this never fires, so I'm back to syntax issue...see this scrape:
http://216.218.227.138/map.jpg
Note the syntax error ... seems to be blocking "mapLoaded", but Firebug doesn't show any errors.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Odd new webpart problem out of the blue. scottlucas58 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 January 17th, 2009 03:40 PM
how to include .js file in .aspx page shanwaj ASP.NET 2.0 Basics 13 March 11th, 2008 07:36 AM
Google Maps JS in ASPX page error kingroon ASP.NET 2.0 Basics 0 December 7th, 2007 09:52 AM
Odd PHP Session Problem moajosh Beginning PHP 2 February 24th, 2005 03:15 PM
Odd problem with ADO CreateParameter Imar Pro VB Databases 7 January 13th, 2005 09:59 AM



All times are GMT -4. The time now is 10:52 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.