Map API

Nutiteq Maps Lib SDK enables developing advanced mobile mapping applications.
Platforms: Android, RIM BlackBerry, Java ME (J2ME)
Download maps API SDK »
Untitled Document

Products

Latest news

Last at Mon, 6 Sep 2010 12:27:06
Topic: Let your feedback ideas flow
See more news »

Nutiteq on Twitter

12 weeks 2 days ago Nutiteq is proud sponsor of StateOfTheMap 2010 #sotm10

Custom map source for local area

4 replies [Last post]
jaak
User offline. Last seen 6 hours 55 min ago. Offline
Joined: 06/19/2008

Following is an advanced example custom map service. "Regio" maps are for local area, so calculation of tile x and y has to be overwritten. This example uses also local custom projection (EPSG:3301), but you can base your map to a built-in projection (like Google Mercator EPSG3785). The map bonds (constants MIN_E etc) must be defined in the map's projection.

Note that library does not prevents user to move outside map bounds, application has to control it (using MapListener and MapMoved events, for example).

The example is just to get some ideas how to solve it, it is not directly usable.

public class Regio extends EPSG3301 implements 
  GeoMap, UnstreamedMap {

  public static final int TILE_EDGE_PX = 256;
  public static final int MIN_E = -211000; 
  public static final int MIN_N = 5732000; 
  public static final int MAX_E = 1325000; 
  public static final int MAX_N = 7268000; 
  public static final int MIN_ZOOM = 2;
  public static final int MAX_ZOOM = 12;
  public static final int MAP_WIDTH_HEIGHT_METERS = MAX_E - MIN_E;

  private final String baseurl;


  public Regio(final String baseurl) {
    super(new StringCopyright("Regio"), 256, 
      MIN_ZOOM, MAX_ZOOM);
    this.baseurl = baseurl;
  }

  public Point mapPosToWgs(final MapPos pos) {
    return toWgs(mapPointToEastingNorthing(pos, pos.getZoom()));
  }

  private Point mapPointToEastingNorthing(final MapPos pos, final int zoom) {
    final int mapWidthHeightInPixels = getMapWidth(zoom);
    final float pixelInMeters = MAP_WIDTH_HEIGHT_METERS / (float) mapWidthHeightInPixels;
    final int easting = (int) (pos.getX() * pixelInMeters + MIN_E);
    final int northing = (int) (MAX_N - pos.getY() * pixelInMeters);
    return new Point(easting, northing);
  }

  public MapPos wgsToMapPos(final Point wgs, final int zoom) {
    //calculate easting/northing
    final Point enPoint = fromWgs(wgs);
    final int eastingFromMapZero = enPoint.getX() - MIN_E;
    final int northingFromMapZero = enPoint.getY() - MIN_N;

    final int mapWidthHeightInPixels = getMapWidth(zoom);
    final int pointX = (int) ((eastingFromMapZero / (float) MAP_WIDTH_HEIGHT_METERS) * mapWidthHeightInPixels);
    final int pointY = (int) (mapWidthHeightInPixels - ((northingFromMapZero / (float) MAP_WIDTH_HEIGHT_METERS) * mapWidthHeightInPixels));
    return new MapPos(pointX, pointY, zoom);
  }

  public String buildPath(final int mapX, final int mapY, final int zoom) {
    final int x = mapX / TILE_EDGE_PX;
    final int y = mapY / TILE_EDGE_PX;
    return getTileUrl(x, y, zoom);
  }

  private String getTileUrl(final int x, final int y, final int zoom) {
    final StringBuffer url = new StringBuffer(baseurl);
    url.append("tile=");
	// generate quad-key for xy
    for (int i = zoom - 1; i >= 0; i--) {
      url.append((((y >> i) & 1) << 1) + ((x >> i) & 1));
    }

    return url.toString();
  }
}

/JaakL

abbottv
User offline. Last seen 43 weeks 13 hours ago. Offline
Joined: 11/04/2009

Hi so I have an issue with implementing custom maps. I have been given a set of sliced images but with no gps information, I dont know what projection is. I also dont know the map bounds, or how to work it out? I dont need to plot any POIs or anything on the map, I just need to display the images at different zoom levels. The files given have the naming format TYPE_ZOOM_X_Y.png eg (TYPE_100_0_00.png, TYPE_100_0_01.png, TYPE_100_1_00.png, TYPE_100_1_01.png,) for a 4 tiled map at full zoom. If you could give me any direction to implement this it would be a great help.

admin
User offline. Last seen 37 weeks 4 days ago. Offline
Joined: 05/08/2008

I would put the images together, and then try to geo-reference them with MSR MapCruncher (see http://www.nutiteq.com/content/mobile-map-mapcruncher). Result images can be put to web server, or to application package for offline use.

abbottv
User offline. Last seen 43 weeks 13 hours ago. Offline
Joined: 11/04/2009

Thanks for your advice, I will look into that one but at the moment we have hundreds of maps and much more on the way, which means alot of extra man hours to geo-reference them. Is there any way I can just use the png as stored maps(pulled from a server) with out that information. I have gone through the examples and pdfs and I cant seem to get it to function.

jaak
User offline. Last seen 6 hours 55 min ago. Offline
Joined: 06/19/2008

How exactly do you want to show them? The georeferencing of map is needed to link map image pixels coordinates with geographical locations, so you can have e.g. points and GPS locations on top of it. If you really do not need any functions which require geographical references, then you can define custom map with only one zoom, and divide your area to 256x256-pixel map images. Depending on size of your map you should select appropriate zoom. e.g. if it is 512x512, then zoom = 1, if 1024x1024, then zoom=2 etc. It has to be power of 2. However, user gets only this one zoom, for client-side cannot do down-sampling for other zooms; this has to be made using scripts beforehand. MSR Mapcrucher does it in addition to georeferencing, but you can also create own script to do similar, depending on size and expected functionality of the map.

/JaakL