1
votes

I want to browse a single image with the Google Maps API, for which I've defined my own projection. I wanted to use a GroundOverlay instead of several image tiles, because I only have one small-resolution image, but I wanted it to still be zoomable. However, I get some erratic behavior when trying to work with this projection:

  1. No overlays show up at all at zoom level 0.
  2. At zoom level 1 and higher, Markers show up, but GroundOverlays still don't.
  3. However, I can get GroundOverlays to show up very briefly, if I zoom out from any level. It will only show while it's zooming out and disappear again immediately. Also, while it does show up shortly, it does not show up at the right coordinates, but the Markers do.

I'm rather new to the API, so I would not be surprised if it was a simple oversight on my part, but I just can't see what could cause this. Here is the code for my projection, which just maps the lat/lng linearly to map coordinates:

function EvenMapProjection() {
    var xPerLng = 512/360;
    var yPerLat = 512/180;
    this.fromLatLngToPoint = function(latlng) {
        var x = (latlng.lng()+180)*xPerLng;
        var y = (latlng.lat()+90)*yPerLat;
        console.log('Lng', latlng.lng(), 'Lat', latlng.lat(), '-> Point', x, y);
        return new google.maps.Point(x, y);
    };
    this.fromPointToLatLng = function(point) {
        var lat = point.y/yPerLat-90;
        var lng = point.x/xPerLng-180;
        console.log('Point', point.x, point.y, '-> Lng', lng, lat);
        return new google.maps.LatLng(lat, lng);
    };
}

An example of what I'm trying to do without the projection (using the default Mercator projection):

http://95.156.209.71/tmp/a.html

The same example with the projection as defined above:

http://95.156.209.71/tmp/b.html

And finally an example using the projection but without the GroundOverlay, and instead just using tiled images (always the same image):

http://95.156.209.71/tmp/c.html

The last link also shows the Marker at LatLng(0, 0) appear at zoom level 1 (or higher), but not at level 0.

Is there something I'm just missing, or some buggy code, or is this actually a problem in the API?

1
Take a look at library.ucf.edu/Web/Js/Maps.js , the file contains a EuclideanProjection, this appears to be what you need.Dr.Molle
@Dr.Molle It is what I need, but it's actually pretty much the same as what I posted above. Some things are different, and I tried to implement them, but I'm getting more or less the same display errors. The overlay doesn't appear until you zoom in and out for a while (it seems totally random), and will often appear shifted by 360 longitude to the right (east). Sometimes only after I drag it around for a bit, but still well within the map boundaries. This seems to be an Overlay issue. Do you happen to have the link to a map actually implementing that code? Maybe that would help. Thanks anyway.Stjepan Bakrac
@Dr.Molle Actually, that gave me the deciding clue to answer the question, although it's still a weird issue.Stjepan Bakrac
fromPointToLatLng needs a second param "noWrap". Don't know whether that will fix your problem but I know I've experienced similar wrapping flakiness to what you describe when I've forgotten it.Don Hatch

1 Answers

1
votes

I just found out that my mistake was in the definition of the ground overlay. I was at zoom level 0, which meant that I set the bounds for the overlay from (-90,-180) to (90,180), but the API seems to have issues with these levels, because they wrap longitude, hence I got weird errors. I adjusted it to be at level 1 for minimum zoom, and set the overlay from (-45,-90) to (45,90), and now it all works fine.