views:

181

answers:

1

I have SVG files, which I'd like to:

  1. export and use as custom ground overlay with flat Euclidean projection (econym.org.uk/gmap/example_custommapflat.htm).
  2. take only polygons and project them on Google Map

My SVG files have some rules in common:

  1. they all are 4096x4096px
  2. main objects of the map are centered

I have done some experiments, one of which could be seen here -- http://dev.ondigital.eu/map/map.php* (remove map.php from the URL to see svg, png and other files). As you can see, the problem is, that polygons points are being projected on the left side instead of being centered + the aspect ratio is absolutely incorrect.

So the question is: How to calculate the aspect ratio, when:

  1. svg's viewBox attribute is present
  2. svg's viewBox attribute is not present and/or each polygon has to be transformed (like in our map.svg).

And what about the offset (object centration)?

Thank you in advance!

*Not tested with IE

A: 

Is it possible that you're confusing DivPixels with ContainerPixels?

Try changing

   var latlng  = self.projection.fromPixelToLatLng(
       new GPoint(point[0], point[1]),
       self.map.getZoom()
   );

to

   var latlng  = self.map.fromContainerPixelToLatLng(
      new GPoint(parseFloat(point[0]), parseFloat(point[1]))
   );

In this case, the fact that you use Strings rather than Numbers probably isn't causing any problems, yet, but it's a good idea to use Numbers now, and avoid the possibility of the + operator doing String concatenation instead of addition on your coordinates later in your project.

Mike Williams