Loading ...
Sorry, an error occurred while loading the content.

Re: [svg-developers] Drag group of elements and line end

Expand Messages
  • Age Bosma
    Thank you for your reply. ... The properties don t have to communicate back to a database but I do need it in various other locations of the Java application.
    Message 1 of 5 , Mar 8, 2009
    • 0 Attachment
      Thank you for your reply.

      ddailey wrote:

      > Unless the properties of the car have to somehow be communicated back to a database, then I'm not sure why doing what you're talking about in JavaScript would be a problem (and even so then you'd just use JSON or AJAX to ship data back and forth asynchronously).
      >

      The properties don't have to communicate back to a database but I do
      need it in various other locations of the Java application. Would using
      JSON or AJAX be more efficient in that case? If yes, do you have some
      resources explaining how to use JSON or AJAX in combination with SVG?

      > So I'd just use JavaScript to drag the car and to redraw the line as the car moves. With each mousemove, reposition the group and reset the x1 and y1 attributes of the line.
      >

      I came to this conclusion as well. This, however, would work when using
      a line, not a path as far as I can tell. The only solution I can think
      of when using a path is to perform some string replacements on the 'd'
      attribute (locate the 'M' command, change the points). Something which
      isn't very clean. Is there any other way to just replace the 'M' command?

      The second issue is getting the path element in the first place. I take
      it there's no easier way then to a) give each line a special 'id', one
      which can be determined by the 'id' of the car group or b) add both the
      car group and the path to a second group and walk the DOM until it finds
      a path in the same group as the car group. Too bad SVG doesn't support
      some kind of snapping behaviour ;-)

      Yours,

      Age
    • David Leunen
      Hey, The only solution I can think ... Yes there is. Are you aware of the SVGPathElement? http://www.w3.org/TR/SVG/paths.html#InterfaceSVGPathElement
      Message 2 of 5 , Mar 8, 2009
      • 0 Attachment
        Hey,


        The only solution I can think
        > of when using a path is to perform some string replacements on the 'd'
        > attribute (locate the 'M' command, change the points). Something which
        > isn't very clean. Is there any other way to just replace the 'M' command?


        Yes there is. Are you aware of the SVGPathElement?
        http://www.w3.org/TR/SVG/paths.html#InterfaceSVGPathElement
        http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/dom/svg/SVGOMPathElement.html
        You can get its pathSegList and modify it without having to parse the 'd'
        attribute yourself.




        > The second issue is getting the path element in the first place. I take
        > it there's no easier way then to a) give each line a special 'id', one
        > which can be determined by the 'id' of the car group or b) add both the
        > car group and the path to a second group and walk the DOM until it finds
        > a path in the same group as the car group. Too bad SVG doesn't support
        > some kind of snapping behaviour ;-)


        What do you mean exactly ?
        By using SMIL (batik does support it pretty well) you can use an
        <animationMotion> and a <mpath> linked to your dynamic path.
        See this example in Batik or Opera :
        http://www.w3.org/TR/SVG/images/animate/animMotion01.svg
        It's from here : http://www.w3.org/TR/SVG/animate.html#AnimateMotionElement
        But yes, in order to link your car to the animation path, you have to give
        the path an id.


        cheers.

        David


        [Non-text portions of this message have been removed]
      • Age Bosma
        ... No, I did not know about the SVGPathElement. There are just too many options :-S Many thanks, that was what I was looking for. ... What I meant was having
        Message 3 of 5 , Mar 10, 2009
        • 0 Attachment
          2009/3/8 David Leunen <leunen.d@...>:
          > Hey,
          >
          >
          > The only solution I can think
          >> of when using a path is to perform some string replacements on the 'd'
          >> attribute (locate the 'M' command, change the points). Something which
          >> isn't very clean. Is there any other way to just replace the 'M' command?
          >
          >
          > Yes there is. Are you aware of the SVGPathElement?
          > http://www.w3.org/TR/SVG/paths.html#InterfaceSVGPathElement
          > http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/dom/svg/SVGOMPathElement.html
          > You can get its pathSegList and modify it without having to parse the 'd'
          > attribute yourself.
          >

          No, I did not know about the SVGPathElement. There are just too many
          options :-S Many thanks, that was what I was looking for.

          >
          >
          >
          >> The second issue is getting the path element in the first place. I take
          >> it there's no easier way then to a) give each line a special 'id', one
          >> which can be determined by the 'id' of the car group or b) add both the
          >> car group and the path to a second group and walk the DOM until it finds
          >> a path in the same group as the car group. Too bad SVG doesn't support
          >> some kind of snapping behaviour ;-)
          >
          >
          > What do you mean exactly ?

          What I meant was having the option in SVG to say: This path point
          should always be attached to this path/location of this element. This
          way, not matter what happens to the element the path point is attached
          to, the point will always move along with the element. You wouldn't
          have to do it manually any more.

          Age
        Your message has been successfully submitted and would be delivered to recipients shortly.