I have created a custom web part for SharePoint and using the Bing Map powerful API done the integration.
1) Firstly, I have open the visual studio 2010 and selected the “Visual web part” project and named it as a GPS viewer web part.
2) Created a new CBingMaps.js file to call load the Map with several properties :-
- function CBingMaps(name)
- {
- this.name = name;
- this.map = new VEMap(this.name.toString());
- this.dataLayer = new VEShapeLayer();
- this.staticMap = false;
- CBingMaps.prototype.GetMap = function (Longitutue, Latitute, fixed, location, Zoom, mode, mapStyle) {
- //Dispose the map if it was previously loaded.
- if (this.map != null) {
- //this.map.Dispose();
- }
- //DashBoard();
- var Longitutue = Longitutue;
- var Latitute = Latitute;
- //VEMap.LoadMap(VELatLong, zoom, style, fixed, mode, showSwitch, tileBuffer, mapOptions);
- var fixed = fixed;
- var location = location;
- if (Longitutue != 0 && Latitute != 0) {
- var latLong = new VELatLong(Longitutue, Latitute);
- if (latLong != null) {
- if (fixed.toLowerCase() == false) {
- this.map.LoadMap(latLong, Zoom, 'h', false);
- }
- else {
- this.map.LoadMap(latLong, 4, 'h', true);
- setZoomLevel(Zoom);
- }
- }
- }
- else if (location != null) {
- if (this.map != null) {
- this.map.Dispose();
- }
- this.map = new VEMap(this.name.toString());
- this.dataLayer = new VEShapeLayer();
- this.map.LoadMap();
- var veLayerSpec = new VEShapeSourceSpecification(VEDataType.VECollection, location, this.dataLayer);
- this.map.ImportShapeLayerData(veLayerSpec);
- }
- else {
- this.map.LoadMap();
- }
- //map.setCredentials("AipIzr5QKQBNJhb1yF_ex5CFZQSKh1eeUq9OQi3MiF8kTYeER9lUQ5rsZw6xlymU");
- this.ChangeMapStyle(mapStyle);
- this.setMapMode(mode);
- }
- CBingMaps.prototype.DashBoard = function (properties) {
- var prop = properties;
- //var lDashBoradStaus = '<%= DashBoard.ToString() %>';
- if (properties.On == true) {
- this.map.ShowDashboard();
- }
- else {
- this.map.HideDashboard();
- }
- }
- CBingMaps.prototype.setZoomLevel = function (properties) {
- var zoomlevel = properties;
- //var zoomlevel = <%= Zoom %>;
- zoomlevel = zoomlevel + 1;
- this.map.SetZoomLevel(zoomlevel);
- }
- CBingMaps.prototype.setMapMode = function (properties) {
- var mode = properties;
- if (properties.CommandValueId != null) {
- mode = properties.CommandValueId;
- }
- if (mode.toString().toUpperCase() == "MODE2D") {
- this.map.SetMapMode(VEMapMode.Mode2D);
- }
- else if (mode.toString().toUpperCase() == "MODE3D") {
- this.map.SetMapMode(VEMapMode.Mode3D);
- }
- }
- CBingMaps.prototype.ChangeMapStyle = function (properties) {
- var s = properties;
- if (properties.CommandValueId != null) {
- s = properties.CommandValueId;
- }
- if (s == "Road") {
- this.map.SetMapStyle(VEMapStyle.Road);
- }
- else if (s == "Shaded") {
- this.map.SetMapStyle(VEMapStyle.Shaded);
- }
- else if (s == "Aerial") {
- this.map.SetMapStyle(VEMapStyle.Aerial);
- }
- else if (s == "Hybrid") {
- this.map.SetMapStyle(VEMapStyle.Hybrid);
- }
- else if (s == "Oblique") {
- this.map.SetMapStyle(VEMapStyle.Oblique);
- }
- else if (s == "Birdseye") {
- this.map.SetMapStyle(VEMapStyle.Birdseye);
- }
- else if (s == "BirdseyeHybrid") {
- this.map.SetMapStyle(VEMapStyle.BirdseyeHybrid);
- }
- else {
- alert("ChangeMapStyle");
- }
- }
- }
3) Loaded the Bing Map based upon it’s Longitude and Latitude on user control.ascx file.
- <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3"></script>
- <script src="http://nmadan/_layouts/CBingMaps.js" type="text/javascript"></script>
- <script src="http://nmadan/_layouts/CGoogleMaps.js" type="text/javascript"></script>
- <script type="text/javascript">
- function addLoadEvent(func) {
- var oldonload = window.onload;
- if (typeof window.onload != 'function')
- { window.onload = func; }
- else {
- window.onload = function ()
- { oldonload(); func(); }
- }
- }
- //addLoadEvent(GetMap);
- var bingMaps = null;
- var cGoogleMap =null;
- function loadBingMap()
- {
- bingMaps = new CBingMaps('myMap');
- var longitutue = <%= Longitute %>;
- var latitute = <%= Latitute %>;
- var fixed = '<%= Fixed.ToString() %>';
- var location = '<%= Location.ToString() %>';
- var mapStyle = '<%=MapStyle.ToString() %>';
- var dashBorad = '<%= DashBoard.ToString() %>';
- var zoom = <%= Zoom %>;
- var mode = '<%= Mode.ToString() %>';
- bingMaps.GetMap(longitutue, latitute, fixed, location, zoom, mode, mapStyle);
- }
- SP.SOD.executeOrDelayUntilScriptLoaded(loadBingMap, "CBingMaps.js");
- addLoadEvent(loadBingMap);
- </script>
- <div id='myMap' style="position: relative; width: 600px; height: 400px;"></div>
4) Created the properties to configure the following feature :-
Ø We can easily get the desired location by providing the Longitude and Latitude.
Ø We can show multiple locations in the map by providing the Cid number. Process to generate the Cid number will be provided in detail further.
Ø We can do Zoom Out to reach deep inside the map or vice-versa.
Ø We can configure the map style from web part properties i.e. Map Properties to Road, Birdseye, Araiel etc.
Ø We can configure the mode of the map i.e. 2D or 3D.
Ø We can configure the visibility of Dashboard (A control which is used to change the map settings though UI.) to true/false.
Ø We can configure the map should be fixed and cannot be modified by the end user.
Either we can configure them as a web part properties or Ribbon. Following is sample to configure as a web part properties :-
All the features has been implemented by web part properties. A new group has been created i.e. Map Properties to configure the map.
1. Longitude & Latitude :- There are two text boxes in which we need to provide the longitude and latitude of the location. For e.g.Banglore Longitude is 13.004558 and latitude is 77.651367. following are the steps to get the two axis :-
1. Go to Windows Live Local.
2. Sign in to your account, or create one if you don’t already have one.
3. Create a collection of shapes on your scratch pad.
4. Save the collection, providing a title and description. Make sure that you select the option to make the collection public. Once you have your collection saved, select the Share option and then the Copy to link to clipboard option. The clipboard should then contain a link similar to http://www.bing.com/mapindia/default.aspx?v=2&FORM=LMLTCC&cp=12.811801~80.595703&style=r&lvl=4&tilt=-90&dir=0&alt=-1000&phx=0&phy=0&phscl=1&cid=E60BB9C18B08E70A!281&encType=1. This link Please copy the cp from the query string i.e. 12.811801~80.595703. Value before ~ is Longitude and later is Latitude.
- Map Provider :- It’s not implemented but will be coming soon in next version
- Location Cid: – Providing Cid is better if you would like to show multiple locations. You have to follow the same steps as you have followed in first point. This time you need to copy the cid from query string i.e. E60BB9C18B08E70A!281 . When you are working with cid, please provide the longitude and latitude to 0 else cid will not work.
Cid is collection of location and it’s implanted as a separate layer in this web part. Here are code details :-
map = new VEMap(‘myMap’); |
4. Map Styles: – Bing map provide 7 (Road, shaded, Aerial, Hybrid, Oblique, Birdseye, and BirdeyeHybrid) map style through VEMapStyle API. You can’t get all these styles in 3D maps.
- Map Mode: – You can see the Bing maps in two i.e. 2D and 3D. To access the 3D maps you need to install a executable from www.bing.com/maps/Help/VE3DInstall .
- Zoom :- You can select the zoom between 1 to Nineteen.
- Fixed Map: – if you don’t want to move inside the map and don’t want end use to zoomIn or Zoom out, then you fixed the map by selecting the “Fixed the map” checkbox or vice-versa.
DashBoard :- Following blue color control called dashboard in the Bing Maps. If you don’t want to show the dashboard just unselect the “DashBoard” checkbox or vice-versa.
- #region Longitute
- private double longitute = 0;
- private const double c_longitute = 0;
- [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
- System.Web.UI.WebControls.WebParts.WebDisplayName("Longitute"),
- System.Web.UI.WebControls.WebParts.WebDescription("Enter the Longitude"),
- System.Web.UI.WebControls.WebParts.Personalizable(
- System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
- System.ComponentModel.Category("Map Properties"),
- System.ComponentModel.DefaultValue(c_longitute)]
- public double Longitute
- {
- get
- {
- return longitute;
- }
- set
- {
- longitute = value;
- }
- }
- #endregion
- #region Latitute
- private double latitute = 0;
- private const double c_latitute = 0;
- [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
- System.Web.UI.WebControls.WebParts.WebDisplayName("Latitute"),
- System.Web.UI.WebControls.WebParts.WebDescription("Enter the Latitude."),
- System.Web.UI.WebControls.WebParts.Personalizable(
- System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
- System.ComponentModel.Category("Map Properties"),
- System.ComponentModel.DefaultValue(c_latitute)]
- public double Latitute
- {
- get
- {
- return latitute;
- }
- set
- {
- latitute = value;
- }
- }
- #endregion
- #region MapProvider
- public enum MyMapProvider
- {
- Bing = 0,
- Google = 1,
- Both = 2
- }
- protected MyMapProvider mapProvider;
- [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
- System.Web.UI.WebControls.WebParts.WebDisplayName("Map Provider"),
- System.Web.UI.WebControls.WebParts.WebDescription("Select the Map Provide."),
- System.Web.UI.WebControls.WebParts.Personalizable(
- System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
- System.ComponentModel.Category("Map Properties"),
- System.ComponentModel.DefaultValue(MyMapProvider.Bing)]
- public MyMapProvider MapProvider
- {
- get
- {
- return mapProvider;
- }
- set
- {
- mapProvider = value;
- }
- }
- #endregion
- #region Location
- private string location;
- [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
- System.Web.UI.WebControls.WebParts.WebDisplayName("Location Cid."),
- System.Web.UI.WebControls.WebParts.WebDescription("Enter the location cid from the Bing Maps."),
- System.Web.UI.WebControls.WebParts.Personalizable(
- System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
- System.ComponentModel.Category("Map Properties"),
- System.ComponentModel.DefaultValue("E60BB9C18B08E70A!281"),
- XmlElement(typeof(string))]
- public string Location
- {
- get
- {
- return location;
- }
- set
- {
- location = value;
- }
- }
- #endregion
- #region Map Styles
- public enum MapStyles {Road = 0, Shaded, Aerial, Hybrid, Oblique, Birdseye, BirdseyeHybrid};
- protected MapStyles mapstyle;
- [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
- System.Web.UI.WebControls.WebParts.WebDisplayName("Map Style"),
- System.Web.UI.WebControls.WebParts.WebDescription("Select any type of map style like Road, Shaded, Hybrid etc"),
- System.Web.UI.WebControls.WebParts.Personalizable(
- System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
- System.ComponentModel.Category("Map Properties"),
- System.ComponentModel.DefaultValue(MapStyles.Road)]
- public MapStyles MapStyle
- {
- get
- {
- return mapstyle;
- }
- set
- {
- mapstyle = value;
- }
- }
- #endregion
- #region Map Mode
- public enum MapMode
- {
- Mode2D = 0,
- Mode3D
- };
- protected MapMode mapMode;
- [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
- System.Web.UI.WebControls.WebParts.WebDisplayName("Map Mode"),
- System.Web.UI.WebControls.WebParts.WebDescription("Select any type of maps mode like 2D or 3D"),
- System.Web.UI.WebControls.WebParts.Personalizable(
- System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
- System.ComponentModel.Category("Map Properties"),
- System.ComponentModel.DefaultValue(MapMode.Mode2D)]
- public MapMode Mode
- {
- get
- {
- return mapMode;
- }
- set
- {
- mapMode = value;
- }
- }
- #endregion
- #region Zoom Level
- public enum ZoomLevel
- {
- One=0,
- Two=1,
- Three=2,
- Four=3,
- Five=4,
- Six=5,
- Seven=6,
- Eight=7,
- Nine=8,
- Ten=9,
- Eleven = 10,
- Tweleve=11,
- Thirteen = 12,
- Fourteen = 13,
- Fifteen= 14,
- Sixteen = 15,
- Seventeen = 16,
- Eighteen =17,
- Nineteen= 18
- };
- protected ZoomLevel zoomLevel;
- [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
- System.Web.UI.WebControls.WebParts.WebDisplayName("Zoom"),
- System.Web.UI.WebControls.WebParts.WebDescription("Select the zoom of map between 1 to 19."),
- System.Web.UI.WebControls.WebParts.Personalizable(
- System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
- System.ComponentModel.Category("Map Properties"),
- System.ComponentModel.DefaultValue(ZoomLevel.Four)]
- public ZoomLevel Zoom
- {
- get
- {
- return zoomLevel;
- }
- set
- {
- zoomLevel = value;
- }
- }
- #endregion
- #region Fixed
- private bool m_fixed = false;
- private const bool c_fixed = false;
- [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
- System.Web.UI.WebControls.WebParts.WebDisplayName("Fixed the Map"),
- System.Web.UI.WebControls.WebParts.WebDescription("A Boolean value that specifies whether the map view is displayed as a fixed map that the user cannot change. Optional. Default is false."),
- System.Web.UI.WebControls.WebParts.Personalizable(
- System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
- System.ComponentModel.Category("Map Properties"),
- System.ComponentModel.DefaultValue(false)]
- public bool Fixed
- {
- get
- {
- return m_fixed;
- }
- set
- {
- m_fixed = value;
- }
- }
- #endregion
- #region DashBoard
- private bool dashBoard = false;
- private const bool c_DashBoard = false;
- [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
- System.Web.UI.WebControls.WebParts.WebDisplayName("DashBoard"),
- System.Web.UI.WebControls.WebParts.WebDescription("Would you like to see the DashBoard?"),
- System.Web.UI.WebControls.WebParts.Personalizable(
- System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
- System.ComponentModel.Category("Map Properties"),
- System.ComponentModel.DefaultValue("")]
- public bool DashBoard
- {
- get
- {
- return dashBoard;
- }
- set
- {
- dashBoard = value;
- }
- }
- #endregion
if you would like to show inside the Ribbon then you need to create a page component and add a contextual Ribbon control
- Type.registerNamespace('ContextualTabWebPart');
- var _webPartPageComponentId;
- ContextualTabWebPart.CustomPageComponent = function ContextualTabWebPart_CustomPageComponent(webPartPcId) {
- this._webPartPageComponentId = webPartPcId;
- ContextualTabWebPart.CustomPageComponent.initializeBase(this);
- }
- ContextualTabWebPart.CustomPageComponent.prototype = {
- init: function ContextualTabWebPart_CustomPageComponent$init() { },
- receiveFocus: function () {
- return true;
- },
- yieldFocus: function () {
- return true;
- },
- getFocusedCommands: function ContextualTabWebPart_CustomPageComponent$getFocusedCommands() {
- return [];
- },
- getGlobalCommands: function ContextualTabWebPart_CustomPageComponent$getGlobalCommands() {
- return ['GoogleTab.EnableMapType', 'CustomContextualTab.CIDLocation', 'CustomContextualTab.lblLongitude', 'CustomContextualTab.FixedMapCommand', 'CustomContextualTab.LoadMapCommand', 'GoogleTab.GoogleGroup', 'GoogleTab.EnableCustomTab', 'GoogleTab.LoadGoogleMapCommand', 'CustomContextualTab.EnableZoom', 'CustomContextualTab.Latitude', 'CustomContextualTab.Longitude', 'CustomContextualTab.GetDynamicZoomXml', 'CustomContextualTab.GetDynamicModeXml', 'CustomContextualTab.DoDynamicModeXml', 'CustomContextualTab.EnableMapMode', 'CustomContextualTab.GetDynamicMenuXml', 'CustomContextualTab.EnableMapStyle', 'CustomContextualTab.DashBoard', 'CustomContextualTab.EnableCustomTab', 'CustomContextualTab.EnableCustomGroup', 'CustomContextualTab.Longitude', 'CustomContextualTab.Latitude'];
- },
- isFocusable: function ContextualTabWebPart_CustomPageComponent$isFocusable() {
- return true;
- },
- canHandleCommand: function ContextualTabWebPart_CustomPageComponent$canHandleCommand(commandId) {
- //Contextual Tab commands
- if ((commandId === 'GoogleTab.EnableMapType') || (commandId === 'CustomContextualTab.CIDLocation') || (commandId === 'CustomContextualTab.lblLongitude') || (commandId === 'CustomContextualTab.FixedMapCommand') || (commandId === 'CustomContextualTab.LoadMapCommand') || (commandId === 'GoogleTab.GoogleGroup') || (commandId === 'GoogleTab.EnableCustomTab') || (commandId === 'GoogleTab.LoadGoogleMapCommand') || (commandId === 'CustomContextualTab.EnableZoom') || (commandId === 'CustomContextualTab.Latitude') || (commandId === 'CustomContextualTab.Longitude') || (commandId === 'CustomContextualTab.GetDynamicZoomXml') || (commandId === 'CustomContextualTab.GetDynamicModeXml') || (commandId === 'CustomContextualTab.DoDynamicModeXml') || (commandId === 'CustomContextualTab.EnableMapMode') || (commandId === 'CustomContextualTab.GetDynamicMenuXml') || (commandId === 'CustomContextualTab.EnableMapStyle') || (commandId === 'CustomContextualTab.DashBoard') || (commandId === 'CustomContextualTab.EnableCustomTab') || (commandId === 'CustomContextualTab.EnableCustomGroup') || (commandId === 'CustomContextualTab.Longitude') || (commandId === 'CustomContextualTab.Latitude')) {
- return true;
- }
- },
- handleCommand: function ContextualTabWebPart_CustomPageComponent$handleCommand(commandId, properties, sequence) {
- if (commandId == 'CustomContextualTab.LoadMapCommand') {
- var notificationId = SP.UI.Notify.addNotification('Loading the Bing Map.');
- var googleMap = document.getElementById('GoogleMap');
- googleMap.setAttribute("style", "display:none;");
- var bingMap = document.getElementById('myMap');
- bingMap.setAttribute("style", "position: relative; width: 600px; height: 400px;");
- var longitutue = document.getElementById('Ribbon.CustomTabExample.CustomGroupExample.Longitude').value;
- var latitute = document.getElementById('Ribbon.CustomTabExample.CustomGroupExample.Latitude').value;
- var fixed = bingMaps.staticMap;
- var location = document.getElementById('Ribbon.CustomTabExample.CustomGroupExample.CIDLocation').value;
- var mapStyle = 'Aerial';
- var zoom = 4;
- var mode = 'Mode2D';
- bingMaps.GetMap(longitutue, latitute, fixed, location, zoom, mode, mapStyle);
- }
- if (commandId == 'GoogleTab.LoadGoogleMapCommand') {
- var notificationId = SP.UI.Notify.addNotification('Loading the Google Map.');
- var googleMap = document.getElementById('GoogleMap');
- googleMap.setAttribute("style", "position: relative; width: 600px; height: 400px;");
- var bingMap = document.getElementById('myMap');
- bingMap.setAttribute("style", "display:none;");
- cGoogleMap = new CGoogleMaps();
- cGoogleMap.GetMap('40.702147', '-74.015794', 'Brooklyn + Bridge, New + York, NY', '14', '512×512', "roadmap");
- }
- if (commandId == 'CustomContextualTab.CIDLocation') {
- }
- if (commandId == 'CustomContextualTab.Longitude') {
- }
- if (commandId == 'CustomContextualTab.Latitude') {
- }
- if (commandId == 'CustomContextualTab.DashBoard') {
- bingMaps.DashBoard(properties);
- }
- if (commandId == 'CustomContextualTab.EnableMapStyle') {
- bingMaps.ChangeMapStyle(properties);
- }
- if (commandId == 'CustomContextualTab.GetDynamicMenuXml') {
- ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, GetDynamicMenuXml), 'SP.js');
- properties.PopulationXML = GetDynamicMenuXml();
- }
- if (commandId == 'CustomContextualTab.EnableMapMode') {
- bingMaps.setMapMode(properties.SourceControlId.toString());
- }
- if (commandId == 'CustomContextualTab.DoDynamicModeXml') {
- //bingMaps.setMapMode(properties);
- loadCurrentModeList();
- }
- if (commandId == 'CustomContextualTab.GetDynamicModeXml') {
- ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, GetDynamicModeXml), 'SP.js');
- properties.PopulationXML = GetDynamicModeXml();
- }
- if (commandId == 'CustomContextualTab.EnableZoom') {
- bingMaps.setMapMode(properties.SourceControlId.toString());
- }
- if (commandId == 'CustomContextualTab.GetDynamicZoomXml') {
- ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, GetDynamicZoomXml), 'SP.js');
- properties.PopulationXML = GetDynamicZoomXml();
- }
- if (commandId == 'CustomContextualTab.FixedMapCommand') {
- alert(properties.CommandValueId);
- if (properties.On == true) {
- bingMaps.staticMap = true;
- }
- else {
- bingMaps.staticMap = false;
- }
- }
- if (commandId == 'GoogleTab.EnableMapType') {
- alert('EnableMapType');
- }
- if (commandId == 'GoogleTab.GetDynamicGoogleMapTypeXml') {
- ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, GetDynamicZoomXml), 'SP.js');
- properties.PopulationXML = GetDynamicGoogleMapTypeXml();
- }
- },
- refreshRibbon: function () {
- SP.Ribbon.PageManager.get_instance().get_commandDispatcher().executeCommand(Commands.CommandIds.ApplicationStateChanged);
- },
- getId: function ContextualTabWebPart_CustomPageComponent$getId() {
- return this._webPartPageComponentId;
- }
- }
- //Register classes
- //ContextualTabWebPart.CustomPageComponent.registerClass('ContextualTabWebPart.CustomPageComponent', CUI.Page.PageComponent);
- // Notify waiting jobs
- if (typeof (NotifyScriptLoadedAndExecuteWaitingJobs) != "undefined")
- NotifyScriptLoadedAndExecuteWaitingJobs("MapContextualTabPageComponent.js");
- function GetDynamicMenuXml() {
- var dynamicMenuXml =
- '<Menu Id="Ribbon.CustomTabExample.CustomGroupExample.MapStyle.Menu">'
- + '<MenuSection Id="Ribbon.CustomTabExample.CustomGroupExample.MapStyle.Section" DisplayMode="Menu16">'
- + '<Controls Id="Ribbon.CustomTabExample.CustomGroupExample.MapStyle.Section.Controls">';
- var mapStyle = new Array("Shaded", "Aerial", "Hybrid", "Oblique", "Birdseye", "BirdseyeHybrid");
- for (i = 0; i < mapStyle.length; i++) {
- var buttonXML = String.format(
- '<Button Id="' + mapStyle[i].toString() + '" '
- + 'Command="CustomContextualTab.EnableMapStyle" '
- + 'CommandValueId ="' + mapStyle[i].toString() + '" '
- + 'MenuItemId="{0}" '
- + 'LabelText="'+ mapStyle[i].toString() +'" '
- + 'ToolTipTitle="'+ mapStyle[i].toString() +'" '
- + 'ToolTipDescription="' + mapStyle[i].toString() + '" />',
- i);
- dynamicMenuXml += buttonXML;
- }
- dynamicMenuXml += '</Controls>' + '</MenuSection>' + '</Menu>';
- return dynamicMenuXml;
- }
- var mode = null;
- var querySucceded = false;
- function loadCurrentModeList() {
- var mode = new Array("MODE2D", "MODE3D");
- querySucceded = true;
- }
- function GetDynamicModeXml() {
- var dynamicMenuXml =
- '<Menu Id="Ribbon.CustomTabExample.CustomGroupExample.Mode.Menu">'
- + '<MenuSection Id="Ribbon.CustomTabExample.CustomGroupExample.Mode.Section" DisplayMode="Menu16">'
- + '<Controls Id="Ribbon.CustomTabExample.CustomGroupExample.Mode.Section.Controls">';
- var mode = new Array("MODE2D", "MODE3D");
- for (i = 0; i < mode.length; i++) {
- var buttonXML = String.format(
- '<Button Id="' + mode[i].toString() + '" '
- + 'Command="CustomContextualTab.EnableMapMode" '
- + 'CommandValueId ="' + mode[i].toString() + '" '
- + 'MenuItemId="{0}" '
- + 'LabelText="' + mode[i].toString() + '" '
- + 'ToolTipTitle="' + mode[i].toString() + '" '
- + 'ToolTipDescription="' + mode[i].toString() + '" />',
- i);
- dynamicMenuXml += buttonXML;
- }
- dynamicMenuXml += '</Controls>' + '</MenuSection>' + '</Menu>';
- return dynamicMenuXml;
- }
- function GetDynamicZoomXml() {
- var dynamicMenuXml =
- '<Menu Id="Ribbon.CustomTabExample.CustomGroupExample.Mode.Menu">'
- + '<MenuSection Id="Ribbon.CustomTabExample.CustomGroupExample.Mode.Section" DisplayMode="Menu16">'
- + '<Controls Id="Ribbon.CustomTabExample.CustomGroupExample.Mode.Section.Controls">';
- var zoom = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19");
- for (i = 0; i < zoom.length; i++) {
- var buttonXML = String.format(
- '<Button Id="' + zoom[i].toString() + '" '
- + 'Command="CustomContextualTab.EnableMapMode" '
- + 'CommandValueId ="' + zoom[i].toString() + '" '
- + 'MenuItemId="{0}" '
- + 'LabelText="' + zoom[i].toString() + '" '
- + 'ToolTipTitle="' + zoom[i].toString() + '" '
- + 'ToolTipDescription="' + zoom[i].toString() + '" />',
- i);
- dynamicMenuXml += buttonXML;
- }
- dynamicMenuXml += '</Controls>' + '</MenuSection>' + '</Menu>';
- return dynamicMenuXml;
- }
- //Google Map functions
- //==============================================
- function GetDynamicGoogleMapTypeXml() {
- var dynamicMenuXml =
- '<Menu Id="Ribbon.GoogleTab.GoogleGroup.EnableMapType.Menu">'
- + '<MenuSection Id="Ribbon.GoogleTab.GoogleGroup.EnableMapType.Section" DisplayMode="Menu16">'
- + '<Controls Id="Ribbon.GoogleTab.GoogleGroup.EnableMapType.Section.Controls">';
- var mapStyle = new Array("roadmap", "Aerial");
- for (i = 0; i < mapStyle.length; i++) {
- var buttonXML = String.format(
- '<Button Id="' + mapStyle[i].toString() + '" '
- + 'Command="GoogleTab.EnableMapType" '
- + 'CommandValueId ="' + mapStyle[i].toString() + '" '
- + 'MenuItemId="{0}" '
- + 'LabelText="' + mapStyle[i].toString() + '" '
- + 'ToolTipTitle="' + mapStyle[i].toString() + '" '
- + 'ToolTipDescription="' + mapStyle[i].toString() + '" />',
- i);
- dynamicMenuXml += buttonXML;
- }
- dynamicMenuXml += '</Controls>' + '</MenuSection>' + '</Menu>';
- return dynamicMenuXml;
- }
- private string contextualTab = @"
- <ContextualGroup Color=""Magenta""
- Command=""CustomContextualTab.EnableContextualGroup""
- Id=""Ribbon.CustomContextualTabGroup""
- Title=""Map Settings""
- Sequence=""502""
- ContextualGroupId=""CustomContextualTabGroup"">
- <Tab
- Id=""Ribbon.CustomTabExample""
- Title=""Bing""
- Description=""www.bing.com/maps""
- Command=""CustomContextualTab.EnableCustomTab""
- Sequence=""513"">
- <Scaling
- Id=""Ribbon.CustomTabExample.Scaling"">
- <MaxSize
- Id=""Ribbon.CustomTabExample.MaxSize""
- GroupId=""Ribbon.CustomTabExample.CustomGroupExample""
- Size=""OneLargeTwoMedium""/>
- <Scale
- Id=""Ribbon.CustomTabExample.Scaling.CustomTabScaling""
- GroupId=""Ribbon.CustomTabExample.CustomGroupExample""
- Size=""OneLargeTwoMedium"" />
- </Scaling>
- <Groups Id=""Ribbon.CustomTabExample.Groups"">
- <Group
- Id=""Ribbon.CustomTabExample.CustomGroupExample""
- Description=""This is a custom group!""
- Title=""Configuation""
- Command=""CustomContextualTab.EnableCustomGroup""
- Sequence=""52""
- Template=""Ribbon.Templates.CustomTemplateExample"">
- <Controls Id=""Ribbon.CustomTabExample.CustomGroupExample.Controls"">
- <Label
- Id=""Ribbon.CustomTabExample.CustomGroupExample.lblLongitude""
- Command=""CustomContextualTab.lblLongitude""
- LabelText=""Longitude""
- TemplateAlias=""cust1""
- Sequence=""11""
- />
- <TextBox
- Id=""Ribbon.CustomTabExample.CustomGroupExample.Longitude""
- Command=""CustomContextualTab.Longitude""
- ToolTipTitle=""Longitude""
- ToolTipDescription=""Please enter the Longitude.""
- MaxLength=""512""
- TemplateAlias=""cust2""
- Image16by16=""/_layouts/images/DATERANGELAST30DAYS_16X16.PNG""
- Image32by32=""/_layouts/images/DATERANGELAST30DAYS_32X32.PNG""
- Sequence=""13""
- />
- <Label
- Id=""Ribbon.CustomTabExample.CustomGroupExample.lblLatitude""
- Command=""CustomContextualTab.lblLatitude""
- LabelText=""Latitude""
- TemplateAlias=""cust3""
- Sequence=""16""
- />
- <TextBox
- Id=""Ribbon.CustomTabExample.CustomGroupExample.Latitude""
- Command=""CustomContextualTab.Latitude""
- ToolTipTitle=""Latitude""
- ToolTipDescription=""Please enter the Latitude.""
- MaxLength=""512""
- TemplateAlias=""cust4""
- Sequence=""17""
- />
- <Label
- Id=""Ribbon.CustomTabExample.CustomGroupExample.lblLatitude""
- Command=""CustomContextualTab.lblCIDLocation""
- LabelText=""Cid Location""
- TemplateAlias=""cust5""
- Sequence=""19""
- />
- <TextBox
- Id=""Ribbon.CustomTabExample.CustomGroupExample.CIDLocation""
- Command=""CustomContextualTab.CIDLocation""
- ToolTipTitle=""Cid Location""
- ToolTipDescription=""Please enter the Cid.""
- MaxLength=""512""
- TemplateAlias=""cust6""
- Image16by16=""/_layouts/images/DATERANGELAST30DAYS_16X16.PNG""
- Image32by32=""/_layouts/images/DATERANGELAST30DAYS_32X32.PNG""
- Sequence=""21""
- />
- <SplitButton
- Id=""Ribbon.CustomTabExample.CustomGroupExample.MapStyle""
- Sequence=""23""
- Command=""CustomContextualTab.EnableMapStyle""
- Image16by16=""/_layouts/$Resources:core,Language;/images/formatmap16x16.png""
- Image16by16Top=""-32""
- Image16by16Left=""-192""
- LabelText=""Map Style""
- ToolTipTitle=""Map Style""
- ToolTipDescription=""Select the Map Style""
- TemplateAlias=""cust7""
- PopulateDynamically=""true""
- PopulateQueryCommand=""CustomContextualTab.GetDynamicMenuXml""
- >
- </SplitButton>
- <DropDown
- Id=""Ribbon.CustomTabExample.CustomGroupExample.Mode""
- Sequence=""26""
- Command=""CustomContextualTab.EnableMapMode""
- PopulateDynamically=""true""
- PopulateOnlyOnce=""true""
- PopulateQueryCommand=""CustomContextualTab.GetDynamicModeXml""
- QueryCommand=""CustomContextualTab.DoDynamicModeXml""
- Width=""75px""
- TemplateAlias=""cust8"" />
- <SplitButton
- Id=""Ribbon.CustomTabExample.CustomGroupExample.Zoom""
- Sequence=""27""
- Command=""CustomContextualTab.EnableZoom""
- Image16by16=""/_layouts/$Resources:core,Language;/images/formatmap16x16.png"" Image16by16Top=""-32"" Image16by16Left=""-192""
- LabelText=""Zoom""
- ToolTipTitle=""Zoom""
- ToolTipDescription=""Zoom""
- TemplateAlias=""cust9""
- PopulateDynamically=""true""
- PopulateQueryCommand=""CustomContextualTab.GetDynamicZoomXml""
- >
- </SplitButton>
- <ToggleButton
- Id=""Ribbon.CustomTabExample.CustomGroupExample.DashBoard""
- Command=""CustomContextualTab.DashBoard""
- Sequence=""28""
- Description=""Would you like to enable the DashBoard?""
- Image16by16=""/_layouts/images/DATERANGELAST30DAYS_16X16.PNG""
- Image32by32=""/_layouts/images/DATERANGELAST30DAYS_32X32.PNG""
- LabelText=""DashBoard""
- TemplateAlias=""cust10""/>
- <ToggleButton
- Id=""Ribbon.CustomTabExample.CustomGroupExample.FixedMap""
- Command=""CustomContextualTab.FixedMapCommand""
- Sequence=""29""
- Description=""Would you like to fix the Map?""
- Image16by16=""/_layouts/GPSImages/Bing.png""
- Image32by32=""/_layouts/GPSImages/Bing.png""
- LabelText=""Fix the Map""
- TemplateAlias=""cust11""/>
- <Button
- Id=""Ribbon.CustomTabExample.CustomGroupExample.LoadMap""
- Command=""CustomContextualTab.LoadMapCommand""
- Sequence=""31""
- Description=""Load the Bing Map.""
- Image16by16=""/_layouts/GPSImages/Bing.png""
- Image32by32=""/_layouts/GPSImages/Bing.png""
- LabelText=""Load Map""
- TemplateAlias=""cust12""/>
- </Controls>
- </Group>
- </Groups>
- </Tab>
- <Tab
- Id=""Ribbon.GoogleTab""
- Title=""Google""
- Description=""www.bing.com/maps""
- Command=""GoogleTab.EnableCustomTab""
- Sequence=""505"">
- <Scaling
- Id=""Ribbon.GoogleTab.Scaling"">
- <MaxSize
- Id=""Ribbon.GoogleTab.MaxSize""
- GroupId=""Ribbon.GoogleTab.GoogleGroup""
- Size=""OneLargeTwoMedium""/>
- <Scale
- Id=""Ribbon.GoogleTab.Scaling.CustomTabScaling""
- GroupId=""Ribbon.GoogleTab.GoogleGroup""
- Size=""OneLargeTwoMedium"" />
- </Scaling>
- <Groups Id=""Ribbon.GoogleTab.Groups"">
- <Group
- Id=""Ribbon.GoogleTab.GoogleGroup""
- Description=""Google group settings""
- Title=""Configuation""
- Command=""GoogleTab.GoogleGroup""
- Sequence=""52""
- Template=""Ribbon.Templates.CustomTemplateExample"">
- <Controls Id=""Ribbon.GoogleTab.GoogleGroup.Controls"">
- <Label
- Id=""Ribbon.GoogleTab.GoogleGroup.lblLongitude""
- Command=""GoogleTab.lblLongitude""
- LabelText=""Longitude""
- TemplateAlias=""cust1""
- Sequence=""11""
- />
- <TextBox
- Id=""Ribbon.GoogleTab.GoogleGroup.Longitude""
- Command=""GoogleTab.Longitude""
- ToolTipTitle=""Longitude""
- ToolTipDescription=""Please enter the Longitude.""
- MaxLength=""512""
- TemplateAlias=""cust2""
- Image16by16=""/_layouts/images/DATERANGELAST30DAYS_16X16.PNG""
- Image32by32=""/_layouts/images/DATERANGELAST30DAYS_32X32.PNG""
- Sequence=""13""
- />
- <Label
- Id=""Ribbon.GoogleTab.GoogleGroup.lblLatitude""
- Command=""GoogleTab.lblLatitude""
- LabelText=""Latitude""
- TemplateAlias=""cust3""
- Sequence=""16""
- />
- <TextBox
- Id=""Ribbon.GoogleTab.GoogleGroup.Latitude""
- Command=""GoogleTab.Latitude""
- ToolTipTitle=""Latitude""
- ToolTipDescription=""Please enter the Latitude.""
- MaxLength=""512""
- TemplateAlias=""cust4""
- Sequence=""17""
- />
- <Label
- Id=""Ribbon.GoogleTab.GoogleGroup.Center""
- Command=""GoogleTab.Center""
- LabelText=""Cid Location""
- TemplateAlias=""cust5""
- Sequence=""19""
- />
- <TextBox
- Id=""Ribbon.GoogleTab.GoogleGroup.Center""
- Command=""GoogleTab.Center""
- ToolTipTitle=""Center""
- ToolTipDescription=""Please enter the Center.""
- MaxLength=""512""
- TemplateAlias=""cust6""
- Image16by16=""/_layouts/images/DATERANGELAST30DAYS_16X16.PNG""
- Image32by32=""/_layouts/images/DATERANGELAST30DAYS_32X32.PNG""
- Sequence=""21""
- />
- <SplitButton
- Id=""Ribbon.GoogleTab.GoogleGroup.EnableMapType""
- Sequence=""23""
- Command=""GoogleTab.EnableMapType""
- Image16by16=""/_layouts/$Resources:core,Language;/images/formatmap16x16.png""
- Image16by16Top=""-32""
- Image16by16Left=""-192""
- LabelText=""Map Type""
- ToolTipTitle=""Map Type""
- ToolTipDescription=""Select the Map Type""
- TemplateAlias=""cust7""
- PopulateDynamically=""true""
- PopulateQueryCommand=""GoogleTab.GetDynamicGoogleMapTypeXml""
- >
- </SplitButton>
- <DropDown
- Id=""Ribbon.GoogleTab.GoogleGroup.Mode""
- Sequence=""26""
- Command=""GoogleTab.EnableMapMode""
- PopulateDynamically=""true""
- PopulateOnlyOnce=""true""
- PopulateQueryCommand=""GoogleTab.GetDynamicModeXml""
- QueryCommand=""GoogleTab.DoDynamicModeXml""
- Width=""75px""
- TemplateAlias=""cust8"" />
- <SplitButton
- Id=""Ribbon.GoogleTab.GoogleGroup.Zoom""
- Sequence=""27""
- Command=""GoogleTab.EnableZoom""
- Image16by16=""/_layouts/$Resources:core,Language;/images/formatmap16x16.png"" Image16by16Top=""-32"" Image16by16Left=""-192""
- LabelText=""Zoom""
- ToolTipTitle=""Zoom""
- ToolTipDescription=""Zoom""
- TemplateAlias=""cust9""
- PopulateDynamically=""true""
- PopulateQueryCommand=""GoogleTab.GetDynamicZoomXml""
- >
- </SplitButton>
- <ToggleButton
- Id=""Ribbon.GoogleTab.GoogleGroup.DashBoard""
- Command=""GoogleTab.DashBoard""
- Sequence=""28""
- Description=""Would you like to enable the DashBoard?""
- Image16by16=""/_layouts/images/DATERANGELAST30DAYS_16X16.PNG""
- Image32by32=""/_layouts/images/DATERANGELAST30DAYS_32X32.PNG""
- LabelText=""DashBoard""
- TemplateAlias=""cust10""/>
- <ToggleButton
- Id=""Ribbon.GoogleTab.GoogleGroup.FixedMap""
- Command=""GoogleTab.FixedMapCommand""
- Sequence=""29""
- Description=""Would you like to fix the Map?""
- Image16by16=""/_layouts/GPSImages/Bing.png""
- Image32by32=""/_layouts/GPSImages/Bing.png""
- LabelText=""Fix the Map""
- TemplateAlias=""cust11""/>
- <Button
- Id=""Ribbon.CustomTabExample.CustomGroupExample.LoadMap""
- Command=""GoogleTab.LoadGoogleMapCommand""
- Sequence=""33""
- Description=""Load the Google Map.""
- LabelText=""Load Map""
- TemplateAlias=""cust12""/>
- </Controls>
- </Group>
- </Groups>
- </Tab>
- </ContextualGroup>";
- private string contextualTabTemplate = @"
- <GroupTemplate Id=""Ribbon.Templates.CustomTemplateExample"">
- <Layout Title=""OneLargeTwoMedium"" LayoutTitle=""OneLargeTwoMedium"">
- <Section Alignment=""Top"" Type=""TwoRow"">
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust1"" />
- </Row>
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust2"" />
- </Row>
- </Section>
- <Section Alignment=""Top"" Type=""TwoRow"">
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust3"" />
- </Row>
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust4"" />
- </Row>
- </Section>
- <Section Alignment=""Top"" Type=""TwoRow"">
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust5"" />
- </Row>
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust6"" />
- </Row>
- </Section>
- <Section Alignment=""Top"" Type=""OneRow"">
- <Row>
- <ControlRef DisplayMode=""Large"" TemplateAlias=""cust11"" />
- </Row>
- </Section>
- <Section Alignment=""Top"" Type=""OneRow"">
- <Row>
- <ControlRef DisplayMode=""Large"" TemplateAlias=""cust12"" />
- </Row>
- </Section>
- <Section Alignment=""Top"" Type=""TwoRow"">
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust7"" />
- </Row>
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust8"" />
- </Row>
- </Section>
- <Section Alignment=""Top"" Type=""TwoRow"">
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust9"" />
- </Row>
- <Row>
- <ControlRef DisplayMode=""Medium"" TemplateAlias=""cust10"" />
- </Row>
- </Section>
- </Layout>
- </GroupTemplate>";
- private string googleContextualTabTemplate = @"
- <GroupTemplate Id=""Ribbon.Templates.GoogleTemplate"">
- <Layout Title=""OneLargeTwoMedium"" LayoutTitle=""OneLargeTwoMedium"">
- <Section Alignment=""Top"" Type=""OneRow"">
- <Row>
- <ControlRef DisplayMode=""Large"" TemplateAlias=""cust12"" />
- </Row>
- </Section>
- </Layout>
- </GroupTemplate>";
- public string DelayScript
- {
- get
- {
- string webPartPageComponentId = SPRibbon.GetWebPartPageComponentId(this);
- return @"
- <script type=""text/javascript"">
- function _addCustomPageComponent()
- {
- var _customPageComponent = new ContextualTabWebPart.CustomPageComponent('" + webPartPageComponentId + @"');
- SP.Ribbon.PageManager.get_instance().addPageComponent(_customPageComponent);
- }
- function _registerCustomPageComponent()
- {
- SP.SOD.registerSod(""MapContextualTabPageComponent.js"", ""\/_layouts\/MapContextualTabPageComponent.js"");
- SP.SOD.executeFunc(""MapContextualTabPageComponent.js"", ""ContextualWebPart.CustomPageComponent"", _addCustomPageComponent);
- }
- SP.SOD.executeOrDelayUntilScriptLoaded(_registerCustomPageComponent, ""sp.ribbon.js"");
- </script>";
- }
- }
- public WebPartContextualInfo WebPartContextualInfo
- {
- get
- {
- WebPartContextualInfo info = new WebPartContextualInfo();
- WebPartRibbonContextualGroup contextualGroup = new WebPartRibbonContextualGroup();
- //WebPartRibbonContextualGroup googleContextualGroup = new WebPartRibbonContextualGroup();
- WebPartRibbonTab ribbonTab = new WebPartRibbonTab();
- WebPartRibbonTab googleRibbonTab = new WebPartRibbonTab();
- //Create the contextual group object and initialize its values.
- contextualGroup.Id = "Ribbon.CustomContextualTabGroup";
- contextualGroup.Command = "CustomContextualTab.EnableContextualGroup";
- contextualGroup.VisibilityContext = "CustomContextualTab.CustomVisibilityContext";
- //Create the tab object and initialize its values.
- ribbonTab.Id = "Ribbon.CustomTabExample";
- ribbonTab.VisibilityContext = "CustomContextualTab.CustomVisibilityContext";
- //Create the contextual group object and initialize its values.
- //contextualGroup.Id = "Ribbon.GoogleContextualTabGroup";
- //contextualGroup.Command = "GoogleContextualTab.EnableContextualGroup";
- //contextualGroup.VisibilityContext = "GoogleContextualTab.CustomVisibilityContext";
- ////Create the tab object and initialize its values.
- ribbonTab.Id = "Ribbon.GoogleTab";
- ribbonTab.VisibilityContext = "GoogleContextualTab.CustomVisibilityContext";
- //Add the contextual group and tab to the WebPartContextualInfo.
- info.ContextualGroups.Add(contextualGroup);
- //info.ContextualGroups.Add(googleContextualGroup);
- //info.Tabs.Add(googleRibbonTab);
- info.Tabs.Add(ribbonTab);
- info.PageComponentId = SPRibbon.GetWebPartPageComponentId(this);
- return info;
- }
- }
- private void AddContextualTab()
- {
- //Gets the current instance of the ribbon on the page.
- Microsoft.Web.CommandUI.Ribbon ribbon = SPRibbon.GetCurrent(this.Page);
- //Prepares an XmlDocument object used to load the ribbon extensions.
- XmlDocument ribbonExtensions = new XmlDocument();
- //Load the contextual tab XML and register the ribbon extension.
- ribbonExtensions.LoadXml(this.contextualTab);
- ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.ContextualTabs._children");
- //Load the custom templates and register the ribbon extension.
- ribbonExtensions.LoadXml(this.contextualTabTemplate);
- ribbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children");
- }
- protected override void OnPreRender(EventArgs e)
- {
- base.OnPreRender(e);
- this.AddContextualTab();
- string webPartPageComponentId = SPRibbon.GetWebPartPageComponentId(this);
- ClientScriptManager clientScript = this.Page.ClientScript;
- clientScript.RegisterClientScriptBlock(this.GetType(), "ContextualTabWebPart", this.DelayScript);
- SPRibbon currentRibbon = SPRibbon.GetCurrent(this.Page);
- currentRibbon.MakeTabAvailable("Ribbon.CustomTabExample");
- currentRibbon.MakeContextualGroupInitiallyVisible("Ribbon.CustomContextualTabGroup", string.Empty);
- }
Following are links for your reference :-
please send me the full code in rar format.
it’s urgent