Package org.geomajas.internal.layer.feature

Examples of org.geomajas.internal.layer.feature.InternalFeatureImpl


    document.writeAttribute("coordsize", coordWidth + "," + coordHeight);
    // up to shapetype
    document.closeElement();

    for (InternalFeature f : tile.getFeatures()) {
      InternalFeatureImpl feature = (InternalFeatureImpl) f;
      Coordinate pos = geoService.calcDefaultLabelPosition(feature);
      if (pos == null) {
        continue;
      }
      com.vividsolutions.jts.geom.Point p = factory.createPoint(pos);
      com.vividsolutions.jts.geom.Point labelPos;
      try {
        labelPos = (com.vividsolutions.jts.geom.Point) transformer.transform(p);
        String labelString = feature.getLabel();

        // If the attribute has no value, continue with the next:
        if (labelString == null || labelString.length() == 0) {
          document.closeElement();
          continue;
        }

        // Calculate label width, left and top:
        Rectangle2D textBox = textService.getStringBounds(labelString, labelStyle.getFontStyle());
        int boxWidth = (int) textBox.getWidth() + 8; // TODO: check why not wide enough !!!
        int boxHeight = (int) textBox.getHeight() + 2;
        int left = ((int) labelPos.getX()) - boxWidth / 2;
        int top = ((int) labelPos.getY()) - boxHeight / 2;

        // Group for an individual label (vml:group):
        document.writeElement("vml:group", true);
        document.writeAttribute("style", "LEFT: " + left + "px; TOP: " + top + "px; WIDTH: " + boxWidth
            + "px; HEIGHT: " + boxHeight + "px; position:absolute;");
        document.writeAttribute("coordsize", boxWidth + " " + boxHeight);

        // First we draw the rectangle:
        document.writeElement("vml:rect", true);
        document.writeAttribute("id", feature.getId() + ".label");
        document.writeAttribute("style", "WIDTH: " + boxWidth + "px; HEIGHT: " + boxHeight + "px;");
        document.writeAttribute("fillcolor", bgStyle.getFillColor());
        document.writeAttribute("strokecolor", bgStyle.getStrokeColor());
        document.writeAttribute("strokeweight", bgStyle.getStrokeWidth());

        // Rect-fill element:
        document.writeElement("vml:fill", true);
        document.writeAttribute("opacity", Float.toString(bgStyle.getFillOpacity()));
        document.closeElement();

        // Rect-stroke element:
        document.writeElement("vml:stroke", true);
        document.writeAttribute("opacity", Float.toString(bgStyle.getStrokeOpacity()));
        document.closeElement();

        // Then the label-text:
        document.writeElement("vml:textbox", true);
        document.writeAttribute("id", feature.getId() + ".text");
        document.writeAttribute("v-text-anchor", "middle");
        document.writeAttribute("inset", "0px, 0px, 0px, 0px");
        document.writeAttribute("style", getCssStyle(labelStyle.getFontStyle())
            + "; text-align:center; WIDTH: " + boxWidth + "px; HEIGHT: " + boxHeight + "px;");
        document.writeAttribute("fillcolor", labelStyle.getFontStyle().getColor());
        if (labelStyle.getFontStyle().getOpacity() > 0) {
          document.writeElement("vml:fill", true);
          document.writeAttribute("opacity", Float.toString(labelStyle.getFontStyle().getOpacity()));
          document.closeElement();
        }
        // document.writeTextNode(labelString.replaceAll(" ", " "));
        document.writeTextNode(labelString);
        document.closeElement();

        // Close the vml:rect
        document.closeElement();

        // Close the individual label group (vml:group):
        document.closeElement();
      } catch (TransformException e) {
        log.warn("Label for " + feature.getId() + " could not be written!");
      }
    }
    document.closeElement();
  }
View Full Code Here


    Geometry maxScreenBbox = null; // The tile's maximum bounds in screen space. Used for clipping.
    for (InternalFeature feature : orgFeatures) {
      // clip feature if necessary
      if (exceedsScreenDimensions(feature, scale)) {
        log.debug("feature {} exceeds screen dimensions", feature);
        InternalFeatureImpl vectorFeature = (InternalFeatureImpl) feature.clone();
        tile.setClipped(true);
        vectorFeature.setClipped(true);
        if (null == maxScreenBbox) {
          maxScreenBbox = JTS.toGeometry(getMaxScreenEnvelope(tile, panOrigin));
        }
        Geometry clipped = maxScreenBbox.intersection(feature.getGeometry());
        vectorFeature.setClippedGeometry(clipped);
        tile.addFeature(vectorFeature);
      } else {
        tile.addFeature(feature);
      }
    }
View Full Code Here

    this.transformer = transformer;
  }

  public void writeObject(Object object, GraphicsDocument document, boolean asChild) throws RenderException {
    try {
      InternalFeatureImpl feature = (InternalFeatureImpl) object;
      Geometry geom = feature.getGeometry();
      if (feature.isClipped()) {
        geom = feature.getClippedGeometry();
      }
      geom = transformer.transform(geom);

      if (geom instanceof Point || geom instanceof MultiPoint) {
        // write the enclosing group
        document.writeElement("g", asChild);
        document.writeAttribute("id", feature.getId());

        // write the points
        for (int i = 0; i < geom.getNumGeometries(); i++) {
          document.writeObject(geom.getGeometryN(i), true);
          document.writeAttribute("id", feature.getId());
          document.writeAttribute("xlink:href", "#" + feature.getStyleInfo().getStyleId());
          document.closeElement();
        }
      } else {
        document.writeObject(geom, asChild);
        document.writeAttribute("id", feature.getId());
      }
    } catch (TransformException e) {
      log.warn("could not render feature");
    }
  }
View Full Code Here

  @Test
  public void testCalcDefaultLabelPosition() throws Exception {
    Geometry geometry;
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
    Coordinate coordinate;
    InternalFeature feature = new InternalFeatureImpl();
    feature.setId("x");
    feature.setLabel("Label x");
    coordinate = geoService.calcDefaultLabelPosition(feature);
    Assert.assertNull(coordinate);

    feature.setGeometry(factory.createMultiPolygon(new Polygon[] {}));
    coordinate = geoService.calcDefaultLabelPosition(feature);
    Assert.assertNull(coordinate);

    feature.setGeometry(JTS.toGeometry(new Envelope(10, 20, 30, 40)));
    coordinate = geoService.calcDefaultLabelPosition(feature);
    // this tests current behaviour, without claims that this is the "best" (or even "good") position
    Assert.assertEquals(15.0, coordinate.x, DELTA);
    Assert.assertEquals(35.0, coordinate.y, DELTA);

    geometry = factory.createLineString(new Coordinate[] { new Coordinate(5,4), new Coordinate(30,10) });
    feature.setGeometry(geometry);
    coordinate = geoService.calcDefaultLabelPosition(feature);
    // this tests current behaviour, without claims that this is the "best" (or even "good") position
    Assert.assertEquals(5.0, coordinate.x, DELTA);
    Assert.assertEquals(4.0, coordinate.y, DELTA);
  }
View Full Code Here

    Authentication auth2 = getAuthentication(1); // base, allow all
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    InternalFeature feature = new InternalFeatureImpl();
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    feature.setAttributes(attributes);
    attributes.put(ATTRIBUTE_ID, new StringAttribute("bla"));
    Assert.assertTrue(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));
  }
View Full Code Here

    Authentication auth2 = getAttributeAuthentication();
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    InternalFeature feature = new InternalFeatureImpl();
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    feature.setAttributes(attributes);
    attributes.put(ATTRIBUTE_ID, new StringAttribute("bla"));
    Assert.assertTrue(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));
  }
View Full Code Here

    Authentication auth2 = getAttributeAuthentication();
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    InternalFeature feature = new InternalFeatureImpl();
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    feature.setAttributes(attributes);
    attributes.put(ATTRIBUTE_ID, new StringAttribute("bla"));
    Assert.assertTrue(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("rea"));
    Assert.assertFalse(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("wri"));
    Assert.assertTrue(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertFalse(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));
  }
View Full Code Here

    Authentication auth2 = getFeatureAuthentication();
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    InternalFeature feature = new InternalFeatureImpl();
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    feature.setAttributes(attributes);
    attributes.put(ATTRIBUTE_ID, new StringAttribute("bla"));
    Assert.assertTrue(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("vis"));
    Assert.assertFalse(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("upd"));
    Assert.assertTrue(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertFalse(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));
  }
View Full Code Here

   */
  private InternalFeature convertFeature(Object feature, Geometry geometry, VectorLayer layer,
      CrsTransform transformation, List<StyleFilter> styles, LabelStyleInfo labelStyle, int featureIncludes)
      throws GeomajasException {
    FeatureModel featureModel = layer.getFeatureModel();
    InternalFeature res = new InternalFeatureImpl();
    res.setId(featureModel.getId(feature));
    res.setLayer(layer);
    res.setGeometry(geometry); // in layer coordinate space for security checks
    res = attributeService.getAttributes(layer, res, feature); // includes security checks

    if (null != res) {
      // add and clear data according to the feature includes
      // unfortunately the data needs to be there for the security tests and can only be removed later
      if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_LABEL) != 0) {
        String labelAttr = labelStyle.getLabelAttributeName();
        Attribute attribute = featureModel.getAttribute(feature, labelAttr);
        if (null != attribute && null != attribute.getValue()) {
          res.setLabel(attribute.getValue().toString());
        }
      }

      // If allowed, add the geometry (transformed!) to the InternalFeature:
      if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_GEOMETRY) != 0) {
        Geometry transformed;
        if (null != transformation) {
          transformed = geoService.transform(geometry, transformation);
        } else {
          transformed = geometry;
        }
        res.setGeometry(transformed);
      } else {
        res.setGeometry(null);
      }

      // If allowed, add the style definition to the InternalFeature:
      if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_STYLE) != 0) {
        res.setStyleDefinition(findStyleFilter(feature, styles).getStyleDefinition());
      }

      // If allowed, add the attributes to the InternalFeature:
      if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES) == 0) {
        res.setAttributes(null);
      }
    }

    return res;
  }
View Full Code Here

    Authentication auth2 = getAuthentication(1); // base, allow all
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    InternalFeature feature = new InternalFeatureImpl();
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    feature.setAttributes(attributes);
    attributes.put(ATTRIBUTE_ID, new StringAttribute("bla"));
    Assert.assertTrue(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertTrue(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
View Full Code Here

TOP

Related Classes of org.geomajas.internal.layer.feature.InternalFeatureImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.