Codebeispiel: Erstellen von benutzerdefinierten Formen und Objekten
Das folgende Codebeispiel zeigt, wie Sie ein MapSimplePolygon-Objekt und ein GsImage-Objekt erstellen können. Das MapSimplePolygon verfügt über einen transparenten Stil, sodass BlackBerry-Gerätebenutzer die Karte hinter dem Objekt sehen können.
import net.rim.device.api.lbs.maps.*;
import net.rim.device.api.lbs.maps.ui.*;
import net.rim.device.api.lbs.maps.view.*;
import net.rim.device.api.lbs.maps.model.*;
import net.rim.device.api.lbs.maps.model.geospatial.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
public class CustomObjectsDemo extends UiApplication
{
public CustomObjectsDemo()
{
pushScreen(new GSScreen());
}
public static final void main( String[] args )
{
new CustomObjectsDemo().enterEventDispatcher();
}
public class CustomObjectsDemoScreen extends FullScreen
{
private RichMapField map;
public CustomObjectsDemoScreen()
{
// Invokes the constructor for FullScreen to set the behavior
// of the screen.
super(FullScreen.DEFAULT_CLOSE |
FullScreen.DEFAULT_MENU |
FullScreen.VERTICAL_SCROLL |
FullScreen.VERTICAL_SCROLLBAR);
// Creates a map and sets the center of the map.
map = MapFactory.getInstance().generateRichMapField();
map.getAction().setCenterAndZoom(new MapPoint(45.0, -75.0), 4);
add(map);
// Adds the geospatial objects to the map.
addData();
}
private void addData()
{
// Creates and adds a MapSimplePolygon object.
MapPoint[] points = new MapPoint[6];
points[0] = new MapPoint(45.05, -75.0);
points[1] = new MapPoint(45.0, -74.95);
points[2] = new MapPoint(44.95, -74.975);
points[3] = new MapPoint(44.95, -75.025);
points[4] = new MapPoint(45.0, -75.05);
points[5] = new MapPoint(45.05, -75.0);
MapSimplePolygon poly = new MapSimplePolygon(points);
map.getModel().add((Mappable) poly, "Polygon", true);
// Creates and adds a GsImage object.
GsImage gsImg = new GsImage();
gsImg.setIconUri("
http://www.rim.com/products/appworld_3col.jpg");
gsImg.setLat(44.5);
gsImg.setLon(-75.0);
gsImg.setName("App World!");
gsImg.setDescription("BlackBerry App World icon");
map.getModel().add(gsImg, "Image", true);
// Creates a style for the MapSimplePolygon class that
// allows the user to see the map behind the object.
StyleSet styles = map.getMapField().getDrawingStyles();
Style transStyle = new Style();
transStyle.setEdgeColor(Color.RED);
transStyle.setEdgeOpacity(255);
transStyle.setFillColor(Color.RED);
transStyle.setFillOpacity(50);
styles.addClassBasedStyle(MapSimplePolygon.class, transStyle);
}
}
}
Nächstes Thema: Erstellen einer Hierarchie von Geoobjekten
Vorheriges Thema: Erstellen von benutzerdefinierten Formen und Objekten
Waren diese Informationen hilfreich? Senden Sie uns Ihren Kommentar.