As asked in a different topic: is it possible to show own map image on mobile. Yes, it is; and probably the easiest way to do it is using MSR Mapcruncher tool.
Basic steps are following:
import com.nutiteq.maps.projections.EPSG3785;
import com.nutiteq.maps.*;
public class MyQuadKeyMap extends EPSG3785 implements GeoMap, OnlineMap {
private String baseUrl;
public MyQuadKeyMap(final String baseUrl) {
super("My Map", 256, 1, 17);
this.baseUrl = baseUrl;
}
public String buildURL(final int x, final int y, final int zoom) {
final int tmpX = x >> 8;
final int tmpY = y >> 8;
final StringBuffer buf = new StringBuffer();
buf.append(baseUrl);
for (int i = zoom - 1; i >= 0; i--) {
buf.append((((tmpY >> i) & 1) << 1) + ((tmpX >> i) & 1));
}
buf.append(".png");
return buf.toString();
}
}
map.setMap(new MyQuadKeyMap("MY-PUBLIC-WEB-URL"));
Some notes:
I can't load the map. I did everything in post #1, except that OnlineMap couldn't be found and I adopted LocalMap, which anyway is what I needed. I use map.setMap("mymap") but all I get is a white map where ever I go.
What's wrong?
In recent Lib versions your map service should have "... implements GeoMap, UnstreamedMap ...", instead of OnlineMap. Also if it uses map tiles from JAR or local file system storage. LocalMap is more or less deprecated.
thanks, that didn't solve the problem but I guess it's one step closer to the solution :)
So my version of MyQuadKeyMap has the exact same code except for the OnlineMap that is now UnstreamedMap
my code to display the map is the following:
[...]
private MapItem mapItem;
[...]
//Inside the class builder
mapItem = new MapItem("Map", "test", "test2", "test1", 300, 150, new WgsPoint(47.64028017, -122.12903380), 12);
mapItem.setMap(new MyQuadKeyMap("maptest/"));
[...]
"maptest/" is the path in wich the .png files made by the cruncher are stored.
Just to let you know: the code in which I'm trying to use the custom map is the HelloMap code in the PDF tutorial.
I just added the setMap() line.
The problem is that I get a white screen insted of getting the map that I got with the cruncher. It's strange because normally tiles that can't be found should be red, am I wrong?
If you use exactly the same MyQuadKeyMap as given above, then library tries to make URL "maptest/.png" and this does not have any reference what should be image source: should it be on-line or offline.
URL should start with
# http:// or https:// - on-line source
# file:// - if it is filesytem
# / - file is in application package (as resources)
If it does not start with any of these then in principle you should have in the log a message (and exception) like "Don't know what to do with...". There is exception and this is why you do not get even the red image.
Usually filesystems have their root directory, and this is different on different devices. With WTK emulator your code should be something like mapItem.setMap(new MyQuadKeyMap("file://root1/maptest/")).
If you do not know name of root directory then I suggest to use e.g. StoredMaps sample (included with j2me package), it has also browser to find correct directory.
Have followed the example above but am getting a red map i know its got do with not getting the tiles but i dont know how fix that please help me
may be on how to point tile locations correctly-with an example i will appreciate.
Here is my code please check out then please tell me where the error is
this is for the MyQuadKeyMap as you showed above
public class MyQuadKeyMap extends EPSG3785 implements GeoMap, UnstreamedMap {
private String baseUrl;
public MyQuadKeyMap(final String baseUrl) {
super("My Map", 256, 12, 13);
this.baseUrl = baseUrl;}
public String buildPath(final int x, final int y, final int zoom) {
final int tmpX = x >> 8;
final int tmpY = y >> 8;
final StringBuffer buf = new StringBuffer();
buf.append(baseUrl);
for (int i = zoom - 1; i >= 0; i--) {
buf.append((((tmpY >> i) & 1) << 1) + ((tmpX >> i) & 1));}
buf.append(".png");
return buf.toString();
}
}
and the midlet code that implements the map is in
mapItem = new MapItem("Map", "test",this, 300, 150, new WgsPoint(.25783452, 35.08707047), 14);
mapItem.setMap(new JaredOpenStreetMap(256, 15, 16));
mapItem.setMap(new MyQuadKeyMap("/Layer_NewLayer/"));
mapItem.setMiddlePoint(.25783452, 35.08707047, 13);
so the problem is that the png tile are in a format like 1223322.png but i know you have to change to a format like zoom_x_y.png but how do you do that anybody can help me
JaredOpenStreetMap requires zoom_x_y.png format, this MyQuadKeyMap (actually latest library already includes similar com.nutiteq.maps.QKMap) uses quadkey, same format like MapCruncher uses.
What is in your log? This should indicate what tiles exactly are searched for and from where. So you can check whether you have particular tile, or just directory is wrong.
Some devices/SDK-s do not handle well subdirectories under /res/ directory. I would suggest to copy all map PNG files to /res directly, without subdirectory, and remove directory name from the MyQuadKeyMap constuctor call also. Maybe this is your issue
Thanks jaakl it worked,
Is it possible to implement direction using cloudmade on you own map tiles from mapcrancher?
If not what are you advising me to do?
Yes. Note that this works on-line only, not using the offline maps.
Hi
Thanks for responding
After storing your tiles from mapcrancher in an online server and you can access, it how do you implement cloudmade on it,
is there an example that i can follow or give me example that implements it?
I will appreciate.
Map tiles and directions service is independent from each other. J2ME samples directory has demo application "directions" source, which shows how to use different routing services, and how route line is shown on the map.
Now step 2: maybe you want your map as overlay, not as a base map. Just like MSN maps shows it.
This is also quite simple:
import com.nutiteq.components.MapTile; import com.nutiteq.maps.MapTileOverlay; public class MyQuadKeyOverlay implements MapTileOverlay { private final String baseUrl; public MyQuadKeyOverlay(final String baseUrl) { this.baseUrl = baseUrl; } public String getOverlayTileUrl(final MapTile tile) { final int tmpX = tile.getX() >> 8; final int tmpY = tile.getY() >> 8; final int zoom = tile.getZoom(); final StringBuffer url = new StringBuffer(baseUrl); for (int i = zoom - 1; i >= 0; i--) { url.append((((tmpY >> i) & 1) << 1) + ((tmpX >> i) & 1)); } url.append(".png"); return url.toString(); } }GeoMap myMap=OpenStreetMap.MAPNIK; myMap.addTileOverlay(new MyQuadKeyOverlay("MY-SERVER-URL")); map.setMap(myMap);See attached sample result.
It might be especially interesting if you have transparent or semi-transparent images. MapCruncher should support it, if original source has transparency.
/JaakL