Solved

Help in debugging Javascript issue

Posted on 2012-04-11
10
241 Views
Last Modified: 2012-04-15
I have a google map that is rendering via a Javascript

Old working script: http://sandbox5.project4.net/landing/v1.asp

I sought some advice on simplifying the code - however the suggestion I got does not render.  This new suggested broken script is here;

New broken script: http://sandbox5.project4.net/landing/v2.asp

There is some problem with the Javascript but I am unable to determine what.

Does anybody have an idea what the problem may be?
0
Comment
Question by:sonic1234
  • 5
  • 3
10 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37836092
change the equals signs to colons here

regionNOROC =

and

regionMIDGOC =
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37836096
so you end up with

 regionNOROC:

and

 regionMIDGOC:
0
 

Author Comment

by:sonic1234
ID: 37840897
Thanks, have tried your suggestion;

http://sandbox5.project4.net/landing/v3.asp

Still does not render unfortunately
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37847787
Load into firefox and look in the console

Timestamp: 15/04/2012 08:50:12
Error: missing : after property id
Source File: v3.asp
Line: 18, Column: 14
Source Code:
      latlngs = [
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Accepted Solution

by:
basicinstinct earned 500 total points
ID: 37848078
here is your code, fixed:
var map;
  var infoWindow;
  var regions = {
    regionNOROC: {
      regitonTitle: "Region title for region NOROC",
      latlngs: [
        {lat:-28.25,lng:153.54},
        {lat:-28.47,lng:154.13},
        {lat:-29.9,lng:153.70},
        {lat:-29.96,lng:151.78},
        {lat:-28.43,lng:152.37}
      ]
    },
    regionMIDGOC: {
      regitonTitle: "Region title for region MIDGOC",
      latlngs: [
        {lat:-29.96,lng:151.78},
        {lat:-29.9,lng:153.70},
        {lat:-32.68,lng:152.95},
        {lat:-32.28,lng:149.61},
        {lat:-30.19,lng:150.20}
      ]
    }
  }; // note the lack of commas after last items
  function initialize() {
    var myLatLng = new google.maps.LatLng(-30.62, 148.8);
    var myOptions = {
      zoom: 7,
      center: myLatLng,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    };

    map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);


  // Start Regions ----------------- 

    for (var region in regions) {
    
      var paths = [];
      var pathArr = regions[region].latlngs; 
      for (var i = 0;i<pathArr.length;i++) {
        paths[i] = new google.maps.LatLng(pathArr[i].lat,pathArr[i].lat); 
      }

      var googleRegion = new google.maps.Polygon({
        paths: paths,
        strokeColor: "#FF0000",
        strokeOpacity: 0.8,
        strokeWeight: 3,
        fillColor: "#FF0000",
        fillOpacity: 0.35
      }); 

      googleRegion.setMap(map);

      // Add a listener for the click event
      google.maps.event.addListener(googleRegion, 'click',
        function() {
          // Since this Polygon only has one path, we can call getPath()
          // to return the MVCArray of LatLngs
          var vertices = this.getPath();
          var contentString = regions[region].regitonTitle;
          // Replace our Info Window's content and position
          infowindow.setContent(contentString);
          infowindow.setPosition(event.latLng);
          infowindow.open(map);
       });


  // End Regions ----------------- 
    
    infowindow = new google.maps.InfoWindow();
  }
}

Open in new window

0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37848082
in short:

- missing curly brace at end of script block
- using equals signs instead of colons to define the following object literal properties:

-- regionNOROC
-- latlngs
-- regionMIDGOC
-- latlngs
0
 

Author Closing Comment

by:sonic1234
ID: 37848090
Greatly appreciated
0
 

Author Comment

by:sonic1234
ID: 37848298
Sorry noticed the polygons don't render on the map still

See;

http://sandbox5.project4.net/landing/v4.asp

As compared to with polygons;

See http://sandbox5.project4.net/landing/v1.asp
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37849107
well it's your code right, so point us in the right direction...

Which part of your code is failing? i.e. where do those polygons come from? which part of your code draws them or asks them to be drawn?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
control character echo in html input field with javascript or jquery 7 35
Form with Modals 16 46
Change javascript css 1 21
Get the number of current month days 2 11
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now