xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Eccles (programming)" <programm...@gringer.org>
Subject Re: Problem overlaying SVG element on top of loaded file
Date Thu, 30 Sep 2010 13:44:51 GMT
jonathan wood has written:
> I have not tried your example, but you might try using the namespace "aware"
> dom calls instead to create your elements...kinda like

> Element circle =
> document.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI,
> SVGConstants.SVG_CIRCLE_TAG);

> and

> circle.setAttributeNS(null, Double.toString(cx));

Thanks heaps, this seemed to be the problem. You've saved me many hours of
confusing mental pain.

David Eccles (gringer)

FWIW, here's my changed city drawing method (a colour field has been added in
the meantime to another class):

  public boolean drawCities(Vector<City> cityList){
    double mapMinX = -170;
    double mapMinY = -90;
    double mapSizeX = 1000;
    double mapSizeY = 420;
    final Vector<Element> circles = new Vector<Element>();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    for(City tCity : cityList){
      double cx =  (tCity.getX() - mapMinX) * (mapSizeX / 360.0);
      // Y is inverted
      double cy =  (-tCity.getY() - mapMinY) * (mapSizeY / 180.0);
      String cs = Pathogenic.CUBECOLOURS[tCity.getColour()];
      Element cityCirc = boardDrawing.getSVGDocument().createElementNS(svgNS,
        "circle");
      cityCirc.setAttributeNS(null, "cx", Double.toString(cx));
      cityCirc.setAttributeNS(null, "cy", Double.toString(cy));
      cityCirc.setAttributeNS(null, "r", "10");
      cityCirc.setAttributeNS(null, "style",
        "fill:"+cs+";stroke:black;stroke-width:3");
      circles.add(cityCirc);
      System.out.println("Preparing " + tCity.getName() +
        " at " + cx + "," + cy);
    }
    boardDrawing.getUpdateManager().getUpdateRunnableQueue().invokeLater
      (new Runnable() {
          public void run() {
            for(Element cityCirc : circles) {
              boardDrawing.getSVGDocument().
                getRootElement().appendChild(cityCirc);
            }
          }
        });
    return true;
  }

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message