/**
   * Create a {@link TiledImageLayer} layer described by an XML layer description.
   *
   * @param domElement the XML element describing the layer to create. The element must inculde a
   *     service name identifying the type of service to use to retrieve layer data. Recognized
   *     service types are "Offline", "WWTileService" and "OGC:WMS".
   * @param params any parameters to apply when creating the layer.
   * @return a new layer
   * @throws WWUnrecognizedException if the service type given in the describing element is
   *     unrecognized.
   */
  protected Layer createTiledImageLayer(Element domElement, AVList params) {
    Layer layer;

    String serviceName = WWXML.getText(domElement, "Service/@serviceName");

    if ("Offline".equals(serviceName)) {
      layer = new BasicTiledImageLayer(domElement, params);
    } else if ("WWTileService".equals(serviceName)) {
      layer = new BasicTiledImageLayer(domElement, params);
    } else if (OGCConstants.WMS_SERVICE_NAME.equals(serviceName)) {
      layer = new WMSTiledImageLayer(domElement, params);
    } else if (AVKey.SERVICE_NAME_LOCAL_RASTER_SERVER.equals(serviceName)) {
      layer = new LocalRasterServerLayer(domElement, params);
    } else {
      String msg = Logging.getMessage("generic.UnrecognizedServiceName", serviceName);
      throw new WWUnrecognizedException(msg);
    }
    //
    //        String name = layer.getStringValue(AVKey.DISPLAY_NAME);
    //        System.out.println(name);

    String actuate = WWXML.getText(domElement, "@actuate");
    layer.setEnabled(actuate != null && actuate.equals("onLoad"));

    return layer;
  }
示例#2
0
  public Layer createLayer(Layer layer) {
    layer.id = getNextLayerId();
    layer.rank = getNextLayerRank();
    layers.put(layer.id, layer);

    return layer;
  }
示例#3
0
  public void makeOrderedRenderable(DrawContext dc, AirspaceRenderer renderer) {
    if (dc == null) {
      String message = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (renderer == null) {
      String message = Logging.getMessage("nullValue.RendererIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    for (Layer layer : this.layers) {
      if (!layer.isVisible()) continue;

      if (!layer.isAirspaceVisible(dc)) continue;

      // The layer is responsible for applying its own attributes, so we override its attributes
      // with our own just
      // before rendering.
      layer.setAttributes(this.getAttributes());

      // Create an ordered renderable that draws each layer, but specifies this Cake as the picked
      // object.
      OrderedRenderable or =
          renderer.createOrderedRenderable(dc, layer, layer.computeEyeDistance(dc), this);
      dc.addOrderedRenderable(or);
    }
  }
示例#4
0
  public boolean isAirspaceVisible(DrawContext dc) {
    if (dc == null) {
      String message = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    // If the parent Cake is not visible, then return false immediately without testing the child
    // layers.
    if (!super.isAirspaceVisible(dc)) return false;

    boolean visible = false;

    // The parent Cake is visible. Since the parent Cake's extent potentially contains volumes where
    // no child
    // geometry exists, test that at least one of the child layers are visible.
    for (Layer l : this.layers) {
      if (l.isAirspaceVisible(dc)) {
        visible = true;
        break;
      }
    }

    return visible;
  }
示例#5
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Finds all entities of a type on the map.
   *
   * @param entityType a type of entity
   * @return the list of the entities of this kind on the map
   */
  public List<MapEntity> getEntitiesOfType(EntityType entityType) {

    List<MapEntity> list = new LinkedList<MapEntity>();
    for (Layer layer : Layer.values()) {
      list.addAll(allEntities[layer.getId()].getEntitiesOfType(entityType));
    }
    return list;
  }
示例#6
0
  public Position getReferencePosition() {
    ArrayList<LatLon> locations = new ArrayList<LatLon>(this.layers.size());
    for (Layer l : this.layers) {
      locations.add(l.getCenter());
    }

    return this.computeReferencePosition(locations, this.getAltitudes());
  }
示例#7
0
文件: Map.java 项目: AlanTR/solarus
  /** Initializes the object. */
  private void initialize() {
    this.allEntities = new MapEntities[3];
    for (Layer layer : Layer.values()) {
      this.allEntities[layer.getId()] = new MapEntities();
    }

    this.entitySelection = new MapEntitySelection(this);
    this.history = new MapEditorHistory();
  }
示例#8
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Sets the entities of the map.
   *
   * @param allEntities an array of 3 MapEntity sets: a set for each layer (this array is copied)
   */
  public void setAllEntities(MapEntities[] allEntities) {

    for (Layer layer : Layer.values()) {
      this.allEntities[layer.getId()] = new MapEntities(allEntities[layer.getId()]);
    }

    setChanged();
    notifyObservers();
  }
示例#9
0
  @Override
  protected void doGetRestorableState(RestorableSupport rs, RestorableSupport.StateObject context) {
    super.doGetRestorableState(rs, context);

    RestorableSupport.StateObject so = rs.addStateObject(context, "layers");
    for (Layer layer : this.layers) {
      RestorableSupport.StateObject lso = rs.addStateObject(so, "layer");
      layer.doGetRestorableState(rs, lso);
    }
  }
示例#10
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Returns the total number of entities of the map.
   *
   * @return the total number of entities of the map.
   */
  public int getNbEntities() {

    int nbEntities = 0;

    // count the entities of each layer
    for (Layer layer : Layer.values()) {
      nbEntities += allEntities[layer.getId()].size();
    }

    return nbEntities;
  }
示例#11
0
文件: World.java 项目: perry-/TDT4240
  /**
   * Applies Camera transformations and draws all the Layers in this World.
   *
   * @param canvas The Canvas onto which the World will be drawn.
   */
  public void draw(Canvas canvas) {

    canvas.save();
    canvas.translate(-camera.getPosition().getX(), -camera.getPosition().getY());

    for (Layer l : layers) {
      l.draw(canvas, camera.getBoundingBox());
    }

    canvas.restore();
  }
示例#12
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Returns an entity, specifying its type and its name.
   *
   * @param type the type of entity
   * @param name the name of the entity
   * @return the entity, or null if there is no entity with this name
   */
  public MapEntity getEntityWithName(EntityType type, String name) {

    for (Layer layer : Layer.values()) {
      MapEntity entity = allEntities[layer.getId()].getEntityWithName(type, name);
      if (entity != null) {
        return entity;
      }
    }

    return null;
  }
示例#13
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Returns the total number of active entities of the map.
   *
   * @return the total number of active entities of the map.
   */
  public int getNbDynamicEntities() {

    int nbDynamicEntities = 0;

    // count the dynamic entities of each layer
    for (Layer layer : Layer.values()) {
      nbDynamicEntities += allEntities[layer.getId()].getNbDynamicEntities();
    }

    return nbDynamicEntities;
  }
示例#14
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Returns the highest layer where a specified rectangle overlaps an existing entity.
   *
   * @param rectangle a rectangle
   * @return the highest layer where an entity exists in this rectangle, or Layer.LOW if there is
   *     nothing here
   */
  public Layer getLayerInRectangle(Rectangle rectangle) {

    Layer[] layers = {Layer.HIGH, Layer.INTERMEDIATE, Layer.LOW};
    for (Layer layer : layers) {
      for (MapEntity entity : allEntities[layer.getId()]) {
        if (rectangle.intersects(entity.getPositionInMap())) {
          return layer;
        }
      }
    }
    return Layer.LOW;
  }
  private List<String> rebuildAttributes(SimpleFeatureType sft) {
    Layer layer = applicationLayer.getService().getSingleLayer(applicationLayer.getLayerName());
    List<String> attributesToRetain = new ArrayList<String>();
    for (AttributeDescriptor ad : sft.getAttributes()) {
      String name = ad.getName();

      String fullName = sft.getId() + ":" + name;
      // if attribute already added return.
      if (attributesToRetain.contains(fullName)) {
        return attributesToRetain;
      }
      attributesToRetain.add(fullName);

      // Used for display in JSP
      if (StringUtils.isNotBlank(ad.getAlias())) {
        attributeAliases.put(fullName, ad.getAlias());
      }

      if (applicationLayer.getAttribute(sft, name) == null) {
        ConfiguredAttribute ca = new ConfiguredAttribute();
        // default visible if not geometry type
        // and not a attribute of a related featuretype
        boolean defaultVisible = true;
        if (layer.getFeatureType().getId() != sft.getId()
            || AttributeDescriptor.GEOMETRY_TYPES.contains(ad.getType())) {
          defaultVisible = false;
        }
        ca.setVisible(defaultVisible);
        ca.setAttributeName(name);
        ca.setFeatureType(sft);
        applicationLayer.getAttributes().add(ca);
        Stripersist.getEntityManager().persist(ca);

        if (!"save".equals(getContext().getEventName())) {
          String message = "Nieuw attribuut \"{0}\" gevonden in ";
          if (layer.getFeatureType().getId() != sft.getId()) {
            message += "gekoppelde ";
          }
          message += "attribuutbron";
          if (layer.getFeatureType().getId() == sft.getId()) {
            message += ": wordt zichtbaar na opslaan";
          }
          getContext().getMessages().add(new SimpleMessage(message, name));
        }
      }
    }
    if (sft.getRelations() != null) {
      for (FeatureTypeRelation rel : sft.getRelations()) {
        attributesToRetain.addAll(rebuildAttributes(rel.getForeignFeatureType()));
      }
    }
    return attributesToRetain;
  }
示例#16
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Changes the layer of an entity. You should call this method instead of calling directly
   * MapEntity.setLayer(), because the entity of the 3 layers are stored in 3 different structures.
   * If the entity is not known by the map (yet), this method just calls MapEntity.setLayer().
   *
   * @param entity the entity to change the layer
   * @param layer the new layer
   */
  public void setEntityLayer(MapEntity entity, Layer layer) {

    Layer oldLayer = entity.getLayer();

    if (layer != oldLayer) {
      entity.setLayer(layer);

      if (allEntities[oldLayer.getId()].remove(entity)) {
        allEntities[layer.getId()].add(entity);
      }

      setChanged();
      notifyObservers();
    }
  }
  /**
   * Create a layer described by an XML layer description.
   *
   * @param domElement the XML element describing the layer to create.
   * @param params any parameters to apply when creating the layer.
   * @return a new layer
   * @throws WWUnrecognizedException if the layer type or service type given in the describing
   *     element is unrecognized.
   * @see #createTiledImageLayer(org.w3c.dom.Element, gov.nasa.worldwind.avlist.AVList).
   */
  protected Layer createFromLayerDocument(Element domElement, AVList params) {
    String className = WWXML.getText(domElement, "@className");
    if (className != null && className.length() > 0) {
      Layer layer = (Layer) WorldWind.createComponent(className);
      String actuate = WWXML.getText(domElement, "@actuate");
      layer.setEnabled(WWUtil.isEmpty(actuate) || actuate.equals("onLoad"));
      WWXML.invokePropertySetters(layer, domElement);
      return layer;
    }

    AVList props = WWXML.copyProperties(domElement, null);
    if (props != null) { // Copy params and add any properties for this layer to the copy
      if (params != null) props.setValues(params);
      params = props;
    }

    Layer layer;
    String href = WWXML.getText(domElement, "@href");
    if (href != null && href.length() > 0) {
      Object o = this.createFromConfigSource(href, params);
      if (o == null) return null;

      if (!(o instanceof Layer)) {
        String msg =
            Logging.getMessage("LayerFactory.UnexpectedTypeForLayer", o.getClass().getName());
        throw new WWRuntimeException(msg);
      }

      layer = (Layer) o;
    } else {
      String layerType = WWXML.getText(domElement, "@layerType");
      if (layerType != null && layerType.equals("TiledImageLayer")) {
        layer = this.createTiledImageLayer(domElement, params);
      } else {
        String msg = Logging.getMessage("generic.UnrecognizedLayerType", layerType);
        throw new WWUnrecognizedException(msg);
      }
    }

    if (layer != null) {
      String actuate = WWXML.getText(domElement, "@actuate");
      layer.setEnabled(actuate != null && actuate.equals("onLoad"));
      WWXML.invokePropertySetters(layer, domElement);
    }

    return layer;
  }
  public Resolution getUniqueValues() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("success", Boolean.FALSE);

    try {
      Layer layer = applicationLayer.getService().getSingleLayer(applicationLayer.getLayerName());
      if (layer != null && layer.getFeatureType() != null) {
        SimpleFeatureType sft = layer.getFeatureType();
        List<String> beh = sft.calculateUniqueValues(attribute);
        json.put("uniqueValues", new JSONArray(beh));
        json.put("success", Boolean.TRUE);
      }
    } catch (Exception e) {
      json.put("msg", e.toString());
    }
    return new StreamingResolution("application/json", new StringReader(json.toString()));
  }
示例#19
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Brings the specified entities to the back, keeping their layer. The order of the specified
   * entities in the map is unchanged.
   *
   * @param entities the entities to move
   */
  public void bringToBack(List<MapEntity> entities) {

    List<MapEntity> sortedEntities = getSortedEntities(entities);

    // bring to back each entity from sortedEntities
    ListIterator<MapEntity> iterator = sortedEntities.listIterator(sortedEntities.size());
    while (iterator.hasPrevious()) {

      MapEntity entity = iterator.previous();
      Layer layer = entity.getLayer();
      allEntities[layer.getId()].remove(entity);
      allEntities[layer.getId()].addFirst(entity);
    }

    setChanged();
    notifyObservers();
  }
示例#20
0
  protected Extent computeExtent(Globe globe, double verticalExaggeration) {
    List<Layer> cakeLayers = this.getLayers();

    if (cakeLayers == null || cakeLayers.isEmpty()) {
      return null;
    } else if (cakeLayers.size() == 1) {
      return cakeLayers.get(0).computeExtent(globe, verticalExaggeration);
    } else {
      ArrayList<Box> extents = new ArrayList<Box>();

      for (Layer layer : cakeLayers) {
        extents.add(layer.computeExtent(globe, verticalExaggeration));
      }

      return Box.union(extents);
    }
  }
示例#21
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Brings the specified entities to the front, keeping their layer. The order of the specified
   * entities in the map is unchanged.
   *
   * @param entities the entities to move
   */
  public void bringToFront(List<MapEntity> entities) {

    List<MapEntity> sortedEntities = getSortedEntities(entities);

    // bring to front each entity from sortedEntities
    ListIterator<MapEntity> iterator = sortedEntities.listIterator(0);
    while (iterator.hasNext()) {

      MapEntity entity = iterator.next();
      Layer layer = entity.getLayer();
      allEntities[layer.getId()].remove(entity);
      allEntities[layer.getId()].addLast(entity);
    }

    setChanged();
    notifyObservers();
  }
示例#22
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Changes the tileset of the map.
   *
   * @param tilesetId id of the new tileset, or an empty string to set no tileset
   * @return true if the tileset was loaded successfuly, false if some tiles could not be loaded in
   *     this tileset
   * @throws MapException if this tileset could be applied
   */
  public boolean setTileset(String tilesetId) throws ZSDXException {

    this.badTiles = false;

    // if the tileset is removed
    if (tilesetId.length() == 0 && this.tilesetId.length() != 0) {

      this.tilesetId = tilesetId;
      this.tileset = null;

      setChanged();
      notifyObservers();
    }

    // if the tileset is changed
    else if (!tilesetId.equals(this.tilesetId)) {

      this.tileset = new Tileset(tilesetId);

      for (Layer layer : Layer.values()) {

        LinkedList<MapEntity> entitiesToRemove = new LinkedList<MapEntity>();
        for (MapEntity entity : allEntities[layer.getId()]) {

          try {
            entity.setTileset(tileset);
          } catch (NoSuchTilePatternException ex) {
            // the entity is not valid anymore, we should remove it from the map
            entitiesToRemove.add(entity);
            badTiles = true;
          }
        }

        for (MapEntity entity : entitiesToRemove) {
          allEntities[layer.getId()].remove(entity);
        }
      }

      this.tilesetId = tilesetId;

      setChanged();
      notifyObservers(tileset);
    }

    return !badTiles;
  }
  /**
   * Handles the getCapabilities request and gives the XML formated server capabilities to the
   * outputStream
   *
   * @param output servlet outputStream
   * @param wmsResponse HttpServletResponse modified for WMS use
   * @throws WMSException
   * @throws UnsupportedEncodingException
   */
  public void getCap(OutputStream output, WMSResponse wmsResponse)
      throws WMSException, UnsupportedEncodingException {
    PrintStream pr = new PrintStream(output, false, "UTF-8");
    WMSCapabilities cap = new WMSCapabilities();
    // Setting service WMS metadata
    cap.setService(getService());
    // Setting Capability parameters
    // Setting Layers capabilities
    Capability c = new Capability();
    // Bounding box of the highest layer is dummy
    Envelope dummy = new Envelope(WEST, EAST, SOUTH, NORTH);
    EXGeographicBoundingBox bb = getGeographicBoundingBox(dummy, "EPSG:4326");
    Layer availableLayers = new Layer();
    availableLayers.setEXGeographicBoundingBox(bb);
    BoundingBox bBox = new BoundingBox();
    bBox.setCRS("EPSG:4326");
    bBox.setMaxx(EAST);
    bBox.setMinx(WEST);
    bBox.setMaxy(NORTH);
    bBox.setMiny(SOUTH);
    availableLayers.getBoundingBox().add(bBox);
    for (Layer e : layerMap.values()) {
      availableLayers.getLayer().add(e);
    }
    // Server supported CRS
    availableLayers.getCRS().addAll(authCRS);
    availableLayers.setName("Available_layers");
    availableLayers.setTitle("Server available layers");
    c.setLayer(availableLayers);
    // Setting the request capabilities
    // GetMap capabilities
    Request req = new Request();
    req.setGetMap(getMapOperation(wmsResponse));
    // GetCap capabilities
    req.setGetCapabilities(getCapOperation(wmsResponse));
    // GetFeatureInfo capabilities
    req.setGetFeatureInfo(getFeatureOperation(wmsResponse));
    c.setRequest(req);
    cap.setCapability(c);

    try {
      // Marshalling the WMS Capabilities into an XML response
      Marshaller marshaller = jaxbContext.createMarshaller();
      NamespacePrefixMapper mapper = new NamespaceMapper();
      marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);

      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

      wmsResponse.setContentType("text/xml;charset=UTF-8");
      marshaller.marshal(cap, pr);

    } catch (JAXBException ex) {
      wmsResponse.setContentType("text/xml;charset=UTF-8");
      wmsResponse.setResponseCode(500);
      pr.append(
          "<?xml version='1.0' encoding=\"UTF-8\"?><ServiceExceptionReport xmlns=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.3.0\" xsi:schemaLocation=\"http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd\"><ServiceException>Something went wrong</ServiceException></ServiceExceptionReport>");
      pr.append(ex.toString());
      ex.printStackTrace(pr);
    }
  }
示例#24
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Returns the specified entities, sorted in the order of the map. The first entity is the lowest
   * one, the last entity is the highest one.
   *
   * @param entities the entities to sort
   * @return the same entities, sorted as they are in the map
   */
  public List<MapEntity> getSortedEntities(List<MapEntity> entities) {

    List<MapEntity> sortedEntities = new LinkedList<MapEntity>();

    // sort the entities so that they have the same order as in the map
    for (Layer layer : Layer.values()) {

      for (MapEntity entity : allEntities[layer.getId()]) {

        if (entities.contains(entity)) {
          sortedEntities.add(entity);
        }
      }
    }

    // now sortedEntities contains all entities of the list,
    // sorted in the same order as in the map
    return sortedEntities;
  }
示例#25
0
  public void doRenderExtent(DrawContext dc) {
    if (dc == null) {
      String message = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    // Called by AirspaceRenderer's drawNow and pickNow methods. These methods do not use the
    // ordered renderable
    // queue, so TrackAirspace must explicitly initiate drawing its legs. When airspace rendering is
    // initiated via
    // AirspaceRenderer drawOrdered or pickOrdered, TrackAirspace does not add an ordered renderable
    // for itself, so
    // this method is never initiated.

    for (Layer l : this.layers) {
      l.renderExtent(dc);
    }
  }
  /** Return a Fig that can be used to represent the given edge */
  public FigEdge getFigEdgeFor(GraphModel gm, Layer lay, Object edge) {
    if (edge instanceof MDependency) {

      MDependency dep = (MDependency) edge;
      FigDependency depFig = new FigDependency(dep);

      MModelElement supplier = (MModelElement) ((dep.getSuppliers().toArray())[0]);
      MModelElement client = (MModelElement) ((dep.getClients().toArray())[0]);

      FigNode supFN = (FigNode) lay.presentationFor(supplier);
      FigNode cliFN = (FigNode) lay.presentationFor(client);

      depFig.setSourcePortFig(cliFN);
      depFig.setSourceFigNode(cliFN);
      depFig.setDestPortFig(supFN);
      depFig.setDestFigNode(supFN);
      depFig.getFig().setLayer(lay);
      depFig.getFig().setDashed(true);
      return depFig;
    }

    if (edge instanceof MAssociation) {
      MAssociation asc = (MAssociation) edge;
      FigAssociation ascFig = new FigAssociation(asc, lay);
      Collection connections = asc.getConnections();
      if (connections == null) System.out.println("null connections....");
      Object[] connArray = connections.toArray();
      MAssociationEnd fromEnd = (MAssociationEnd) connArray[0];
      MClassifier fromCls = (MClassifier) fromEnd.getType();
      MAssociationEnd toEnd = (MAssociationEnd) connArray[1];
      MClassifier toCls = (MClassifier) toEnd.getType();
      FigNode fromFN = (FigNode) lay.presentationFor(fromCls);
      FigNode toFN = (FigNode) lay.presentationFor(toCls);
      ascFig.setSourcePortFig(fromFN);
      ascFig.setSourceFigNode(fromFN);
      ascFig.setDestPortFig(toFN);
      ascFig.setDestFigNode(toFN);
      ascFig.getFig().setLayer(lay);
      return ascFig;
    }
    return null;
  }
示例#27
0
  protected void doMoveTo(Position oldRef, Position newRef) {
    if (oldRef == null) {
      String message = "nullValue.OldRefIsNull";
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }
    if (newRef == null) {
      String message = "nullValue.NewRefIsNull";
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    super.doMoveTo(oldRef, newRef);

    for (Layer l : this.layers) {
      l.doMoveTo(oldRef, newRef);
    }

    this.setExtentOutOfDate();
  }
示例#28
0
  @Override
  protected void doRestoreState(RestorableSupport rs, RestorableSupport.StateObject context) {
    super.doRestoreState(rs, context);

    RestorableSupport.StateObject so = rs.getStateObject(context, "layers");
    if (so == null) return;

    RestorableSupport.StateObject[] lsos = rs.getAllStateObjects(so, "layer");
    if (lsos == null || lsos.length == 0) return;

    ArrayList<Layer> layerList = new ArrayList<Layer>(lsos.length);

    for (RestorableSupport.StateObject lso : lsos) {
      if (lso != null) {
        Layer layer = new Layer();
        layer.doRestoreState(rs, lso);
        layerList.add(layer);
      }
    }

    this.setLayers(layerList);
  }
示例#29
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Returns the entities located in a rectangle defined by two points.
   *
   * @param x1 x coordinate of the first point
   * @param y1 y coordinate of the first point
   * @param x2 x coordinate of the second point
   * @param y2 y coordinate of the second point
   */
  public List<MapEntity> getEntitiesInRectangle(int x1, int y1, int x2, int y2) {

    List<MapEntity> entitiesInRectangle = new LinkedList<MapEntity>();

    int x = Math.min(x1, x2);
    int width = Math.abs(x2 - x1);

    int y = Math.min(y1, y2);
    int height = Math.abs(y2 - y1);

    Rectangle rectangle = new Rectangle(x, y, width, height);

    for (Layer layer : Layer.values()) {

      for (MapEntity entity : allEntities[layer.getId()]) {
        if (rectangle.contains(entity.getPositionInMap())) {
          entitiesInRectangle.add(entity);
        }
      }
    }

    return entitiesInRectangle;
  }
示例#30
0
文件: Map.java 项目: AlanTR/solarus
  /**
   * Returns the first entity under a point of the map, in the specified layer.
   *
   * @param layer the layer
   * @param x x of the point
   * @param y y of the point
   * @return the entity found, or null if there is no entity here
   */
  public MapEntity getEntityAt(Layer layer, int x, int y) {

    MapEntities entities = allEntities[layer.getId()];
    ListIterator<MapEntity> iterator = entities.listIterator(entities.size());
    while (iterator.hasPrevious()) {

      MapEntity entity = iterator.previous();
      if (entity.containsPoint(x, y)) {
        return entity;
      }
    }

    return null;
  }