arcgissamples\display\AddLogoCommand.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package arcgissamples.display; import com.esri.arcgis.carto.IDynamicMap; import com.esri.arcgis.controls.BaseCommand; import com.esri.arcgis.controls.HookHelper; public class AddLogoCommand extends BaseCommand { private static final long serialVersionUID = 1L; HookHelper hookHelper = null; public AddLogoCommand() { super(); caption = "Add ESRI Logo"; enabled = true; } LogoLayer myLayer; public void onClick() { try { if (myLayer == null) myLayer = new LogoLayer(); if (!toggledOn) { // Enable Dynamic map mode IDynamicMap dynamicMap = (IDynamicMap) hookHelper.getFocusMap(); if (!dynamicMap.isDynamicMapEnabled()) dynamicMap.setDynamicMapEnabled(true); // Add ESRI logo layer hookHelper.getFocusMap().addLayer(myLayer); } else { // Disable Dynamic mode IDynamicMap dynamicMap = (IDynamicMap) hookHelper.getFocusMap(); if (dynamicMap.isDynamicMapEnabled()) dynamicMap.setDynamicMapEnabled(false); // Remove ESRI logo layer hookHelper.getFocusMap().deleteLayer(myLayer); } } catch (Exception e) { e.printStackTrace(); } toggledOn = !toggledOn; } boolean toggledOn = false; public boolean isChecked() { return toggledOn; } public void onCreate(Object arg0) { try { hookHelper = new HookHelper(); hookHelper.setHookByRef(arg0); this.bitmapPath = this.getClass().getClassLoader().getResource( "esri_logo_command.png").getPath(); if(System.getProperty("os.name").toLowerCase().indexOf("win")>-1){ this.bitmapPath =this.bitmapPath.substring(1).replaceAll("%20"," "); } } catch (Exception e) { e.printStackTrace(); } } }