Problem trying Osm tiles provider

Mar 11, 2014 at 6:02 PM
Hi,

I'm working with the trunk version and I'm trying to use the new features that allows to use openstreetmap data directly in mapwingis. Does any one know if it's working in the trunk ? because I didn't manage to get it working sadly. The problem I have, is in the display of the tiles.

As I understand i have to do something like that:
my_map.LoadTiles(my_map.GetExtents(), 256, key, tkTileProvider::OpenStreetMap);
where my_map is an object of type CMap1 in my application and key is a BSTR variable initilized to "OSM".

At first i got a messagebox saying one of my parameters was of the wrong type. It seems there is a inconsistency between the code definition and the odl file on the trunk. So I change it and made the "key" parameter of BSTR type.
Then when i called the code nothing was happening, so i goolged some and found an old post somewhere from 2008 saying I had to specify the geoprojection in my map object. So I did like that:
   IGeoProjectionPtr pProj = NULL;
   pProj.CreateInstance( __uuidof(GeoProjection));
    VARIANT_BOOL res= VARIANT_FALSE;
    CString sProj = _T("+proj=longlat +datum=WGS84 +no_defs");
    BSTR sProjBstr = sProj.AllocSysString();
    pProj->ImportFromProj4(sProjBstr, &res);
    SysFreeString(sProjBstr);
    my_map.SetGeoProjection(pProj);
Now the system began to work. I could see MakeTileImageUrl being called in OpenStreetMapProvider which generated a valid URL, I could see that a bitmap was allocated in memory etc. But after that MapWingis crashed.

The crash occure because of an unhandled exception in TilesDrawer.cpp
void CTilesDrawer::DrawTiles(ITiles* cotiles, double pixelsPerMapUnit, 
                             IGeoProjection* mapProjection, BaseProjection* tileProjection, bool printing)
on line 54
customProj = dynamic_cast<CustomProjection*>(tileProjection);
tileProjection as its name says comme from the tile provider and for OSM it's of type MercatorProjection so it's normal for the cast to fail. I tried several changes but none displayed the tiles correctly :(

I don't want to make big modification to the code, I'm thinking i'm missing something but after some time looking at the problem i can't see what. I'll keep working on this but comments or ideas are welcome :)
Mar 13, 2014 at 3:23 PM
Re,
Since tuesday i updated the trunk to the latest revision, now even without my asking mapwingis adds OSM tiles to the map but it still crahses in DrawTiles.
    if (tileProjection && mapProjection)
    {
        customProj = dynamic_cast<CustomProjection*>(tileProjection);
        if (customProj)
        {
            mapProjection->get_IsSame(customProj->projCustom, &isSame);
            Debug::WriteLine("Is same projection: %d", isSame);
        }
    }
this is the code in question, the dynamic_cast fails because tileProjection (actualy of type MercatorProjection) isn't castable into CustomProjection. So i hacked a bit and wrote this:
    if (tileProjection && mapProjection)
    {
        customProj = new CustomProjection();
        VARIANT_BOOL b = VARIANT_FALSE;
        customProj->projCustom->ImportFromEPSG(3857, &b);
        if (customProj)
        {
            mapProjection->get_IsSame(customProj->projCustom, &isSame);
            Debug::WriteLine("Is same projection: %d", isSame);
        }
    }
It's very crude but allows the tiles to be drawn quite correctly (I haven't done thorough tests though). I choose EPSG 3857 because it looks like this is the most frequently used projection by the "web" tiles provider (google, osm, bign, yahoo,..).

Since the rest of the code (download, cache, etc) looks like it's working properly, I will try to make a cleaner correction even though i don't know what was intended when the code was written. I'll also try to figure why by default some tiles are loaded.
Coordinator
Dec 8, 2014 at 6:56 AM
Hi Vincent,

When you use today's trunk do you still have these problems?
Did you look at this documentation: http://www.mapwindow.org/documentation/mapwingis4.9/getting_started.html

Thanks,

Paul
Marked as answer by pmeems on 1/1/2015 at 3:34 AM