Compare OSM and Google Maps

Why settle with only one online map provider when you can use them all. Sometimes OSM (OpenStreetMaps) offers better coverage in some places while Google Maps look really good plus you have Street View and Satellite View.

That’s why I decided to use a tool that will let you easily compare the maps and get all the available information. It looks something like Continuă lectura „Compare OSM and Google Maps”

Compute OpenStreetMaps tile numbers so that they wrap around

I use Google Maps API to display OSM tiles. Log story short, the code below helps you make this:

be displayed like this:

Notice how the one OSM tile that shows the whole map is replicated left and right forever. In this way the tiles will be shown the same way like Google tiles.

The code to initialize the Google Maps API with OSM tiles:

function init_osm() {
    map_osm = new google.maps.Map(map_div, {
    center: new google.maps.LatLng(pos.lat, pos.lng),
    zoom: pos.zoom,
    mapTypeId: "OSM",
    mapTypeControl: false,
    streetViewControl: false
  });
  //Define OSM map type pointing at the OpenStreetMap tile server
  map_osm.mapTypes.set("OSM", new google.maps.ImageMapType({
    getTileUrl: function(coord, zoom) {
      var maxTile = Math.pow(2, zoom);
      if (coord.y < 0 || coord.y >= maxTile) { return;};
      var x = coord.x % maxTile;
      var y = coord.y % maxTile;
      x = x < 0 ? x + maxTile : x;
      y = y < 0 ? y + maxTile : y;
      return "http://tile.openstreetmap.org/" + zoom + "/" 
                + coord.x + "/" + coord.y + ".png";
    },
    tileSize: new google.maps.Size(256, 256),
    name: "OpenStreetMap",
    maxZoom: 19
  }));
};

Bing Maps API v7 – unable to register/trigger „mousedown” event on map’s div

Instead of:

map.addEventListener("mousedown", handler_function, false);

do:

map.addEventListener("mousedown", handler_function, true);

Notice the „true” value in the second line of code. That means that we get the event during the capture phase. It seems that Bing Maps get the event in the same phase and then kill it, so you will not receive the event if you wait for it in the bubbling phase (like in the first line of code).