Look at the MapMarker class If you want to put pictorial icons rather than Balloon push-pins onto your map. The basic map components anchor to the globe via GeoCoordinates so will move with the map.
if however you want to add a static image as an attribution for an overlay or something. you'll need something to anchor to the MapDisplay via Points, so you'll have to create a custom MapComponent to do this.
Here is an Attribution Map Component - attach it to the map in the usual way.
Code:
AttributionMapComponent attribution = new AttributionMapComponent(loadAttributionImage(), 2, 0x000000,
0xFFFFFF);
map.addMapComponent(attribution);
Where the attribution image is taken from the resources of the app.
Code:
private Image loadAttributionImage() {
// load image resource from MIDlet's jar file
Image im = null;
try {
im = Image.createImage("/NLS.png");
} catch (IOException io) {
throw new IllegalStateException("no attribution found.");
}
return im;
}
I've written the following MapComponent to put an un-moving attribution image over the map. It displays if an overlay is present. (map.getAllMapOverlays().length > 0)
Code:
public class AttributionMapComponent implements MapComponent {
private final String id = "attribution";
private final String version = "1.0";
private final Image attribution;
private MapDisplay map;
private static final int SMALL_CORNER_ARC = 5;
private static final int Y_OFFSET = 5;
private static final int X_OFFSET = 5;
private static final int NO_FILL = -1;
private final int border;
private final int borderColor;
private final int backgroundColor;
private Point borderAnchor;
private Point backgroundAnchor;
public AttributionMapComponent(Image attribution,int border, int borderColor,
int backgroundColor) {
this.attribution = attribution;
this.border = border;
this.borderColor = borderColor;
this.backgroundColor = backgroundColor;
}
public AttributionMapComponent(Image attribution) {
this(attribution, 0, NO_FILL, NO_FILL);
}
// from MapComponent
public void attach(MapDisplay map) {
this.map = map;
this.borderAnchor = new Point(map.getWidth() - attribution.getWidth() - border - X_OFFSET,
map.getHeight() - attribution.getHeight() - Y_OFFSET - border);
this.backgroundAnchor = new Point(map.getWidth() - attribution.getWidth() - X_OFFSET,
map.getHeight() - attribution.getHeight() - Y_OFFSET);
return;
}
// from MapComponent
public void detach(MapDisplay map) {
this.map = null;
return;
}
// from MapComponent
public String getId() {
return id;
}
// from MapComponent
public String getVersion() {
return version;
}
// from MapComponent
public void mapUpdated(boolean zoomChanged) {
}
// from MapComponent
public void paint(Graphics g) {
if (map != null && map.getAllMapOverlays().length > 0) {
if (border > 0) {
g.setColor(borderColor);
g.fillRoundRect(borderAnchor.getX(), borderAnchor.getY(),
attribution.getWidth() + (border * 2), attribution.getHeight() + (border * 2),
SMALL_CORNER_ARC, SMALL_CORNER_ARC);
}
if (backgroundColor > NO_FILL) {
// Draw the background.
g.setColor(backgroundColor);
g.fillRoundRect(backgroundAnchor.getX(), backgroundAnchor.getY(),
attribution.getWidth(),
attribution.getHeight(), SMALL_CORNER_ARC, SMALL_CORNER_ARC);
}
g.drawImage(attribution,
backgroundAnchor.getX(), backgroundAnchor.getY(),
Graphics.TOP | Graphics.LEFT);
}
}
public EventListener getEventListener() {
return null; // add eventHandler here if necessary.
}
}