> From: bratliff
>
> Hi Mike,
>
> I looked at PolyGonzo. Pretty Cool.
Thanks, Berry!
> Do you know the reason it is much more efficient than GPoly ?
GPolygon goes through multiple function calls for every point. You have to
create a GLatLng for each point, ang GPolygon converts each lat/lng to a
pixel coordinate by going through quite a bit of general purpose code.
PolyGonzo uses a tight inner loop for the points within a single polygon,
with separate inner loops for IE (generating VML directly) and other
browsers (using Canvas). It makes no JavaScript function calls in these
inner loops, and precalculates as much of the coordinate conversion as
possible outside the inner loop. This conversion is hard coded to use
Mercator at the moment.
In addition, all of the variables used in the inner loop are local
variables. There's an eachShape() function in polygonzo.js that has a
surprisingly long list of function parameters. These parameters are there so
that the references to them are truly local variables. This saves on name
lookups in the inner loop.
Here's the innermost loop for IE:
for( var iCoord = -1, coord; coord = coords[++iCoord]; ) {
vml[iVml++] = round( coord[0] * 10 );
vml[iVml++] = ',';
vml[iVml++] = round( coord[1] * 10 );
vml[iVml++] = ' l ';
}
And for other browsers:
for( var iCoord = 0, coord; coord = coords[++iCoord]; ) {
c.lineTo(
round( coord[0] + offsetX ) + .5,
round( coord[1] + offsetY ) + .5
);
}
The use of "vml[iVml++] = ...." in the IE version is itself one of the
optimizations. It's quite a bit faster than the "vml.push(...);" that I
would prefer to use.
> Do you have benchmarks against GPoly with the same polys ?
No benchmarks, but when I get some time (or if anyone else wants to do it),
I want to add an option to the test app to use GPolygons for comparison.
> Have you applied Douglas-Peucker or something else for point
> reduction ?
Yes, I used www.mapshaper.org to reduce the shapefiles interactively. The
numbers in the generateXyz function calls at the end of makeshapes.py show
the percentage reduction I used in mapshaper. I tried a Python
Douglas-Peucker implementation that I found, but it left gaps between the
state/county boundaries. Mapshaper avoids that problem and was good enough
for what I needed in the election maps. It would be nice to automate this,
though.
> What role does JQuery play ?
> Is it required ?
There's a temporary dependency on jQuery in the core polygonzo.js file. This
is used only for mouse hit-testing; it was the quickest way to get that
running with my election deadlines.
polymap.js and testmap.js use a bit more jQuery, but as I review the code,
there aren't really that many jQuery dependencies. It would be easy to
revise these files to not use jQuery at all, or to make a simple version
with no jQuery and a fancy version that really makes use of some jQuery
features.
> Is the AJAX loader required ?
Not at all. I just used it in test.html for convenience.
> Is SVG obsolete ?
No, and in fact it would probably benefit some browsers to generate SVG
directly in the same way that the code generates VML for IE. I didn't do
that yet, because the worst case by far for performance, and still the most
common browser, is IE. Canvas is pretty fast in all other browsers, so the
browser I worked hardest to optimize for the election maps was IE.
> For my own JS enlightenment, I am not sure I understand the
> purpose of the unnamed / anonymous "()" function. Is it to
> keep clutter out of the global namespace ? I believe Google
> is using a similar trick with their classic loader. Do you
> anticipate a conflict ?
Yes, that's precisely what it's for - to create a local namespace. The
particular form that I used in polymap.js and testmap.js is popular in
jQuery code:
(function( $ ) {
var foo;
// etc
})( jQuery );
This creates a local namespace for 'foo' and other variables, and it also
makes the global function 'jQuery' available inside the function as '$'. For
the reasoning behind this, see:
http://docs.jquery.com/Using_jQuery_with_Other_Libraries
Of course this would be a moot point if the code is changed to not use
jQuery.
Thanks for taking such a close look at the code and for the interesting
questions!
-Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---