måndag 6 januari 2014

Extending Bing Maps Pushpin with Attributes

Recently I needed to store attributes with Pushpins in Bing Maps. Either I'm blind or it is just not there. Bing Maps is offering the following properties with the Pushpin object:

If I just try to add a property when initializing the Pushpin, Bing Maps will not take notice of that property due to the setOptions function on the Pushpin object. I don't really want to override the setOptions function - since I don't know the domino effect. So there are still two ways to solve the problem.

  1. Add a property on the Pushpin object - it is Javascript. Such as.
    var pin = new Microsoft.Maps.Pushpin(OpenSMILWebPart.map.getCenter(), { height: 50, width: 50 });
    and just add a property:
    pin.customfield = 'customData';
  2. Add get and set method on the Pushpin object such as:
    Microsoft.Maps.Pushpin.prototype.setAttributes = function () { this._attributes = arguments[0] }; Microsoft.Maps.Pushpin.prototype.getAttributes = function () { return this._attributes; };
    and set properties such as:
    pin.setAttributes({ customObject: 'some data' });
    use get method to receive data:
    pin.getAttributes();
Alternative two is more complex, but more useful if we need to control the data.

Microsoft - feel free to add a Tag property to each geometry type giving the opportunity storing values in.

lördag 28 december 2013

Using Bing services to validate addresses

Bing Maps services provides a feature for geocoding. A way to increase user input address quality, for example in SharePoint, is to present address quality feedback for the user. I've done that with a custom field.
This is the feedback I want to give to the user. I start to structure the application such as:
Why do I use HTTP handlers in SharePoint? In my opiniun they are easier to install than WCF services in SharePoint. But they are low level services. In order to get them to work I have to point out the assembly and the webhandler such as:
<%@ Assembly Name="OpenSMIL.Server, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=deb5cb40dd7862f6" %>
<%@ WebHandler Language="C#" CodeBehind="ValidateAddress.ashx.cs" Class="OpenSMIL.Server.ValidateAddress" %>

After that the server side development is pretty straight forward. As you can see in the image to the left the server code is divided into two seperate parts. The HTTP-handler, wich just needs some codebehind and let the other code worry about the Bing geocoding logic. And that is just a few lines of code.
And the code to ask Bing..

That's all for the services. In order to build a custom field here is a tutorial . And this article can come handy.

I'm almost done, all that is left is a XML-file describing for SharePoint about this field.

What is left now is just some JavaScript for rendering and communicating with the server. I have intentially left out jQuery and other JS libraries since it is basically just an Ajax requests.
That is it. All code is available here.

torsdag 17 oktober 2013

osx eclipse "there are no resources that can be added or removed from the server"

Been struggling with eclipse telling me "there are no resources that can be added or removed from the server". I installed Eclipse Java EE Developer Tools and that got rid of that problem.

onsdag 26 januari 2011

PG Routing Shooting Star issue

screenshot43In a recent project I’m using PG Routing for routing with Navteq data. To route start to stop PGRouting comes with three different algorithms.

  • Djikstra – classic shortest path.
  • Shortest Path A* – using heuristics to find the shortest path.
  • Shortest Path Shooting Star – using heuristics with traffic rules to find the shortest path.

The Djikstra and Shortest Path A* works fine and are pretty fast after working with the network and bounding box. When trying the algorithm Shortest Path Shooting Star there are some problems. One major problem is when starting reverse direction of the first link.

Navteq’s segments starts from south. So when calculating a route on that starts off south there is a phenomena, see image. It should a straight line from the top point to the bottom point, very badly visualized.

onsdag 19 maj 2010

Tech Days 2010, blog posts and start with Bing Maps

Speaking Swedish or understand Swedish? If you are interested in BIng Maps, SharePoint, DeepEarth, Microsoft and GIS you can watch my presentation at Tech Days 2010 in Örebro, Sweden the 24th of Mars this year.

Lately Johannes Kebeck, a Bing Maps TSP blogged about my favorite project SMIL. That blog post is one post in a blog series about integrating maps into SharePoint. His latest post is about integration themetic maps from SQL Server 2008 R2.

If you are intested in starting developing with Bing Maps you should really go to Bing Maps portal. Johannes Kebeck, Chris Pendleton and BingMapsDev are people you can follow on twitter to get the latest news. Another good start is to go the developer forum. When should also have a look at Deep Earth Toolkit for Bing Maps.

onsdag 12 maj 2010

Creating a Silverlight Web Part for SharePoint 2007

In this blog post I describe an approach to add a Silverlight Web Part in SharePoint 2007. Adding Silverlight Web Parts to SharePoint can really make magic to SharePoint, i.e. maps (my personal favorite topic), Web Parts with drag and drop support from the file system etc. I always create a Silverlight project and separate and load it to a web part. I describe my favorite approach:

  1. Create a Web Part project, rename the Web Part and it’s files to something appropriate. I use Visual Studio 2008 extensions for Windows SharePoint Services 3.0 (version 1.2) in this example.
  2. Create a folder name it Templates.
  3. Create a folder name it ControlTemplates
  4. Create a folder name it YourWebPart-name.
  5. Choice File –> Add –> New Project. Choose web and give it a name.
  6. Get rid of the Default.aspx file in the web project.
  7. Add a User Control to the web project, get rid of the code behind and add your the reference to the web part assembly to the inherits of the file, example: <%@ Control Language="C#" AutoEventWireup="true"  Inherits="MyNameSpace.ClassName, AssemblyName, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=3283a693cab37f84" %> See understanding SharePoint for more info. The nice part now is that you can start designing the user control as with any .aspx-file, well almost. Add your .xap file and Silverlight.js-file to this project. 
  8. Add javascript and code for loading your silverlight control, i.e
    <div id="silverlightMultiFileUploadControlHost" >
    <object id="MultiFileUploader" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="450" height="280">
    <param name="source" value="/_controltemplates/mPost.MultiFileUpload/mpost.SilverlightMultiFileUpload.xap" />
    <param name="onerror" value="onSilverlightError" />
    <param name="initParams" value="MaxFileSizeKB=,MaxUploads=2,FileFilter=,ChunkSize=4194304,CustomParam=[site=<%=Site%>;docLib=<%=DocumentLibrary%>;httpService=<%=HttpService%>],DefaultColor=White" />
    <param name="background" value="white" />
    <param name="onload" value="pluginLoaded" />
    <param name="minRuntimeVersion" value="4.0.50401.0" />
    <param name="autoUpgrade" value="true" />
    <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.5040


    1.0" style="text-decoration:none">
    <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
    </a>
    </object>
    <iframe style='visibility: hidden; height: 0; width: 0; border: 0px'></iframe>
    </div>




  9. Add properties to your .cs file. I always add a SPWeb property to access the web from the user control and make sure that the .designer.cs file has the same class name.


  10. Go back to your web part project and add the following methods:

         protected override void OnLoad(EventArgs e)

            { SilverlightWebPart


                ScriptManager scriptManager = ScriptManager.GetCurrent(Page);


                if (scriptManager == null) 
                {  scriptManager = new ScriptManager();


                    Controls.Add(scriptManager); 
                } 
            }
     
            protected override void OnPreRender(EventArgs e)

            {


                base.OnPreRender(e);


                ClientScriptManager cs = Page.ClientScript; 
                if (!cs.IsClientScriptIncludeRegistered("sl_javascript"))


                    cs.RegisterClientScriptInclude(this.GetType(), "sl_ja vascript", "~/_controltemplates/mPost.MultiFileUpload/Silverlight.js");


                if (!cs.IsClientScriptIncludeRegistered("spsl_javascript"))


                    cs.RegisterClientScriptInclude(this.GetType(), "spsl_javascript", "~/_controltemplates/mPost.MultiFileUpload/SpSilverlight.js");


            }


  11. Of course you need to change the script source to your path.


  12. Add reference System.Web.Extensions


  13. Choóse add existing item in your web part project. Add your user control as a link (we want to compile it with the web part assembly), also add a Silverlight.js and your .xap file the same way to this folder.


  14. You’re done, all you have to do now is to load the user control to the web part in the CreateChildControls method like:
    mPost.MultiFileUploadWebPart.MultiFileUploadUC uc = (mPost.MultiFileUploadWebPart.MultiFileUploadUC)
    Page.Page.LoadControl("~/_controlTemplates/mPost.MultiFileUpload/MultiFileUploadUC.ascx");
    Controls.Add(uc);




In 14 steps I can write shiny cool Silverlight web parts for SharePoint 2007. There are some steps, especially with the 5 part assembly that is a little tricky. Of course my favorite Silverlight web part is the one in SMIL and Silverlight Multi File Upload that has inspired this blog post. See http://slfileupload.codeplex.com/SourceControl/changeset/view/47874#1002455 for a working code example.




tisdag 4 maj 2010

SharePoint MultifileUpload – HTTP Handlers and “the security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again”

In a current project I added a custom HTTP handler for a silverlight multifile upload web part for SharePoint. First, it’s obvious I need a client and a server pattern for make this happen. The client is just a Silverlight Web Part, nothing special nothing fancy. The server is a HTTP-handler, i.e an .ashx-file.

Integrate ASHX file into SharePoint

In order to integrate http-handler my favorite approach is to use WSPBuilder. Add a new WSPBuilder project, close it and open your .csproj file in notepad, or your favorite text editor, insert the following line right after <PropertyGroup>:

<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

Compile the project and find your public key token, either by writing
sn –T dll-file in the .NET console window or by just adding to dll to the GAC.

Now, all you need to do is create a directory structure in the hive 12 structure. I.e 12/Layouts, it’s common practice to add a directory after Layouts, in my case MultiFileUploadStructureMultifileUpload. The next step is just  to add Generic Handler to your solution. When you’ve done that you need to reference to your assembly in the GAC on the following pattern: AssemblyName, Version, Culture, PublicKeyToken. Example:

<%@ Assembly Name="MultiFileUpload, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a8aa1afe43cd31d3" %>

My complete markup is as follows:

<%@ Assembly Name="MultiFileUpload, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a8aa1afe43cd31d3" %>
<%@ WebHandler Language="C#" CodeBehind="MultiFileUpload.ashx.cs" Class="MultiFileUpload.MultiFileUpload" %>

By now you’re all set, you should be able to open IIS-manager and browse to the .ashx-file and open it in a web browser. Make sure the .ashx-file is at least in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS folder.

In my case I uploaded files to a document library with a Silverlight web part, in order to make that to work I needed to add:

site.AllowUnsafeUpdate = true.

This is strange because I make the call from a web browser inside SharePoint, perhaps it has something to do that it is actually a Silverlight web part?

The web part and the server code is given back to the project. http://slfileupload.codeplex.com/.

More info:MSDN, myrocode.com, Mike Poulson.

Technorati Tags: ,