hopelesszxq / google-maps-utility-library-v3

Automatically exported from code.google.com/p/google-maps-utility-library-v3
Apache License 2.0
0 stars 0 forks source link

CanvasLayer canvas2d example fails to render when date line is crossed #243

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

What steps will reproduce the problem?
1. Load the canvaslayer/examples/hello2d.html sample into your browser
2. Ensure the window is wide enough to display both the west Pacific and the 
south-eastern US at the default zoom.
3. Click and drag the map, moving the pointer to the right so that Asia, 
Siberia and the Pacific are shown.

Expected result:
The green rectangle on the southeast of the US should remain visible.

Actual result:
As the left corner of the map crosses the international date line, the green 
rectangle disappears.

Version: Code downloaded on March 27th 2013

Browser / Operating System:
Reproduced in both Chrome and Firefox

Additional comments:

I have a patch for this, which should be inserted after line 89 in the 
hello2d.html file

        var offset = mapProjection.fromLatLngToPoint(canvasLayer.getTopLeft());
+
+        /* We need to do some fix-ups for cases where we cross the 
international
+         * dateline. The offset is returned in normalized 0.0 to 256.0
+         * coordinates, so we get the desired result by subtracting 256.0.
+        */
+        var bounds = map.getBounds();
+        var westLongitude = bounds.getSouthWest().lng();
+        var eastLongitude = bounds.getNorthEast().lng();
+        var doesCrossDateLine = (westLongitude >= 0.0) && (eastLongitude < 0);
+        if (doesCrossDateLine) {
+          offset.x -= 256.0;
+        }
        context.translate(-offset.x, -offset.y);

Original issue reported on code.google.com by searchbr...@gmail.com on 27 Mar 2013 at 8:05