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 GraphicsController createVertexController(GeometryIndex index) {
   CompositeGeometryIndexController controller =
       new CompositeGeometryIndexController(
           mapWidget,
           editingService,
           index,
           editingService.getEditingState() == GeometryEditState.DRAGGING);
   for (AbstractGeometryIndexMapHandler handler : EditingHandlerRegistry.getVertexHandlers()) {
     controller.addMapHandler(handler);
   }
   for (VertexMapHandlerFactory factory : customVertexFactories) {
     controller.addMapHandler(factory.create());
   }
   return controller;
 }
  private GraphicsController createGeometryController(GeometryIndex index) {
    List<AbstractGeometryIndexMapHandler> handlers = EditingHandlerRegistry.getGeometryHandlers();
    if (handlers == null || handlers.size() == 0) {
      return null;
    }

    CompositeGeometryIndexController controller =
        new CompositeGeometryIndexController(
            mapWidget,
            editingService,
            index,
            editingService.getEditingState() == GeometryEditState.DRAGGING);
    for (AbstractGeometryIndexMapHandler handler : handlers) {
      controller.addMapHandler(handler);
    }
    return controller;
  }
  public void onCoordinateSnapAttempt(CoordinateSnapEvent event) {
    if (editingService.getEditingState() == GeometryEditState.INSERTING) {
      String identifier =
          baseName + "." + editingService.getIndexService().format(editingService.getInsertIndex());
      Object parentGroup =
          groups.get(identifier.substring(0, identifier.lastIndexOf('.')) + ".vertices");

      Coordinate temp = event.getTo();
      Coordinate coordinate =
          mapWidget.getMapModel().getMapView().getWorldViewTransformer().worldToPan(temp);
      addShapeToGraphicsContext(
          mapWidget.getVectorContext(),
          parentGroup,
          identifier,
          coordinate,
          event.hasSnapped() ? styleService.getVertexSnappedStyle() : new ShapeStyle());
    }
  }
  private GraphicsController createEdgeController(GeometryIndex index) {
    CompositeGeometryIndexController controller =
        new CompositeGeometryIndexController(
            mapWidget,
            editingService,
            index,
            editingService.getEditingState() == GeometryEditState.DRAGGING);
    for (AbstractGeometryIndexMapHandler handler : EditingHandlerRegistry.getEdgeHandlers()) {
      controller.addMapHandler(handler);
    }
    for (EdgeMapHandlerFactory factory : customEdgeFactories) {
      controller.addMapHandler(factory.create());
    }

    EdgeMarkerHandler edgeMarkerHandler =
        new EdgeMarkerHandler(mapWidget, editingService, controller);
    controller.addMouseOutHandler(edgeMarkerHandler);
    controller.addMouseMoveHandler(edgeMarkerHandler);
    controller.addMapDownHandler(edgeMarkerHandler);
    return controller;
  }