Solved

Help in debugging Javascript issue

Posted on 2012-04-11
10
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

729 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