private void draw(
      Object parentGroup,
      GeometryIndex parentIndex,
      LinearRing linearRing,
      GraphicsContext graphics) {
    String groupName = baseName;
    if (parentIndex != null) {
      groupName += "." + editingService.getIndexService().format(parentIndex);
    }
    Composite edgeGroup = getOrCreateGroup(parentGroup, groupName + ".edges");
    Composite vertexGroup = getOrCreateGroup(parentGroup, groupName + ".vertices");

    Coordinate[] coordinates = linearRing.getCoordinates();
    if (coordinates != null) {
      // Check if we have to draw the background as well (if there are controllers defined for it):
      GraphicsController controller = createGeometryController(parentIndex);
      if (controller != null) {
        Polygon polygon =
            mapWidget.getMapModel().getGeometryFactory().createPolygon(linearRing, null);
        graphics.drawPolygon(parentGroup, groupName + ".background", polygon, new ShapeStyle());
        graphics.setController(parentGroup, groupName + ".background", controller);
      }

      // Draw individual edges:
      int max = coordinates.length;
      if (!styleService.isCloseRingWhileInserting()
          && editingService.getEditingState() == GeometryEditState.INSERTING
          && editingService
              .getIndexService()
              .isChildOf(parentIndex, editingService.getInsertIndex())) {
        max--;
      }
      for (int i = 1; i < max; i++) {
        GeometryIndex edgeIndex =
            editingService
                .getIndexService()
                .addChildren(parentIndex, GeometryIndexType.TYPE_EDGE, i - 1);
        String identifier = baseName + "." + editingService.getIndexService().format(edgeIndex);

        LineString edge =
            linearRing
                .getGeometryFactory()
                .createLineString(new Coordinate[] {coordinates[i - 1], coordinates[i]});
        graphics.drawLine(edgeGroup, identifier, edge, findEdgeStyle(edgeIndex));
        graphics.setController(edgeGroup, identifier, createEdgeController(edgeIndex));
      }

      addInivisibleShapeToGraphicsContext(graphics, vertexGroup);
      for (int i = 0; i < coordinates.length - 1; i++) {
        GeometryIndex vertexIndex =
            editingService
                .getIndexService()
                .addChildren(parentIndex, GeometryIndexType.TYPE_VERTEX, i);
        String identifier = baseName + "." + editingService.getIndexService().format(vertexIndex);
        addShapeToGraphicsContext(
            graphics, vertexGroup, identifier, coordinates[i], findVertexStyle(vertexIndex));
        graphics.setController(vertexGroup, identifier, createVertexController(vertexIndex));
      }
    }
  }
  private void draw(Geometry geometry) {
    org.geomajas.gwt.client.spatial.geometry.Geometry transformed =
        mapWidget
            .getMapModel()
            .getMapView()
            .getWorldViewTransformer()
            .worldToPan(GeometryConverter.toGwt(geometry));

    GraphicsContext graphics = mapWidget.getVectorContext();
    graphics.drawGroup(mapWidget.getGroup(RenderGroup.VECTOR), geometry);

    if (transformed instanceof MultiPolygon) {
      draw(geometry, null, (MultiPolygon) transformed, graphics);
    } else if (transformed instanceof MultiPoint) {
      draw(geometry, null, (MultiPoint) transformed, graphics);
    } else if (transformed instanceof MultiLineString) {
      draw(geometry, null, (MultiLineString) transformed, graphics);
    } else if (transformed instanceof Polygon) {
      draw(geometry, null, (Polygon) transformed, graphics);
    } else if (transformed instanceof LineString) {
      draw(geometry, null, (LineString) transformed, graphics);
    } else if (transformed instanceof Point) {
      draw(geometry, null, (Point) transformed, graphics);
    }
  }
  private void draw(
      Object parentGroup, GeometryIndex parentIndex, Polygon polygon, GraphicsContext graphics) {
    String groupName = baseName;
    if (parentIndex != null) {
      groupName += "." + editingService.getIndexService().format(parentIndex);
    }

    Composite bgGroup = getOrCreateGroup(parentGroup, groupName + ".background");
    Composite geometryGroup = getOrCreateGroup(parentGroup, groupName + ".geometries");

    // Draw the exterior ring:
    GeometryIndex shellIndex =
        editingService
            .getIndexService()
            .addChildren(parentIndex, GeometryIndexType.TYPE_GEOMETRY, 0);
    if (!polygon.isEmpty()) {
      if (styleService.getBackgroundStyle() != null
          && styleService.getBackgroundStyle().getFillOpacity() > 0) {
        graphics.drawPolygon(bgGroup, "background", polygon, findGeometryStyle(shellIndex));
      }
      draw(geometryGroup, shellIndex, polygon.getExteriorRing(), graphics);
    }

    // Draw the interior rings:
    for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
      GeometryIndex holeIndex =
          editingService
              .getIndexService()
              .addChildren(parentIndex, GeometryIndexType.TYPE_GEOMETRY, i + 1);
      draw(geometryGroup, holeIndex, polygon.getInteriorRingN(i), graphics);
    }
  }
  private void draw(
      Object parentGroup,
      GeometryIndex parentIndex,
      LineString lineString,
      GraphicsContext graphics) {
    String groupName = baseName;
    if (parentIndex != null) {
      groupName += "." + editingService.getIndexService().format(parentIndex);
    }
    Composite edgeGroup = getOrCreateGroup(parentGroup, groupName + ".edges");
    Composite vertexGroup = getOrCreateGroup(parentGroup, groupName + ".vertices");

    Coordinate[] coordinates = lineString.getCoordinates();
    if (coordinates != null) {
      // Draw individual edges:
      for (int i = 1; i < coordinates.length; i++) {
        GeometryIndex edgeIndex =
            editingService
                .getIndexService()
                .addChildren(parentIndex, GeometryIndexType.TYPE_EDGE, i - 1);
        String identifier = baseName + "." + editingService.getIndexService().format(edgeIndex);

        LineString edge =
            lineString
                .getGeometryFactory()
                .createLineString(new Coordinate[] {coordinates[i - 1], coordinates[i]});
        graphics.drawLine(edgeGroup, identifier, edge, findEdgeStyle(edgeIndex));
        graphics.setController(edgeGroup, identifier, createEdgeController(edgeIndex));
      }

      addInivisibleShapeToGraphicsContext(graphics, vertexGroup);
      for (int i = 0; i < coordinates.length; i++) {
        GeometryIndex vertexIndex =
            editingService
                .getIndexService()
                .addChildren(parentIndex, GeometryIndexType.TYPE_VERTEX, i);
        String identifier = baseName + "." + editingService.getIndexService().format(vertexIndex);

        addShapeToGraphicsContext(
            graphics, vertexGroup, identifier, coordinates[i], findVertexStyle(vertexIndex));
        graphics.setController(vertexGroup, identifier, createVertexController(vertexIndex));
      }
    }
  }
 private void addShapeToGraphicsContext(
     GraphicsContext graphics,
     Object parentGroup,
     String identifier,
     Coordinate coordinate,
     ShapeStyle style) {
   int vertexSize = getStyleService().getPointSymbolizerShapeAndSize().getSize();
   int halfVertexSize = vertexSize / 2;
   switch (styleService.getPointSymbolizerShapeAndSize().getShape()) {
     case SQUARE:
       Bbox rectangle =
           new Bbox(
               coordinate.getX() - halfVertexSize,
               coordinate.getY() - halfVertexSize,
               vertexSize,
               vertexSize);
       graphics.drawRectangle(parentGroup, identifier, rectangle, style);
       break;
     case CIRCLE:
       graphics.drawCircle(parentGroup, identifier, coordinate, vertexSize, style);
       break;
   }
 }
  private void draw(
      Object parentGroup, GeometryIndex parentIndex, Point point, GraphicsContext graphics) {
    String groupName = baseName;
    if (parentIndex != null) {
      groupName += "." + editingService.getIndexService().format(parentIndex);
    }
    Composite vertexGroup = getOrCreateGroup(parentGroup, groupName + ".vertices");

    addInivisibleShapeToGraphicsContext(graphics, vertexGroup);
    if (!point.isEmpty()) {
      GeometryIndex vertexIndex =
          editingService
              .getIndexService()
              .addChildren(parentIndex, GeometryIndexType.TYPE_VERTEX, 0);
      String identifier = baseName + "." + editingService.getIndexService().format(vertexIndex);

      addShapeToGraphicsContext(
          graphics, vertexGroup, identifier, point.getCoordinate(), findVertexStyle(vertexIndex));
      graphics.setController(vertexGroup, identifier, createVertexController(vertexIndex));
    }
  }