코드 샘플: 사용자 정의 모양 및 객체 만들기

다음 코드 샘플은 MapSimplePolygon 객체와 GsImage 개체를 만드는 방법을 보여줍니다. MapSimplePolygon은 객체에 적용되는 투명한 스타일로서, BlackBerry 단말기 사용자가 객체 뒤에 있는 지도를 볼 수 있도록 합니다.

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);                                  
        }     
    }
}

이 정보가 도움이 되었습니까? 의견을 보내 주십시오.