Today (8/31) is last day to enter 2010 Community Coding Contest for chance to win an MSDN Ultimate Subscription!

31. August 2010

Today is the last day to enter the 2010 Community Coding Contest for a chance to win an MSDN Ultimate Subscription plus a total of approximately $20,719 worth of prizes!!

All you need to do is write some source code to do something, and enter it into the contest. Who know, you could be one of the winners!

http://communitycodingcontest.org

General ,

Use New Bing Maps Road Imagery In Silverlight Map Control (Unofficially and Unsupported)

19. August 2010

NewBingMapsRoadImageryFromSilverlight Recently the consumer facing Bing Maps site changed the map imagery that is displayed for the Road map mode. This map imagery has not been officially made available for Bing Maps for Enterprise developers to use within their applications. The imagery is only officially available to the Bing Maps consumer website. Unofficially, you can still access the imagery if you know the URL format to get it. Below is an example of using the URL format for the new imagery to display it within the Bing Maps Silverlight Control.

I have not seen anything official from Microsoft on this, so I assume that doing this is against their terms of use. You assume any and all responsibility in violating their terms of use if you use the below code. Sorry for the disclaimer, but I don’t want you to tell Microsoft I told you it was ok. Basically, do not use this in a production application, unless you get consent from Microsoft.

Now the code…

Displaying the Map (XAML):

<UserControl x:Class="Silverlight_NewBingMapsRoadImagery_2010.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Silverlight_NewBingMapsRoadImagery_2010"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
xmlns:mCore="clr-namespace:Microsoft.Maps.MapControl.Core;assembly=Microsoft.Maps.MapControl"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">

<m:Map NavigationVisibility="Collapsed">
<m:Map.Mode>
<!-- Do Not Display Default Bing Maps Imagery -->
<mCore:MercatorMode />
</m:Map.Mode>
<m:Map.Children>
<m:MapTileLayer>
<m:MapTileLayer.TileSources>
<!-- Show the new Bing Maps imagery -->
<local:NewBingMapsTileSource />
</m:MapTileLayer.TileSources>
</m:MapTileLayer>
</m:Map.Children>
</m:Map>

</Grid>
</UserControl>

NewBingMapTileSource (C#):

public class NewBingMapsTileSource : Microsoft.Maps.MapControl.TileSource
{
public NewBingMapsTileSource()
: base("{UriScheme}://ecn.t{subdomain}.tiles.virtualearth.net/tiles/r{quadkey}?g=530&mkt=EN-US&lbl=l1&stl=h&shading=hill&n=z")
{ }
}

Bing Maps, C#, Silverlight , ,

Loading Microsoft CDN Hosted OpenStreetMap Imagery in Silverlight Bing Maps Control

19. August 2010

MSHostedOpenStreetMapImageryFromSilverlight Recently a new Bing Maps App for OpenStreetMap (OSM) was released. This new feature of the Bing Maps consumer facing website is hosting the OpenStreetMap imagery using the Azure CDN, rather than relying on OpenStreetMap’s server. There has been some question as to whether developers can use the Microsoft hosted OpenStreetMap imagery within their own applications.

I have not seen anything official from Microsoft on this, so I assume that doing this is against their terms of use. You assume any and all responsibility in violating their terms of use if you use the below code. Sorry for the disclaimer, but I don’t want you to tell Microsoft I told you it was ok. Basically, do not use this in a production application, unless you get consent from Microsoft.

Now the code…

Displaying the Map (XAML):

<UserControl x:Class="Silverlight_NewBingMapsRoadImagery_2010.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Silverlight_NewBingMapsRoadImagery_2010"
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    xmlns:mCore="clr-namespace:Microsoft.Maps.MapControl.Core;assembly=Microsoft.Maps.MapControl"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">

        <m:Map NavigationVisibility="Collapsed">
            <m:Map.Mode>
                <!-- Do Not Display Default Bing Maps Imagery -->
                <mCore:MercatorMode />
            </m:Map.Mode>
            <m:Map.Children>
                <m:MapTileLayer>
                    <m:MapTileLayer.TileSources>
                        <!-- Display OpenStreetMap Imagery -->
                        <local:OpenStreetMapTileSource />
                    </m:MapTileLayer.TileSources>
                </m:MapTileLayer>
            </m:Map.Children>
        </m:Map>
        
    </Grid>
</UserControl>

OpenStreetMapTileSource (C#):

public class OpenStreetMapTileSource : Microsoft.Maps.MapControl.TileSource
{
    public OpenStreetMapTileSource()
        : base()
    {
        this.UriFormat = "{UriScheme}://{3}.osm.virtualearth.net/{2}/{0}/{1}.png"
            .Replace("{UriScheme}", OpenStreetMapTileSource.PageUriScheme); // <-- set "http" or "https" appropriately
    }

    public override System.Uri GetUri(int x, int y, int zoomLevel)
    {
        // Randomly decide which server to use
        string server;
        var rnd = new Random();
        var i = rnd.Next(0, 2);
        switch (i)
        {
            case 1:
                server = "b";
                break;
            case 2:
                server = "c";
                break;
            default:
                server = "a";
                break;
        }

        // Format Uri for the desired map tile image
        return new Uri(string.Format(this.UriFormat, x, y, zoomLevel, server));
    }

    internal static string PageUriScheme
    {
        get
        {
            if ((HtmlPage.IsEnabled && (HtmlPage.Document != null)) && (HtmlPage.Document.DocumentUri != null))
            {
                return HtmlPage.Document.DocumentUri.Scheme;
            }
            return "HTTP";
        }
    }
}

Bing Maps, C#, Silverlight , ,

Microsoft BizSpark: My new startup is enrolled, but was denied twice before this blog post

14. August 2010

Update Monday, Aug. 16, 2010: My startup, Carto LLC, is now enrolled in the BizSpark program! Also, if you are having similar issues getting enrolled in BizSpark (are legitimate company and not trying to scam the system) then feel free to contact me through this blog. I now know who to contact directly on the BizSpark team, and may be able to help you out.

Update Sunday, Aug. 15, 2010: I just got off the phone with Cliff Reeves, the General Manager responsible for BizSpark. Apparently, BizSpark has recently dealt with some problems of piracy with people enrolling in BizSpark who do not have a legitimate company. He assured me that the any confusion causing my denial of enrollement into BizSpark will be fixed, and I am going to get an invitation code to get Carto LLC enrolled on Monday. This was a really prompt response, and I really appreciate him taking time out of his weekend to get in touch. Also, he mentioned that they are going to work at either calling people or telling them why they do not meet the eligibility requirements, instead of just sending a generic message on the order of "You do not meet the requirements at this time."


Original Post:

I know the title of this post is a little on the strong side, but I am currently really perterbed about the Microsoft BizSpark program. Some of you may know that I have been involved in founding a new startup, Carto LLC. Carto is a software as a service business that specializes in developing and hosting custom GIS-based (Map-based) line of business applications that perfectly fit the needs of the client. Since we are just starting out, I thought I would get Carto enrolled in the Microsoft BizSpark program, but have been denied twice! Also, they have no contact phone number and my email was ignored!

What is BizSpark?

Basically BizSpark was started as an on-going effort by Microsoft to get more startups to use Microsoft technologies and products instead of going with open source. The way that they do it is by making the technology and software extremely cheap for startups that qualify for the BizSpark program.

According to Microsoft, BizSpark is...

"Launched in November 2008, the BizSpark program is designed to help accelerate the success of entrepreneurs and early-stage startups globally. The program provides fast and easy access to current, full-featured software development tools and platforms, and a connection to over 2,000 BizSpark Network Partners – including university incubators, hosters, government agencies, investors, consultants and financial institutions – all with a common goal of supporting entrepreneurship. BizSpark startups can also have the opportunity to achieve global visibility to an audience of potential investors, clients, and partners by profiling their company and posting offers and events in the BizSpark online networking hub, BizSpark Connect. Join a community of over 30,000 startups enrolled in BizSpark by signing up today."

Enrollment in BizSpark is free, as long as the startup meets the following requirements:

  1. Actively engaged in development of a software-based product or online service that will form a core piece of its current or intended business.
  2. Privately held.
  3. In business for less than 3 years
  4. Less than $1 million in annual revenue

Then if you meet those requirements you get free Microsoft software to use for that three year period, at the end of which you are required to pay a fee of $100 USD.

Apparently Microsoft Does Not Really Care About Startups!

About 4 weeks ago, I applied to BizSpark for my new startup, Carto LLC. After about a week I got an email saying that we were denied because "it does not appear that you meet all the eligibility requirements at this time." After being denied I looked on the BizSpark website to see if I could find a contact phone number, so I could call to find out why we were denied. They have no contact number published. However, in the denial email I recieved, they state that you can email, bizspark@microsoft.com, if you have any questions.

About 3 weeks ago, I emailed bizspark@microsoft.com to find out why we were denied entry into BizSpark. I also explained in the email that we definately meet the four posted requirements on their website. I never recieved a reply.

About 1 week ago, I tried applying for the BizSpark program a second time. After about a week, I recieved another email stating that we were denied due to not meeting the requirements.

Today, I emailed bizspark@microsoft.com again, am posting this message to my blog, and spreading it on my Twitter and LinkedIn  account.

I am really annoyed that Microsoft would offer such poor support for this program that they have been promoting so much. I am a Microsoft MVP (have been since 2008) and promote Microsoft products to people everyday. I have also been recommending the BizSpark program to others interested in starting their own companies. This send me the message that Microsoft does not really care about startups all that much, even though they say they do. Unless this gets resolved, I will tell people specifically not to bother with BizSpark, since Microsoft obviously does not care about startups all that much.

How many others have been denied entry in to BizSpark for no apparent reason? If it happened to me, I assume there are others that it has happened to.

I would really like someone from the BizSpark team to contact me. I can be reached on this blog, @crpietschmann, or on LinkedIn.

General

Bing Community Site Not SEO Optimized

4. August 2010

Since Bing is a search (ahem, I mean “decision”) engine, I would assume that the rest of the website, other than the search, would be SEO optimized (Search Engine Optimization). It hosts blogs and forums, and I would assume Microsoft would want them to be indexed by Google and Yahoo. After all, more traffic to the Bing site should be a good thing. However, it seems that the “Bing Community” sections of http://bing.com are lacking when it comes to SEO.

Below are some links to blog and forum posts with examples of how the Bing Community, a sub-section of Bing, is lacking when it comes to SEO.

Blog Post: http://www.bing.com/community/blogs/maps/archive/2010/08/02/king-of-bing-maps-applications-are-go.aspx

  • The page Title is “Bing Community,” instead of the actual title of the blog post. If you search either Google or Bing the title of the page that shows in the search results is “Bing Community,” which does not represent the page content what so ever. As a result many users would just gloss over those results, assuming they are irrelevant. What the page Title should be is the full title of the blog post.
  • The page source contains 2 <H1> (header) tags. If a page has an <H1> tag, search engines will use that to help detect what the main title of the page content is. By having 2 <H1> tags, the page will therefore “confuse” the search engines causing them to not be able to figure out what the main title of the page content is. The 2 <H1>’s in this blog post contain the text “Community” and “King of Bing Maps: Who Shall Be King?”

Forum Post: http://www.bing.com/community/forums/t/651827.aspx

  • The same two issues for blog posts are also there for forums posts.

Other Issues with the Bing Community website that may or may not be related to SEO:

  • The html markup of the page includes a <link> tag to include a “/community/favicon.ico” image. However, the image linked to does not exists and requesting it returns a 404 (Page Not Found) error page.
  • One usability issue with viewing blogs on the Bing Community website is that you cannot click the “Blogs” tab at the top of the page to view the list of blogs hosted there. Instead you must click “Community,” then click the “Blogs” tab on that page to view the list of blogs hosted on the Bing Community website. This is very Un-Intuitive.

I understand that most people, developers and website administrators may not be aware of these simple SEO mistakes that are commonly missed. I would expect Microsoft and Bing to get these things right, but apparently even they have troubles with SEO, which is very odd since they are in charge of one of the most used search engines. Anyway, I hope that by pointing these coupe items out will help others make their websites more SEO friendly, and get them higher search engine rankings and increased website traffic.

Also, I am definitely not claiming to be an SEO expert. If you have anything to add, on either the SEO of my blog or the Bing Community website, please post a comment. I am really interested to hear any comments you may have.

SEO , , ,

Silverlight Bing Maps: Draw Circle Around a Latitude/Longitude Location

28. June 2010

SLBingMaps_DrawCircles Over 2 years ago I posted an example of how to draw circles on the Bing Maps JavaScript control. I thought it was about time to update that post to demonstrate how to do this using the Bing Maps Silverlight control. This is basically a C# port of the original JavaScript code.

Sometimes this can be really useful, but it isn’t built into the Sivleright Bing Maps Control. So you need to implement it yourself in order to do it. However, instead of writing from scratch, feel free to copy the code from this post.

Download Full Source: SLBingMaps_DrawCircle.zip

 

 

Here’s example usage:

// Draw circle at the location where the user clicked
private void Map_MouseClick(object sender, Microsoft.Maps.MapControl.MapMouseEventArgs e)
{
// Get the location the mouse clicked
var mousePoint = e.ViewportPoint;
var clickedLocation = MainMap.ViewportPointToLocation(mousePoint);

// Calculate the points to make up a circle with radius of 200 miles
var locations = GeoCodeCalc.CreateCircle(clickedLocation, 200, DistanceMeasure.Miles);

// Add Red Polyline to the Map
var poly = new MapPolyline();
poly.Locations = locations;
poly.Stroke = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
poly.StrokeThickness = 2;
MainMap.Children.Add(poly);
}

 

And, here’s the code that calculates the location points to make up the circle:

/*
* Written by Chris Pietschmann (http://pietschsoft.com)
* This code is derived from the code posted in the following location:
* http://pietschsoft.com/post/2010/03/02/Bing-Maps-JS-Calculate-Area-of-Circle-and-Draw-Circle-on-Map.aspx
*/
using System;
using System.Collections.Generic;
using Microsoft.Maps.MapControl;

namespace SLBingMaps_DrawCircle
{
public enum DistanceMeasure
{
Miles,
Kilometers
}

public class GeoCodeCalc
{
public const double EarthRadiusInMiles = 3956.0;
public const double EarthRadiusInKilometers = 6367.0;

public static double ToRadian(double degrees)
{
return degrees * (Math.PI / 180);
}

public static double ToDegrees(double radians)
{
return radians * (180 / Math.PI);
}

public static LocationCollection CreateCircle(Location center, double radius, DistanceMeasure units)
{
var earthRadius = (units == DistanceMeasure.Miles ? GeoCodeCalc.EarthRadiusInMiles : GeoCodeCalc.EarthRadiusInKilometers);
var lat = ToRadian(center.Latitude); //radians
var lng = ToRadian(center.Longitude); //radians
var d = radius / earthRadius; // d = angular distance covered on earth's surface
var locations = new LocationCollection();

for (var x = 0; x <= 360; x++)
{
var brng = ToRadian(x);
var latRadians = Math.Asin(Math.Sin(lat) * Math.Cos(d) + Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng));
var lngRadians = lng + Math.Atan2(Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat), Math.Cos(d) - Math.Sin(lat) * Math.Sin(latRadians));

locations.Add(new Location(ToDegrees(latRadians), ToDegrees(lngRadians)));
}

return locations;
}
}
}

Bing Maps, Silverlight , ,

Display Google Maps Imagery using Bing Maps Silverlight Control

14. June 2010

I’ve gotten a couple emails asking how to show Google Maps imagery using the Bing Maps Silverlight Control. I previously post how to display OpenStreetMaps and Yahoo maps imagery using the control, but is it possible to show Google Maps imagery too?? Yes, absolutely; well technically, but the Google Maps Terms of Use does prohibit it. Actually, the Google Maps Terms of Use prohibits the direct access of the map tile images, and does not specifically prohibit using them with the Bing Maps Silverlight Control.

SLBingMapsControl_GoogleMapsImagery

You may only continue reading if you are willing to break the Google Maps Terms of Use, and see how similar the two mapping platforms really are.

Remember the below code most likely violates the Google Maps Terms of Use, and probably shouldn’t be used in a production system; unless of course you really don’t mind breaking the terms of use.

The below code follows suite after the code I posted a while back on displaying OpenStreetMap and Yahoo Maps imagery within the Bing Maps Silverlight Control.

First, here’s some XAML usage samples using the Google Maps TIle Source classes listed further down. The first one is showing the Google Maps Road/Terrain imagery, the second shows the Google Maps Aerial/Satellite imagery:

<!-- Display Google Maps Road/Terrain Imagery -->
<m:Map CopyrightVisibility="Collapsed" LogoVisibility="Collapsed">
<m:Map.Mode>
<!-- Do Not Display Bing Maps Imagery -->
<mCore:MercatorMode></mCore:MercatorMode>
</m:Map.Mode>
<m:Map.Children>
<m:MapTileLayer>
<m:MapTileLayer.TileSources>
<local:GoogleMapsRoadTileSource></local:GoogleMapsRoadTileSource>
</m:MapTileLayer.TileSources>
</m:MapTileLayer>
</m:Map.Children>
</m:Map>

<!-- Display Google Maps Aerial/Satellite Imagery with Labels -->
<m:Map CopyrightVisibility="Collapsed" LogoVisibility="Collapsed">
<m:Map.Mode>
<!-- Do Not Display Bing Maps Imagery -->
<mCore:MercatorMode></mCore:MercatorMode>
</m:Map.Mode>
<m:Map.Children>
<m:MapTileLayer>
<m:MapTileLayer.TileSources>
<local:GoogleMapsAerialTileSource></local:GoogleMapsAerialTileSource>
<local:GoogleMapsLabelsTileSource></local:GoogleMapsLabelsTileSource>
</m:MapTileLayer.TileSources>
</m:MapTileLayer>
</m:Map.Children>
</m:Map>

 

If you notice, the second example showing the usage of the Google Maps Aerial/Satellite imagery is displaying 2 tile sources. This is because Google Maps has separate tile sources for both the Aerial/Satellite imagery and the Labels. This example shows the Labels tile source over the top of the Aerial/Satellite tile source to give the desired effect of “Aerial with Labels.”

Now, here’s the main attraction of this article; the actual Google Maps TileSource objects referred to above:

public class GoogleMapsRoadTileSource : GoogleMapsTileSourceBase
{
public GoogleMapsRoadTileSource()
: base("http://mt{0}.google.com/vt/lyrs=m@128&hl=en&x={1}&y={2}&z={3}&s=")
{ }
}

public class GoogleMapsAerialTileSource : GoogleMapsTileSourceBase
{
public GoogleMapsAerialTileSource()
: base("http://khm{0}.google.com/kh/v=62&x={1}&y={2}&z={3}&s=")
{ }
}

public class GoogleMapsLabelsTileSource : GoogleMapsTileSourceBase
{
public GoogleMapsLabelsTileSource()
: base("http://mt{0}.google.com/vt/lyrs=h@128&hl=en&x={1}&y={2}&z={3}&s=")
{ }
}

public abstract class GoogleMapsTileSourceBase : Microsoft.Maps.MapControl.TileSource
{
public GoogleMapsTileSourceBase(string uriFormat)
: base(uriFormat)
{ }

public override System.Uri GetUri(int x, int y, int zoomLevel)
{
return new Uri(string.Format(this.UriFormat, new Random().Next() % 4, x, y, zoomLevel));
}
}

 

Disclaimer: Use the above posted code at your own risk. The usage of it may be in violation of the Google Maps Terms of Use.

Bing Maps, Silverlight , ,

Resizing and Auto-Scaling Pushpin in Bing Maps Silverlight

4. June 2010

Plotting pushpins on the Bing Maps Silverlight control is really simple when using the Pushpin control that comes with the control. But, what if you want to change the size of the Pushpin? It doesn't work to just change the Pushpin.Height and Pushpin.Width properties. This is actually because those properties pertain to the controls Content property. So, how exactly do you go about changing the size of the Pushpin if the Height and Width properties don't work?

Use ScaleTransform to Resize Pushpins

The answer is simple. All you need to do is use a ScaleTransform. Below is a couple examples, one making the pushpin smaller and the other bigger.

<m:Pushpin Location="0,-15">
    <m:Pushpin.RenderTransform>
        <ScaleTransform ScaleX=".5" ScaleY=".5" CenterX="17" CenterY="35"></ScaleTransform>
    </m:Pushpin.RenderTransform>
</m:Pushpin>
<m:Pushpin Location="0,15">
    <m:Pushpin.RenderTransform>
        <ScaleTransform ScaleX="2" ScaleY="2" CenterX="17" CenterY="35"></ScaleTransform>
    </m:Pushpin.RenderTransform>
</m:Pushpin>

You may have noticed that not only does the above example set the ScaleX and ScaleY properties of the ScaleTransform, but the CenterX and CenterY are also set. This is because if we don't set the CenterX and CenterY appropriately the Pushpin will get "moved" from its correct location when the Transform is performed.

How did I decide to set CenterX to 17 and CenterY to 35? Well, the Pushpins "default" size sets the Width equal to 34 and Height to 35, and the PositionOrigin to BottomCenter. Since the PositionOrigin is set to BottomCenter, in order to get the pushpin to stay in its correct position on the map we need to set the CenterX to half the Width or 17, and CenterY to the Height or 35.

The image to the right shows an example of this in action.

Auto Scale Pushpin with Map Zoom Level

A neat feature that becomes available with the Bing Maps Silverlight control once you start using ScaleTransforms to modify the size of Pushpins is the ability to change the size of the Pushpins when the Map Zoom Level is changed. All it takes is a little help from a custom IValueConverter and a little Data Binding.

The image to the right shows this in action. Both sides of the image were not resized at all, the difference in size of the Pushpins is due to the usage of the following code.

First, we'll add some Pushpins to a Map and set the Pushpins RenderTransform property binding to bind it to the Map's ZoomLevel property and set it to use a custom converter.

<m:Map Height="200" x:Name="myMap">
    <m:Map.Children>
        <m:Pushpin Location="0,-15"
            RenderTransform="{Binding ZoomLevel, ElementName=myMap, Converter={StaticResource PushpinScaleTransform}}"></m:Pushpin>
        <m:Pushpin Location="0,15"
            RenderTransform="{Binding ZoomLevel, ElementName=myMap, Converter={StaticResource PushpinScaleTransform}}"></m:Pushpin>
    </m:Map.Children>
</m:Map>

Next, make sure you declare the PushpinScaleTransform static resource in the UserControl, Page or App. Also, don't forget to include the namespace, in the below example I named it "local".

<UserControl.Resources>
    <local:PushpinScaleTransform x:Key="PushpinScaleTransform"></local:PushpinScaleTransform>

</UserControl.Resources>

Finally, add the PushpinScaleTransform custom IValueConverter object to the project. This custom IValueCoverter will recieve the ZoomLevel and "convert" it to a ScaleTransform with ScaleX, ScaleY and CenterX, CenterY properties set appropriately to Auto Scale the Pushpin with the Map ZoomLevel. Below is an example of this that I found works quite well.

using System;
using System.Windows.Data;
using System.Windows.Media;

namespace SLBingMapsScalePushpins
{
    public class PushpinScaleTransform : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double currentZoomLevel = (double)value;

            // Calculate the scale to use. This is just a simple algorithm that
            // I found works nicely.
            var scaleVal = (0.05 * (currentZoomLevel + 1)) + 0.3;

            var transform = new ScaleTransform();
            transform.ScaleX = scaleVal;
            transform.ScaleY = scaleVal;

            // Set the transform center X and Y so the Pushpin stays at the correct location.
            // The Default Pushpin's height is 35 and width is 34
            // Since the Default Pushpin's PositionOrigin is set to BottomCenter, we need to
            // set the CenterX to half the width (17), and CenterY to the height (35).
            transform.CenterX = 17;
            transform.CenterY = 35;

            return transform;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}

Download Code

Here's a link to download a small Silverlight project that implements the above code examples.

SLBingMapsScalePushpins.zip (446.52 kb)

Bing Maps, Silverlight ,

Draggable Pushpins using Bing Maps Silverlight Control

30. May 2010

Using a map to visualize data within an application is great, but you must first get the location of the data to be displayed. If you have the address you can geocode it using the Bing Maps Web Services, but "What if you can't geocode it?" Or, "What if the geocoding can't find the address?" Well, if your user knows where the location is, then you can have them point it out by clicking on the map. Creating Pushpins in response to a users click is nice, but wouldn't it be even nicer if they could "Click and Drag" the Pushpin around to define/edit/change the location of the data entity?

I have even seen this discussed a bit in regards to the Bing Maps Silverlight Control, and it isn't something that is built into the map control directly. However it isn't too difficult to implement, if you know what to do. So I decided to create and post a simple "DraggablePushpin" object deriving from the "Microsoft.Maps.MapControl.Pushpin" object that implements Dragging in a nice, self contained fashion. There's no need to wire up any events, you simple add a "DraggablePushpin" to you Map, and the user can drag it around.

Here's the code for the "DraggablePushpin":

public class DraggablePushpin : Microsoft.Maps.MapControl.Pushpin
{
    private bool isDragging = false;
    EventHandler<MapMouseDragEventArgs> ParentMapMousePanHandler;
    MouseButtonEventHandler ParentMapMouseLeftButtonUpHandler;
    MouseEventHandler ParentMapMouseMoveHandler;

    protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
    {
        // Check if the Map Event Handlers have been created/attached to the Map
        // If not, then attach them. This is done in the "Pushpin.OnMouseLeftButtonDown"
        // event because we don't know when the Pushpin is added to a Map or MapLayer, but
        // we do konw that when this event is fired the Pushpin will already have been added.
        var parentLayer = this.Parent as MapLayer;
        if (parentLayer != null)
        {
            var parentMap = parentLayer.ParentMap;
            if (parentMap != null)
            {
                if (this.ParentMapMousePanHandler == null)
                {
                    this.ParentMapMousePanHandler = new EventHandler<MapMouseDragEventArgs>(ParentMap_MousePan);
                    parentMap.MousePan += this.ParentMapMousePanHandler;
                }
                if (this.ParentMapMouseLeftButtonUpHandler == null)
                {
                    this.ParentMapMouseLeftButtonUpHandler = new MouseButtonEventHandler(ParentMap_MouseLeftButtonUp);
                    parentMap.MouseLeftButtonUp += this.ParentMapMouseLeftButtonUpHandler;
                }
                if (this.ParentMapMouseMoveHandler == null)
                {
                    this.ParentMapMouseMoveHandler = new MouseEventHandler(ParentMap_MouseMove);
                    parentMap.MouseMove += this.ParentMapMouseMoveHandler;
                }
            }
        }

        // Enable Dragging
        this.isDragging = true;

        base.OnMouseLeftButtonDown(e);
    }

    #region "Mouse Event Handler Methods"

    void ParentMap_MousePan(object sender, MapMouseDragEventArgs e)
    {
        // If the Pushpin is being dragged, specify that the Map's MousePan
        // event is handled. This is to suppress the Panning of the Map that
        // is done when the mouse drags the map.
        if (this.isDragging)
        {
            e.Handled = true;
        }
    }

    void ParentMap_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        // Left Mouse Button released, stop dragging the Pushpin
        this.isDragging = false;
    }

    void ParentMap_MouseMove(object sender, MouseEventArgs e)
    {
        var map = sender as Microsoft.Maps.MapControl.Map;
        // Check if the user is currently dragging the Pushpin
        if (this.isDragging)
        {
            // If so, the Move the Pushpin to where the Mouse is.
            var mouseMapPosition = e.GetPosition(map);
            var mouseGeocode = map.ViewportPointToLocation(mouseMapPosition);
            this.Location = mouseGeocode;
        }
    }

    #endregion
}

Bing Maps, Silverlight

Boycott BP, Save the Planet!

18. May 2010

I've decided to boycott BP until the Oil Spill in the Guld of Mexico is fixed/cleaned up! If you remember the oil spill in Alaska back in the '80's then you remember all the pictures/videos of all the animals killed by being covered in oil. The same thing is happening today in the Gulf of Mexico with the oil drilling blowout that has been spewing oil into the ocean for a month now.

Oil does not occur naturaling in the ocean or on land. As a result animals can not breath or fly when covered in oil. This is killing OUR environment!

Bottom line, if we can't keep things like this from happening, or hold accountable those responsible, then there is no way we should continue drilling for oil. Period.

Sure, you may say "accidents can happen", but this shows that we obviously need to make sure the oil companies take appropriate precautions to make sure this type of thing does not happen again.

In addition to having BP pay for the entire clean up efforts, I encourage everyone to boycott all products made by BP until things are cleaned up. We need to make sure all oil companies fully understand that we will not stand for this. And, if BP goes bankrupt because no one buys their products, then I know we will have gotten our message across.

Here's a couple links worth checking out:

60 Minutes: Deepwater Horizon's Blowout, Part 1

Wikipedia: Deep Water Horizon oil spill

UPDATE: I understand it seems a bit impossible to boycott all products that may contain oil/petroleum from one of BP's oil rigs, but even if you just stop purchasing Gas from BP's stations you will still help to put a dent in their profits. The point is to get the message across that we all do not want this type of thing to happen and every precaution to prevent it should be taken. The easiest way to help make a huge difference is to make one small step at a time, and eventually they add up to change the world. Besides, other than complaining to politicians, a boycott is really the only other thing we can do to express our concern.

health