When developing Map based application, it’s very likely you want to display some point of interests on top of the map or draw some shape on the map.
The RasterMap in the Guidebee Map API actually is an image| protected void paint(Graphics g) { map.paint(mapGraphics); g.drawImage((Image) mapImage.getNativeImage(), 0, 0, 0); //start drawing your own sharps or images. ... … } |
So a simple way is to draw the POIs or shapes after you render the map on screen.
Remember to use proper coordinate system when draw on screen. The Map API uses latitude, longitude coordinate system while graphics system (screen) uses device coordinates. RasterMap has methods fromLatLngToScreenPixel to convert coordinate for latitude, longitude pair to x,y coordinate on screen. And method fromScreenPixelToLatLng to covert x,y coordinate on screen to latitude,longitude on map.
The following example uses a better solution to draw overlay on the map: define a subclass of MapLayer. RasterMap is also a map layer container, a sub class of MapLayerContainer, which can be used to manage mulptile map layers. Think of these layers as transparencies where each layer contains a different part of the map. The layers are stacked one on top of the other and allow you to see all aspects of the map at the same time.
The following examples display several POIs, a triangle and center cross on the map.
| public class MapOverlayMIDP extends MapDemoMIDP { OverLayMapLayer mapLayer; public void startApp() { init(); GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778); map.setCenter(center, 9, MapType.GOOGLECHINA); Display.getDisplay(this).setCurrent(canvas); mapLayer = new OverLayMapLayer(canvas.getWidth(), canvas.getHeight()); map.addMapLayer(mapLayer); } class OverLayMapLayer extends MapLayer { GeoLatLng pt1 = new GeoLatLng(32.345281, 118.84261); GeoLatLng pt2 = new GeoLatLng(32.05899, 118.62789); GeoLatLng pt3 = new GeoLatLng(32.011811, 118.798656); public OverLayMapLayer(int width, int height) { super(width, height); } public void paint(IGraphics graphics, int offsetX, int offsetY) { drawCursor(graphics); drawTriangle(graphics); drawPoint(graphics, pt1); drawPoint(graphics, pt2); drawPoint(graphics, pt3); } public void drawTriangle(IGraphics g) { GeoPoint ptOnScreen1 = map.fromLatLngToScreenPixel(pt1); GeoPoint ptOnScreen2 = map.fromLatLngToScreenPixel(pt2); GeoPoint ptOnScreen3 = map.fromLatLngToScreenPixel(pt3); g.setColor(0x0000FF); g.drawLine((int) ptOnScreen1.x, (int) ptOnScreen1.y, (int) ptOnScreen2.x, (int) ptOnScreen2.y); g.drawLine((int) ptOnScreen2.x, (int) ptOnScreen2.y, (int) ptOnScreen3.x, (int) ptOnScreen3.y); g.drawLine((int) ptOnScreen1.x, (int) ptOnScreen1.y, (int) ptOnScreen3.x, (int) ptOnScreen3.y); } public void drawPoint(IGraphics g, GeoLatLng pt) { GeoPoint ptOnScreen = map.fromLatLngToScreenPixel(pt); int x = (int) ptOnScreen.x; int y = (int) ptOnScreen.y; g.setColor(0x00FF00); g.fillRect(x - 4, y - 4, 8, 8); } private void drawCursor(IGraphics g) { int x = getScreenWidth() / 2; int y = getScreenHeight() / 2; g.setColor(0x205020); g.drawRect(x - 4, y - 4, 8, 8); g.drawLine(x, y - 6, x, y - 2); g.drawLine(x, y + 6, x, y + 2); g.drawLine(x - 6, y, x - 2, y); g.drawLine(x + 6, y, x + 2, y); } } } |



