0

I am getting the following error when trying to run my Javascript file:

"Uncaught TypeError: Object function (a){"undefined"==typeof a&& a=0);this.m_PolyOuts=null;this.m_ClipType= d.ClipType.ctIntersection;this.m_IntersectNodeComparer=this.m_IntersectList=this.m_SortedEdges=this.m_ActiveEdges=this.m_Scanbeam=null;this.m...<omitted>...y'"

Relevant code:

<script>

 // Geolocation
 var stateData;
 var states = new Object();

 d3.json("states.json", function (data) {

         stateData = data;

         data.features.forEach(function (datum) {
                 // Populate data for each entry in states[__]...
         });

         var pt = new ClipperLib.IntPoint(67.007915, -152.002047);
         for (var i = 0; i < states["Alaska"].length; ++i) {
                 var done = 0;
                 for (var j = 0; j < states["Alaska"][i].length; ++j) {
                         var poly = states["Alaska"][i][j];
                         if (ClipperLib.Clipper.PointInPoly(pt, poly) == 1) {
                                 done = 1;
                                 break;
                         }
                         ...
                  }
         }

         ...
  });

</script>

When I try running the command on the console in Chrome, I do not receive an error: https://www.dropbox.com/s/cm29oaxgr5rjz2d/Screenshot%202014-02-28%2011.42.19.png

I am using ClipperJS and have at the top of my file included it as a src as such:

< script src="clipper.js" charset="utf-8">< /script>

(No spaces before "script" or "/script" - they are here because it would not display otherwise.)

I thought it might have been because of a type mismatch but I then tried:

...
var poly = [{X:10,Y:10},{X:110,Y:10},{X:110,Y:110},{X:10,Y:110}];
if (ClipperLib.Clipper.PointInPoly(pt, poly) == 1) {
    done = 1;
    break;
}
...

And I still got the same error. Any help is appreciated!

Relevant link for where I got the idea to use ClipperJS (answer by "Timo")

Community
  • 1
  • 1
Supervisor
  • 582
  • 1
  • 6
  • 20

1 Answers1

0

Without seeing the rest of your code, it seems like a bootstrapping issue. Try ensuring that your code is run after everything on the page has run already.

Also: D3's json request calls its callback with error as the first parameter, and data as the second. I suspect this is causing the Poly configurations for each state to be misconfigured or, not configured at all, so when you're querying them for point inclusion it's failing.

https://github.com/mbostock/d3/wiki/Requests

Allain Lalonde
  • 91,574
  • 70
  • 187
  • 238
  • Just added everything relevant to the call above. Let me know if you still would like more. – Supervisor Feb 28 '14 at 17:19
  • Hmm... Are you saying that states would not be populated by the time we get to the Clipper call? Why is states populated when I use it in the console? – Supervisor Feb 28 '14 at 18:50