void MapPainterCanvas::DrawSymbol(const Projection& projection,
                     const MapParameter& parameter, const Symbol& symbol,
                     double x, double y)
  {
    double minX;
    double minY;
    double maxX;
    double maxY;

    symbol.GetBoundingBox(minX,minY,maxX,maxY);

    for (std::list<DrawPrimitiveRef>::const_iterator p=symbol.GetPrimitives().begin();
         p!=symbol.GetPrimitives().end();
         ++p) {
      FillStyleRef fillStyle=(*p)->GetFillStyle();

      DrawPrimitivePath(projection,
                        parameter,
                        *p,
                        x, y,
                        minX,
                        minY,
                        maxX,
                        maxY);

      DrawFillStyle(projection,
                    parameter,
                    *fillStyle);
    }
  }
Ejemplo n.º 2
0
  void MapPainterAgg::DrawSymbol(const Projection& projection,
                                 const MapParameter& parameter,
                                 const Symbol& symbol,
                                 double x, double y)
  {
    double minX;
    double minY;
    double maxX;
    double maxY;
    double centerX;
    double centerY;

    symbol.GetBoundingBox(minX,minY,maxX,maxY);

    centerX=maxX-minX;
    centerY=maxY-minY;

    for (std::list<DrawPrimitiveRef>::const_iterator p=symbol.GetPrimitives().begin();
         p!=symbol.GetPrimitives().end();
         ++p) {
      DrawPrimitive* primitive=p->Get();

      if (dynamic_cast<PolygonPrimitive*>(primitive)!=NULL) {
        PolygonPrimitive* polygon=dynamic_cast<PolygonPrimitive*>(primitive);
        FillStyleRef      style=polygon->GetFillStyle();
        agg::path_storage path;

        for (std::list<Coord>::const_iterator pixel=polygon->GetCoords().begin();
             pixel!=polygon->GetCoords().end();
             ++pixel) {
          if (pixel==polygon->GetCoords().begin()) {
            path.move_to(x+projection.ConvertWidthToPixel(pixel->x-centerX),
                         y+projection.ConvertWidthToPixel(maxY-pixel->y-centerY));
          }
          else {
            path.line_to(x+projection.ConvertWidthToPixel(pixel->x-centerX),
                         y+projection.ConvertWidthToPixel(maxY-pixel->y-centerY));
          }
        }

        path.close_polygon();

        rasterizer->add_path(path);

        DrawFill(projection,
                 parameter,
                 *style,
                 path);
      }
      else if (dynamic_cast<RectanglePrimitive*>(primitive)!=NULL) {
        RectanglePrimitive* rectangle=dynamic_cast<RectanglePrimitive*>(primitive);
        FillStyleRef        style=rectangle->GetFillStyle();
        agg::path_storage   path;
        double              xPos=x+projection.ConvertWidthToPixel(rectangle->GetTopLeft().x-centerX);
        double              yPos=y+projection.ConvertWidthToPixel(maxY-rectangle->GetTopLeft().y-centerY);
        double              width=projection.ConvertWidthToPixel(rectangle->GetWidth());
        double              height=projection.ConvertWidthToPixel(rectangle->GetHeight());

        path.move_to(xPos,yPos);
        path.line_to(xPos+width,yPos);
        path.line_to(xPos+width,yPos+height);
        path.line_to(xPos,yPos+height);

        path.close_polygon();

        rasterizer->add_path(path);

        DrawFill(projection,
                 parameter,
                 *style,
                 path);
      }
      else if (dynamic_cast<CirclePrimitive*>(primitive)!=NULL) {
        CirclePrimitive*  circle=dynamic_cast<CirclePrimitive*>(primitive);
        FillStyleRef      style=circle->GetFillStyle();
        agg::path_storage path;
        double            radius=projection.ConvertWidthToPixel(circle->GetRadius());

        agg::ellipse ellipse(x+projection.ConvertWidthToPixel(circle->GetCenter().x-centerX),
                             y+projection.ConvertWidthToPixel(maxY-circle->GetCenter().y-centerY),
                             radius,
                             radius);

        path.concat_path(ellipse);

        rasterizer->add_path(path);

        DrawFill(projection,
                 parameter,
                 *style,
                 path);
      }
    }
  }
  void MapPainterCanvas::DrawContourSymbol(const Projection& projection,
                                           const MapParameter& parameter,
                                           const Symbol& symbol,
                                           double space,
                                           size_t transStart, size_t transEnd)
  {
    double lineLength=0;

    int numPoints=transEnd-transStart+1;

    double *onPathX=new double[numPoints];
    double *onPathY=new double[numPoints];

    double *segmentLengths=new double[numPoints-1];

    for(int i=0; i<numPoints; i++)
    {
      onPathX[i]=(double)transBuffer.buffer[transStart+i].x;
      onPathY[i]=(double)transBuffer.buffer[transStart+i].y;

      if (i!=0)
        segmentLengths[i-1]=sqrt(pow(onPathX[i]-onPathX[i-1], 2.0)+
                                 pow(onPathY[i]-onPathY[i-1], 2.0));

      lineLength+=segmentLengths[i-1];
    }

    double minX;
    double minY;
    double maxX;
    double maxY;

    symbol.GetBoundingBox(minX,minY,maxX,maxY);

    double width=ConvertWidthToPixel(parameter,maxX-minX);
    double height=ConvertWidthToPixel(parameter,maxY-minY);

    for (std::list<DrawPrimitiveRef>::const_iterator p=symbol.GetPrimitives().begin();
         p!=symbol.GetPrimitives().end();
         ++p)
    {
      FillStyleRef fillStyle=(*p)->GetFillStyle();

      double offset=space/2;

      while (offset+width<lineLength)
      {
        DrawPrimitivePath(projection,
                          parameter,
                          *p,
                          offset+width/2,
                          0,
                          minX,
                          minY,
                          maxX,
                          maxY,
                          onPathX, onPathY,
                          segmentLengths);

        DrawFillStyle(projection,
                      parameter,
                      *fillStyle);

        offset+=width+space;
      }
    }
  }