Solved

Help in debugging Javascript issue

Posted on 2012-04-11
10
240 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

708 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

20 Experts available now in Live!

Get 1:1 Help Now