简体   繁体   中英

Add element to existing group using svg.js

I have a loaded svg map, and then I create some paths that I want to be added inside a group of the loaded SVG, but I cant.

Here I load my map

var mapa = SVG('map').size('100%', '100%');

var mapLoad = new XMLHttpRequest();
mapLoad.open('GET', 'img/my_map.svg', true);
mapLoad.send();
mapLoad.onload = function(e) {
  mapa.svg(mapLoad.responseText);
}

Then I create some paths in the SVG

var plane = mapa.path('...');

And this is the actual result

那就是我得到的结果

What I want is to add all those paths inside the "#content" group

Your new mapa is an element within your markup, not the root element, so just use that element when you create new content.

var mapa = SVG('map').size('100%', '100%');

var mapLoad = new XMLHttpRequest();
mapLoad.open('GET', 'img/my_map.svg', true);
mapLoad.send();
mapLoad.onload = function(e) {
  mapa.svg(mapLoad.responseText);
  mapa = SVG.get('mapa');
  var plane = mapa.path('...');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM