private function onLayerReorder(event:MapEvent):void { var layer:Layer = event.layer; var index:int = event.index; var i:int; var currentTOCIndex:int; var currentItem:Object; if (index <= (map.layerIds.length - _tocRoots.length)) // move this item to the bottom of toc { // index of item to move currentTOCIndex = getCurrentTOCIndex(); // item to move currentItem = _tocRoots.getItemAt(currentTOCIndex); for (i = currentTOCIndex; i < _tocRoots.length; i++) { if(i == _tocRoots.length - 1) { _tocRoots.setItemAt(currentItem, _tocRoots.length - 1); } else { _tocRoots.setItemAt(_tocRoots.getItemAt(i+1), i); } } } else if ((map.layerIds.length - _tocRoots.length) < index < map.layerIds.length) { // index of item to move currentTOCIndex = getCurrentTOCIndex(); // item to move currentItem = _tocRoots.getItemAt(currentTOCIndex); var newTOCIndex:Number = map.layerIds.length - index - 1; if (newTOCIndex < currentTOCIndex) { for (i = currentTOCIndex; newTOCIndex <= i; i--) { if(i == newTOCIndex) { _tocRoots.setItemAt(currentItem, newTOCIndex); } else { _tocRoots.setItemAt(_tocRoots.getItemAt(i-1), i); } } } else { for (i = currentTOCIndex; i <= newTOCIndex; i++) { if(i == newTOCIndex) { _tocRoots.setItemAt(currentItem, newTOCIndex); } else { _tocRoots.setItemAt(_tocRoots.getItemAt(i+1), i); } } } } function getCurrentTOCIndex():int { var result:int; for (i = 0; i < _tocRoots.length; i++) { if (_tocRoots.getItemAt(i) is TocMapLayerItem && TocMapLayerItem(_tocRoots.getItemAt(i)).layer === layer) { result = i; break; } } return result; } }
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.