Select to view content in your preferred language

how to modify 1.3 bookmark widget

885
4
03-31-2011 01:24 PM
DanielLewis
Emerging Contributor
This is probably more of a AS/flex question than specifically flex viewer, but I'm trying to modify the 1.3 bookmark widget so that it shows only the name of the bookmark, not the name with the x/y coords.  I've tried commenting out minx/miny in a few locations, but the bookmarks don't work when I do that.  Any help is appreciated.

I believe the relevant section of the source is here:

<WidgetTemplate id="wTemplate">
  <mx:ViewStack id="viewStack" width="100%" height="170" creationPolicy="all">
   <mx:VBox width="100%" height="100%" verticalGap="1">
    <mx:Repeater id="wRepeater" dataProvider="{bookmarkAC}">
     <widgets:RecordBookmark recid="{wRepeater.currentIndex}" bookmark="{wRepeater.currentItem}" click="clickRecord(event)" bookmarkDelete="removeBookmark(event)"/>
    </mx:Repeater>
   </mx:VBox>
   <mx:VBox width="100%" height="100%" verticalGap="10" paddingTop="10">
    <mx:Label text="{addLabel}" styleName="WidgetText" width="100%" />
    <mx:TextInput id="txtName" width="100%" />
    <mx:HBox horizontalAlign="center" width="100%">
     <mx:Button label="{submitLabel}" click="addBookmark()"/>
    </mx:HBox>
   </mx:VBox>
  </mx:ViewStack>
</WidgetTemplate>

</BaseWidget>
Tags (2)
0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Daniel,

  Look at line 88 of the RecordBookmark.mxml and comment it out

<!--mx:Text selectable="false" styleName="RecordText" fontWeight="normal" text="{content}" width="90%"/-->
0 Kudos
DanielLewis
Emerging Contributor
Daniel,

  Look at line 88 of the RecordBookmark.mxml and comment it out

<!--mx:Text selectable="false" styleName="RecordText" fontWeight="normal" text="{content}" width="90%"/-->



Thank you for the reply.  This source has been customized and the line you mentioned doesn't exist (nothing like it in the source).  Here's the source (minus a few lines to make it fit in the 10000 character limit):


<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
//
// Copyright © 2008 - 2009 ESRI
//
////////////////////////////////////////////////////////////////////////////////
-->
<BaseWidget xmlns:esri   ="http://www.esri.com/2008/ags" 
   xmlns    ="com.esri.solutions.flexviewer.*" 
   xmlns:mx   ="http://www.adobe.com/2006/mxml" 
   xmlns:mxeffects  ="com.adobe.ac.mxeffects.*"
   xmlns:widgets  ="com.esri.solutions.flexviewer.widgets.*"
   x     ="600" 
   y     ="300" 
   widgetConfigLoaded ="init()">
 
 
 <mx:Script>
  <![CDATA[
  
   import com.esri.ags.geometry.Extent;
   import com.esri.solutions.flexviewer.utils.WidgetEffects;
   import flash.net.SharedObject;
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;   
   import flash.net.SharedObject;
   import com.esri.serialization.json.JSON;
   private var bookmarksLabel:String;
   private var addbookmarksLabel:String;
   [Bindable]
   private var addLabel:String;
   [Bindable]
   private var submitLabel:String;
   private var errorLabel:String;
   [Bindable]
   private var bookmarkAC:ArrayCollection;
   
   private var bookmarkSO:SharedObject;
   
   private const BOOKMARKS:String = "bookmarks";
   
   private const ICON_URL:String = "com/esri/solutions/flexviewer/assets/images/icons/";
   
   private var fr:FileReference;
   private var savebookmarksLabel:String;   
   private var loadbookmarksLabel:String;
       
   private function init():void
   {
    try
    {
     if (configXML)
     {
         bookmarksLabel = configXML.labels.bookmarkslabel || "Bookmarks";
      addbookmarksLabel = configXML.labels.addbookmarkslabel || "Add Bookmarks";
      savebookmarksLabel = configXML.labels.savebookmarkslabel || "Save Bookmarks to file";
      loadbookmarksLabel = configXML.labels.loadbookmarkslabel || "Load Bookmarks from file";
      
      addLabel = configXML.labels.addlabel || "Add current extent as bookmark named:";
      submitLabel = configXML.labels.submitlabel || "Add Bookmark";
      errorLabel = configXML.labels.errorlabel || "Please enter a name for the bookmark.";
     }
     
     wTemplate.addTitlebarButton(ICON_URL + "i_bookmark_add.png", addbookmarksLabel, showStateAdd);
     wTemplate.addTitlebarButton(ICON_URL + "i_bookmark.png", bookmarksLabel, showStateBookmarks);
     
     wTemplate.addTitlebarButton(ICON_URL + "i_save.png", savebookmarksLabel, saveStateBookmarks);
     wTemplate.addTitlebarButton(ICON_URL + "i_folder.png", loadbookmarksLabel, loadStateBookmarks);
     
     bookmarkAC = new ArrayCollection();
              bookmarkSO = SharedObject.getLocal(BOOKMARKS);
              if (bookmarkSO.size > 0) {
                   loadBookmarks();
              }
              else
              {
               loadBookmarks();
              }
      }
      catch (error:Error)
    {
     showError(error.message);
    } 
   }   
   
   private function loadStateBookmarks(event:MouseEvent):void
   {
    try
    {
     fr = new FileReference();
 
     fr.addEventListener(Event.SELECT, onFileSelect);
 
     fr.addEventListener(Event.CANCEL,onCancel);
 
     fr.browse(FILE_TYPES);
    }
    catch (error:Error)
    {
     showError(error.message);
    }
   }
   
   private function saveStateBookmarks(event:MouseEvent):void
   {
    try
    {
     if(!fr) fr = new FileReference();
     fr.save(JSON.encode(bookmarkAC.source),"SavedBookMark.txt")
    }
    catch (error:Error)
    {
     showError(error.message);
    }    
   } 
   
   private static const FILE_TYPES:Array = [new FileFilter("Bookmark File", "*.txt;")];

   private function onFileSelect(e:Event):void
   {
    try
    {
     fr.addEventListener(Event.COMPLETE, onLoadComplete);
 
     fr.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
 
     fr.load();
    }
    catch (error:Error)
    {
     showError(error.message);
    }
   }

   private function onCancel(e:Event):void
   {
    trace("File Browse Canceled");
    fr = null;
   }
   
 
   private function onLoadComplete(e:Event):void
   {
    try
    {
     var data:ByteArray = fr.data;
     var dobj:Object = JSON.decode(data.readUTFBytes(data.bytesAvailable));    
     fr = null;
     
     bookmarkAC.removeAll();
     
 
     var i:Number;
     for (i = 0; i < dobj.length; i++)
     {       
      var gObj:Object = dobj;
      var icon:String = gObj.recicon;      
      var name:String = gObj.name;      
      var bookmark:Object = 
      {
       recicon: icon, 
       name: name,
       xmin: Number(gObj.xmin), 
       ymin: Number(gObj.ymin), 
       xmax: Number(gObj.xmax), 
       ymax: Number(gObj.ymax)
      
      }
      bookmarkAC.addItem(bookmark);
       
     }
     updateBookmarks();
    }
    catch (error:Error)
    {
     showError(error.message);
    }
   }
   
   private function onLoadError(e:IOErrorEvent):void
   {
    trace("Error loading file : " + e.text);
   }
   
   private function showStateBookmarks(event:MouseEvent):void
   {
    WidgetEffects.flipWidget(this, viewStack, "selectedIndex", 0, 400);
   }    
      
   private function showStateAdd(event:MouseEvent):void
   {
    WidgetEffects.flipWidget(this, viewStack, "selectedIndex", 1, 400);
   }   
   
   private function loadBookmarks():void
   {
    try
    {
     if (configXML)
     {
      var bookmarkList:XMLList = configXML..bookmark;
      for (var i:Number = 0; i < bookmarkList.length(); i++)
      {
       var icon:String = widgetIcon;
       var name:String = bookmarkList.@name;
       var extent:String = bookmarkList;
       var extArray:Array = extent.split(" ");
       var bookmark:Object = 
       {
        recicon: icon, 
        name: name,
        xmin: Number(extArray[0]), 
        ymin: Number(extArray[1]), 
        xmax: Number(extArray[2]), 
        ymax: Number(extArray[3])
       
       }
       bookmarkAC.addItem(bookmark);
      }
      updateBookmarks();
     }
    } 
    catch (error:Error)
    {
     showError(error.message);
    }
   }   
   
   private function getBookmarks():ArrayCollection 
   {
    try
    {
              return bookmarkSO.data[BOOKMARKS];
       }
       catch (error:Error)
    {
     showError(error.message);
    }
    return null;
         }

   private function addBookmark():void 
   {
    try
    {
        var name:String = txtName.text;
        if (name)
        {
         var icon:String = widgetIcon;
      var ext:Extent = map.extent;
      var bookmark:Object = 
      {
       recicon: icon, 
       name: name,
       xmin: ext.xmin.toFixed(2), 
       ymin: ext.ymin.toFixed(2), 
       xmax: ext.xmax.toFixed(2), 
       ymax: ext.ymax.toFixed(2)
      }
      bookmarkAC.addItem(bookmark);
            updateBookmarks();
            txtName.text = "";
            WidgetEffects.flipWidget(this, viewStack, "selectedIndex", 0, 400);
        }
         else
        {
         Alert.show(errorLabel);
     }
    }
    catch (error:Error)
    {
     showError(error.message);
    }
      }

   public function removeBookmark(event:Event):void 
   {
    try
    {
     var id:int = event.currentTarget.recid
           bookmarkAC.removeItemAt(id);
           updateBookmarks();
     }
       catch (error:Error)
    {
     showError(error.message);
    }
      }

      private function updateBookmarks():void 
      {
       try
       {
           bookmarkSO.data[BOOKMARKS] = bookmarkAC;
           bookmarkSO.flush();
        }
        catch (error:Error)
    {
     showError(error.message);
    }
      }

   private function clickRecord(event:MouseEvent):void
   {
    try
    {
     var bookmark:Object = event.currentTarget.bookmark;
     var ext:Extent = new Extent(bookmark.xmin, bookmark.ymin, bookmark.xmax, bookmark.ymax);
     map.extent = ext;
    }
    catch (error:Error)
    {
     showError(error.message);
    }
   }
    
  ]]>
 </mx:Script>
 

 <WidgetTemplate id="wTemplate">
  <mx:ViewStack id="viewStack" width="100%" height="170" creationPolicy="all">
   <mx:VBox width="100%" height="100%" verticalGap="1">
    <mx:Repeater id="wRepeater" dataProvider="{bookmarkAC}">
     <widgets:RecordBookmark recid="{wRepeater.currentIndex}" bookmark="{wRepeater.currentItem}" click="clickRecord(event)" bookmarkDelete="removeBookmark(event)"/>
    </mx:Repeater>
   </mx:VBox>
   <mx:VBox width="100%" height="100%" verticalGap="10" paddingTop="10">
    <mx:Label text="{addLabel}" styleName="WidgetText" width="100%" />
    <mx:TextInput id="txtName" width="100%" />
    <mx:HBox horizontalAlign="center" width="100%">
     <mx:Button label="{submitLabel}" click="addBookmark()"/>
    </mx:HBox>
   </mx:VBox>
  </mx:ViewStack>
 </WidgetTemplate>
 
</BaseWidget>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Daniel,

  You are still looking at the wrong file you need to find the RecordBookmark.mxml
0 Kudos
DanielLewis
Emerging Contributor
Daniel,

  You are still looking at the wrong file you need to find the RecordBookmark.mxml


😮  Thanks!  That worked!
0 Kudos