private void changedOrderOfLayer() { System.out.println("Before - layer's name at index 1 is : " + map.getLayers().get(1).getName()); // Move Layer to index 0 map.getLayers().set(0, map.getLayers().get(1)); // IllegalArgumentException HERE !!! System.out.println("after - layer's name at index 1 : " + map.getLayers().get(0).getName()); }
Solved! Go to Solution.
public void setOrderOfLayer(Layer layer, int order) { // Process the reordering of layer by removing it, then adding it at the expecting order index jMap.getLayers().remove(layer); jMap.getLayers().add(order, layer); }
Re-ordering graphics layers in a map
It was too bad that this wasn�??t functional and clearer in the first release, but the team nailed it down. You can add *n* number of graphics layers to your map and reorder them on the fly. By the way, you can also use �??send to back�?� and �??bring to front�?� on graphic elements in the same layer. It can work in code as simple as this (Java) (No offense to my WPF friends!):GraphicsLayer gLayer1 = (GraphicsLayer)map.getLayers().get(1); map.getLayers().remove(2); map.getLayers().add(3,gLayer1);