adding image namespace in svg through JS still doesn't show me the picture

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

adding image namespace in svg through JS still doesn't show me the picture

MrSmile
after working out getting the parameter through a scaled version of a
picture, I am trying through Javascript adding the picture with the
original size parameter in SVG.

Firebug shows me the element, and all the necessary parameter, but
with best wishes I am not getting through to get the image itself
being displayed.

this.svg = document.getElementsByTagNameNS('http://www.w3.org/2000/
svg','svg');
var bild = document.createElementNS('http://www.w3.org/2000/
svg','image');
var BildURL = this.image[0][0].getAttribute('xlink:href');
var imgX = new Image();
imgX.src = BildURL;

bild.setAttribute("x","60");
bild.setAttribute("y","40");
bild.setAttribute("width",imgX.width);
bild.setAttribute("height",imgX.height);
bild.setAttribute("id","image12976");
bild.setAttribute("xlink:href",BildURL);
this.svg[0].appendChild(bild);

If i take a look in Firebug, the element fully exists.

Any ideas to solve it?!


for any advises, I would kindly thank you.


Tamer
_______________________________________________
dev-tech-svg mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-svg
Reply | Threaded
Open this post in threaded view
|

Re: adding image namespace in svg through JS still doesn't show me the picture

Holger Jeromin-3
Martin Honnen schrieb am 02.08.2011 16:20:
> Tamer Higazi wrote:
>> bild.setAttribute("xlink:href",BildURL);
>> this.svg[0].appendChild(bild);
>> If i take a look in Firebug, the element fully exists.
>> Any ideas to solve it?!
> Well you certainly need
>    bild.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
> BildURL)
> to create the proper XLINK href attribute.

My guess would be
bild.setAttributeNS('http://www.w3.org/1999/xlink', 'href', BildURL);

--
Holger
_______________________________________________
dev-tech-svg mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-svg
Reply | Threaded
Open this post in threaded view
|

Re: adding image namespace in svg through JS still doesn't show me the picture

Cameron McCormack-4
Martin Honnen schrieb am 02.08.2011 16:20:
> > Well you certainly need
> >    bild.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
> > BildURL)
> > to create the proper XLINK href attribute.

Holger Jeromin:
> My guess would be
> bild.setAttributeNS('http://www.w3.org/1999/xlink', 'href', BildURL);

Either of those should work, and are roughly equivalent.  (The only time
it really matters whether you specify a prefix in the second argument is
when you are doing a naive serialisation of the DOM to XML, where you
assume the specified prefix is correct.  Which you shouldn’t.)

--
Cameron McCormack ≝ http://mcc.id.au/
_______________________________________________
dev-tech-svg mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-svg
Reply | Threaded
Open this post in threaded view
|

Re: adding image namespace in svg through JS still doesn't show me the picture

Robert Longson
In reply to this post by MrSmile
On Aug 1, 3:08 am, Tamer Higazi <[hidden email]> wrote:
>
> this.svg = document.getElementsByTagNameNS('http://www.w3.org/2000/
> svg','svg');
> var bild = document.createElementNS('http://www.w3.org/2000/
> svg','image');
> var BildURL = this.image[0][0].getAttribute('xlink:href');

you should probably use getAttributeNS instead.

> var imgX = new Image();
> imgX.src = BildURL;
>
> bild.setAttribute("x","60");
> bild.setAttribute("y","40");
> bild.setAttribute("width",imgX.width);
> bild.setAttribute("height",imgX.height);
> bild.setAttribute("id","image12976");
> bild.setAttribute("xlink:href",BildURL);

setAttributeNS

Is there a complete example somewhere to examine? I'm only guessing
that these changes may improve things at the moment.

Best regards

Robert.
_______________________________________________
dev-tech-svg mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-svg
Reply | Threaded
Open this post in threaded view
|

Re: adding image namespace in svg through JS still doesn't show me the picture

Robert Longson
In reply to this post by MrSmile
>
> this.svg = document.getElementsByTagNameNS('http://www.w3.org/2000/
> svg','svg');
> var bild = document.createElementNS('http://www.w3.org/2000/
> svg','image');
> var BildURL = this.image[0][0].getAttribute('xlink:href');

This needs to use getAttributeNS

> bild.setAttribute("xlink:href",BildURL);

And this needs to use setAttributeNS

I'm not sure what if anything else is wrong as this seems to be a
partial example

Best regards

Robert.
_______________________________________________
dev-tech-svg mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-svg