basiclayer.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 150 行
JAVA
150 行
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/learn/BasicLayer.java,v $// $RCSfile: BasicLayer.java,v $// $Revision: 1.1.2.2 $// $Date: 2007/02/26 16:57:11 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.learn;import java.awt.BasicStroke;import java.awt.Color;import com.bbn.openmap.layer.OMGraphicHandlerLayer;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicConstants;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMLine;import com.bbn.openmap.omGraphics.OMPoint;import com.bbn.openmap.omGraphics.OMTextLabeler;/** * This layer is a good place to start learning how to create OpenMap layers. It * extends OMGraphicHandler, which contains a good bit of functionality, but * exposes only the methods you need to start putting features (OMGraphics) on * the map. If you want to learn more about interacting with your OMGraphics * after you get the hang of displaying them efficiently, then move to the * InteractionLayer. */public class BasicLayer extends OMGraphicHandlerLayer { /** * The empty constructor is necessary for any layer being created using the * openmap.properties file, via the openmap.layers property. This method * needs to be public, too. Don't try to do too much in the constructor - * remember, this code gets executed whether the user turns the layer on * uses the layer or not. Performance-wise, it's better to do most * initialization the first time the layer is made part of the map. You can * test for that in the prepare() method. * * @see #prepare */ public BasicLayer() { // Sets the name of the layer that is visible in the GUI. Can also be // set with properties with the 'prettyName' property. setName("Basic Layer"); // This is how to set the ProjectionChangePolicy, which // dictates how the layer behaves when a new projection is // received. The StandardPCPolicy is the default policy and you don't // need to set it, this method call is here to illustrate where and how // you would make that call with a different policy. setProjectionChangePolicy(new com.bbn.openmap.layer.policy.StandardPCPolicy(this, true)); } /** * This is an important Layer method to override. The prepare method gets * called when the layer is added to the map, or when the map projection * changes. We need to make sure the OMGraphicList returned from this method * is what we want painted on the map. The OMGraphics need to be generated * with the current projection. We test for a null OMGraphicList in the * layer to see if we need to create the OMGraphics. This layer doesn't * change it's OMGraphics for different projections, if your layer does, you * need to clear out the OMGraphicList and add the OMGraphics you want for * the current projection. */ public OMGraphicList prepare() { OMGraphicList list = getList(); if (list == null) { list = init(); } /* * This call to the list is critical! OMGraphics need to be told where * to paint themselves, and they figure that out when they are given the * current Projection in the generate(Projection) call. If an * OMGraphic's location is changed, it will need to be regenerated * before it is rendered, otherwise it won't draw itself. You generally * know you have a generate problem when OMGraphics show up with the * projection changes (zooms and pans), but not at any other time after * something about the OMGraphic changes. * * If you want to be more efficient, you can replace this call to the * list as an else clause to the (list == null) check above, and call * generate(Projection) on all the OMGraphics in the init() method below * as you create them. This will prevent the * OMGraphicList.generate(Projection) call from making an addional loop * through all of the OMGraphics before they are returned. */ list.generate(getProjection()); return list; } /** * Called from the prepare() method if the layer discovers that its * OMGraphicList is null. * * @return new OMGraphicList with OMGraphics that you always want to display * and reproject as necessary. */ public OMGraphicList init() { // This layer keeps a pointer to an OMGraphicList that it uses // for painting. It's initially set to null, which is used as // a flag in prepare() to signal that the OMGraphcs need to be // created. The list returned from prepare() gets set in the // layer. // This layer uses the StandardPCPolicy for new // projections, which keeps the list intact and simply calls // generate() on it with the new projection, and repaint() // which calls paint(). OMGraphicList omList = new OMGraphicList(); // Add an OMLine OMLine line = new OMLine(40f, -75f, 42f, -70f, OMGraphic.LINETYPE_GREATCIRCLE); // line.addArrowHead(true); line.setStroke(new BasicStroke(2)); line.putAttribute(OMGraphicConstants.LABEL, new OMTextLabeler("Line Label")); omList.add(line); // Add a list of OMPoints. OMGraphicList pointList = new OMGraphicList(); for (int i = 0; i < 100; i++) { OMPoint point = new OMPoint((float) (Math.random() * 89f), (float) (Math.random() * -179f), 3); point.setLinePaint(Color.green); pointList.add(point); } omList.add(pointList); return omList; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?