Wesley Bakker

Interesting things I encounter doing my job...

Sponsors

News

Wesley Bakker
motion10
Rivium Quadrant 151
2909 LC Capelle aan den IJssel
Region of Rotterdam
The Netherlands
Phone: +31 10 2351035

(feel free to chat with me)

Add to Technorati Favorites

Virtual Earth Web Part

This is part two in a series of posts on how to create a Virtual Earth Web Part. In this post we’ll finish our properties with their attributes. I’ll explain the differences between the V2 web part attributes and the V3 web part attributes, and what these attributes actually do.

Remember from our first post that we inherit a microsoft.sharepoint.webpartpages.webpart  aka V2 web part. I can reveal now that we have to do this in order to make it possible to implement the IListConsumer and IRowConsumer interfaces later to connect to our Contacts list. The reason we have to implement those interfaces is because the SharePoint List View web part sadly does not implement the recommended IWebPartTable as you can read in my previous post.

Since we inherit the SharePoint web part we need to use some ‘legacy’ attributes but we’ll do fine. First focus on what we want before we focus on how to do it.

Properties

The properties I would like to implement because those get asked for pretty often are these:

Pushpins
A generic list with pushpins. We already discussed this property extensively in post one from this series
Zoom level
(int) The zoom level of the map. We can set this zoom level manually or let the next property decide the best possible zoom level.
Auto zoom
(bool) Auto zoom will first place all pushpins on the map and then decide what's the best zoom level in which all pushpins are visible on the map.
Show info box
(bool) With this option enabled the info box of the last added item with a description will be shown. This comes in handy if you place just one address on the map and want to display the address lines themselves or the company name above the pushpin.
Fixed
(bool) With this option enabled the client will lose all interaction with the map control. Comes in handy with a single address again.
Dashboard size
(VEDashBoard enum) This property does exactly what you'll expect. You can determine the dashboard size with it.

Property code

The code isn't that difficult it's just that we have to use different attributes than we are familiar with because we use a V2 web part. First the code and than we'll discus the different attributes:

/// <summary>
/// Gets or sets the zoom level.
/// </summary>
/// <value>The zoom level.</value>
[Browsable(true)]
[Category("Map Settings")]
[WebPartStorage(Storage.Shared)]
[FriendlyName("Zoom level")]
[Description("The zoom level of the Virtual Earth control.")]
public int ZoomLevel {
    get {
        return _zoomlevel;
    }
    set {
        if (value < 1 || value > 19) {
            throw new WebPartPageUserException("can't be less than 1 or greater than 19!");
        }
        _zoomlevel = value;
    }
}
 
/// <summary>
/// Gets or sets a value indicating whether to auto zoom.
/// </summary>
/// <value><c>true</c> if auto zoom is enabled; otherwise, <c>false</c>.</value>
[Browsable(true)]
[Category("Map Settings")]
[WebPartStorage(Storage.Shared)]
[FriendlyName("Auto Zooming")]
[Description("Sets the zoom level of the Virtual Earth control to a level where all pushpins are visible if set to true")]
public bool AutoZoom {
    get {
        return _autoZoom;
    }
    set {
        _autoZoom = value;
    }
}
 
/// <summary>
/// Gets or sets a value indicating whether to fix the map.
/// </summary>
/// <value><c>true</c> if the map should be fixed; otherwise, <c>false</c>.</value>
[Browsable(true)]
[Category("Map Settings")]
[WebPartStorage(Storage.Shared)]
[FriendlyName("Fixed")]
[Description("Disables client interactions with the Virtual Earth control if set to true")]
public bool Fixed {
    get {
        return _fixed;
    }
    set {
        _fixed = value;
    }
}
 
/// <summary>
/// Gets or sets a value indicating whether to show the info box.
/// </summary>
/// <value><c>true</c> if info box is to be shown; otherwise, <c>false</c>.</value>
[Browsable(true)]
[Category("Map Settings")]
[WebPartStorage(Storage.Shared)]
[FriendlyName("Show Info Box")]
[Description("Shows the info box of the last added pushpin with a description, on open")]
public bool ShowInfoBox {
    get {
        return _showInfoBox;
    }
    set {
        _showInfoBox = value;
    }
}
 
/// <summary>
/// Gets or sets the size of the dashboard.
/// </summary>
/// <value>The size of the dashboard.</value>
[Browsable(true)]
[Category("Map Settings")]
[WebPartStorage(Storage.Shared)]
[FriendlyName("Dashboard size")]
[Description("The size of the virtual earth dashboard")]
public VEDashboardSize DashboardSize {
    get {
        return _dashBoardSize;
    }
    set {
        _dashBoardSize = value;
    }
}

So it’s all straight forward. We do some validation in which we use the WebPartPageUserException to give the client a decent error message and we added some attributes.

Attributes

SharePoint uses different attributes to give the developer some influence over what properties get displayed, how they get displayed and how they are stored. Let’s walk through all the attributes used in the code above.

Browsable: This is the V2 version of WebBrowsable. With this attribute you decide whether or not the end user can view this property at all. If set to false the property will not show in the editor.

Category: This attribute is the same in V2 and V3. With this attribute you decide in which category the property shows up.

Category

WebPartStorage: This is the V2 version of Personalizable. With this attribute you decide if this property is shared or personal. If set the Personal(V2) or User(V3), the editing of this property will result in changes for the current user only. If set to Shared the editing              of this property will result in changes that effect all users that view the page.

FriendlyName: This is the V2 version of WebDisplayName. Most of the time the property name is in Pascal Case and the naming doesn’t have to make sense to the end user. With this attribute you can change the label that’s displayed with the field.

FriendlyName

Description: This is the V2 version of WebDescription. With this attribute you determine the tooltip that get’s displayed when an end user hovers the field.

Description

Conclusion

It’s not that hard to create SharePoint web part properties and there’s no big differences in the type of attribute you can use between V2 and V3. It’s just that the class names have changed. In the beginning when I started out developing V3 web parts it was kind of hard for me to see which attribute belongs to which web part type and I’ve made mistakes with it more than often. I hope this post gives some clarification to all.

Next time we’ll continue with implementing the IListConsumer and IRowConsumer interface.

Cheers,

Wes

Comments

Virtual Earth Web Part - Wesley Bakker said:

Pingback from  Virtual Earth Web Part - Wesley Bakker

# February 3, 2009 4:48 AM

Dew Drop - February 3, 2009 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - February 3, 2009 | Alvin Ashcraft's Morning Dew

# February 3, 2009 9:55 AM

Virtual Earth Web Part | IT Questions said:

Pingback from  Virtual Earth Web Part | IT Questions

# February 3, 2009 1:06 PM

Links (2/5/2009) « Steve Pietrek - Everything SharePoint said:

Pingback from  Links (2/5/2009) &laquo; Steve Pietrek - Everything SharePoint

# February 5, 2009 8:09 PM

Mirrored Blogs said:

En esta ocasion les dejo un nuevo compilado de los Articulos mas importantes y recientes para SharePoint

# February 7, 2009 6:49 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)