This project is read-only.

Some advice on adding open streetmap to my project

Feb 23, 2013 at 1:17 AM
Edited Feb 23, 2013 at 1:18 AM
I want to add open streetmaps to my project..... i saw an extension long time ago who could do this but i want to have the most recent known best working method....

So my question is... where is an example or a best read article on this as my googling efforts didnt bring what i wanted :o(

thx for reading and keep up the good work

for people interested in my own progress :o)

see my work
Feb 23, 2013 at 1:49 AM
you can do with DotSpatial.Controls.BruTileLayer
check this link TEXT
Feb 23, 2013 at 1:51 AM
thx... so i will be able to load the map under my own project?
Feb 23, 2013 at 1:55 AM
Edited Feb 23, 2013 at 1:59 AM
indeed..
Your project looks great congratulations
Feb 23, 2013 at 2:03 AM
Edited Feb 23, 2013 at 2:04 AM
searches the internet "DotSpatial.Controls.BruTileLayer.zip" if don't find it I can send you to your email...
check too DotSpatial.Plugins.WebMap
Feb 23, 2013 at 2:07 AM
Thx :o)

I found the zip... it contains C-sharp stuff in it..... and u know have any idea how to get it to work? I mean i may be able to make that certain project i showed you but i feel still a noob :o(

So where to put or install it and such.... thx for helping anyway
Feb 23, 2013 at 2:15 AM
You have to be patient because I know almost no English
Feb 23, 2013 at 2:16 AM
compiles the project and will generate a dll, this dll the add to your project... :)
Feb 23, 2013 at 2:16 AM
camiza wrote:
You have to be patient because I know almost no English
What is your native language Camiza?
Feb 23, 2013 at 2:18 AM
compiles the project and will generate a dll, this dll the add to your project... :)

I speak Spanish
Feb 23, 2013 at 2:22 AM
gracias so far, i will see if I can get this a bit working but i doubt it, it feels hard...
Feb 23, 2013 at 2:25 AM
Edited Feb 23, 2013 at 2:26 AM
watch this video on the post "OpenStreetMap" TEXT see at minute 2:50 that's my project
Feb 23, 2013 at 3:01 AM
Edited Feb 23, 2013 at 3:03 AM
very nice project camiza.... ur more advanced from what i see...... sadly couldnt see how u added the streetmap maps

ur from colombia!
Feb 23, 2013 at 3:05 AM
give me your email I send the compiled dll and I'll explain more or less
Feb 23, 2013 at 3:20 AM
Feb 23, 2013 at 3:35 AM
Ok I send you the dlls and tell me if you got it..
Feb 23, 2013 at 4:00 AM
I have and i will try it right away thx...
Feb 23, 2013 at 4:54 AM
  1. Add BruTile.dll in your project
  2. Add DotSpatial.Controls.BruTileLayer.dll in your project
  3. Write this for reference map in your project
Imports DotSpatial.Controls.BruTileLayer

Dim mapSatellite As BruTileLayer
mapSatellite = BruTileLayer.CreateBingAerialLayer()
map1.Projection = mapSatellite.Projection
map1.Layers.Add(mapSatellite)
Feb 23, 2013 at 7:16 PM
watch this video on the post "OpenStreetMap" TEXT that's your project :D

I send you and your project.... :)
Feb 23, 2013 at 7:34 PM
Hahaha i will watch it :o)
Feb 23, 2013 at 7:40 PM
pfff that looked very simple to make it work..... seems i missed something here
Feb 23, 2013 at 7:47 PM
that was what you wanted to do?
Feb 23, 2013 at 9:19 PM
Yup exact what I wanted, thx..... but now I must work on its projection... since in holland we use a different special projection Amersfoort or RD_NEW

If u have ideas on this.... I have to rescale it to my own projection-system

but thx so far ur great :o) your country have great men and great women ;o)
Feb 24, 2013 at 8:01 AM
Joska, There is currently no open source solution to project rasters or tiles. So your basemap needs to be in the right projection. So you can either choose a SphericalMercator tile layer (like bing) and project your other data to SphericalMercator or find a basemap that is already in RD_NEW.
Feb 24, 2013 at 2:31 PM
:o(

Hi Paul, you seem to be from dutch origin... :o)

You checked my blog? It feels we do related work in Holland, i work for Movares, perhaps known to you. I myself am a acoustic engineer.

Do you have any suggestions on usable background maps related to RD_NEW?

Greetings Joska

Sidenote
I have more RD_NEW issues..... which i may solve with my compagnies programmers...
Although I am making a non-commercial product when it comes to real benefits, its market is just too small, my field of work needs such tools to help our dutch citizens in a better way :o) And above all I love to make handy tools :o)
Feb 25, 2013 at 10:42 AM
Edited Feb 25, 2013 at 12:10 PM
Hi Joska, I work at Geodan Amsterdam. A geo specialist.

For free RD datasets you could look at PDOK. It publishes RD datasets as TMS (and WMTS).
https://www.pdok.nl/nl
Their ArcGIS plugin is actually based on ArcBruTile. So it uses the same BruTile core assembly as the DotSpatial BruTileLayer:
https://www.pdok.nl/nl/producten/pdok-software/pdok-extensie-voor-arcgis
Geodan also publishes RD datasets:
http://www.geodan.nl/diensten/webmapping-services/
We are about to publish an OSM TMS in RD_NEW.

Here is an example of a PDOK layer as BruTile tile source:
_tileSource = new TmsTileSource("http://geodata.nationaalgeoregister.nl/tiles/service/tms/1.0.0/brtachtergrondkaart", new WkstNederlandSchema());

Paul
Feb 25, 2013 at 10:31 PM
thx for the explanation although i doubt i can solve it myself :o)
Feb 26, 2013 at 4:16 PM
Somewhere in the code there is a line
= new OsmTileSouce();
You should replace this with:
= new TmsTileSource("http://geodata.nationaalgeoregister.nl/tiles/service/tms/1.0.0/brtachtergrondkaart", new WkstNederlandSchema());
I don't know in which part of the code this is but perhaps you could try search and replace.

Paul
Feb 26, 2013 at 4:23 PM
Edited Feb 26, 2013 at 4:26 PM
Thx again Paul

My current code is this:
    Private Sub BruTileOpenStreetMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BruTileOpenStreetMap.Click
        mapSatellite = Joska.BruTileLayer.CreateOsmLayer()
        Me.myVenster.Projection = mapSatellite.Projection
        Me.myVenster.Layers.Add(mapSatellite)
    End Sub
so i see no way to follow your advice :o(
Feb 26, 2013 at 4:57 PM
Use the debugger and step through the CreateOsmLayer function and you'll find what you are looking for
Feb 26, 2013 at 5:26 PM
to use the debugger remembers add your joska.dll as DMC project viewer 4.2 dspot_v1.4
Feb 26, 2013 at 5:51 PM
to use the debugger remembers add your joska.dll as DMC project viewer 4.2 dspot_v1.4
Feb 26, 2013 at 7:04 PM
to use the debugger remembers add your joska.dll as DMC project viewer 4.2 dspot_v1.4
Feb 26, 2013 at 7:30 PM
mmm camiza your reply appeared 3 times... concerning programming i meay be slow but this slow? ;o)

thx for your advices this thread is becomming a tutorial in itself soon :o)
Feb 26, 2013 at 7:39 PM
Sorry... not happened....
Feb 26, 2013 at 11:16 PM
you actually the built the project of "JoskaBrutileLayer.dll" is how I'm currently working because DotSpatial.Plugins.WebMap.dll could do better, but I could not do incorporate this DotSpatial.Plugins.WebMap.dll to my project.

If you learn to do me like that show me.. :D
Feb 28, 2013 at 5:57 PM
FObermaier and Paul

When i follow your advice I get eventually an error "No response receiving" ....

Do i have to register at PDOK and het some sort of a key? to make this posisble?

tileSource = new TmsTileSource("http://geodata.nationaalgeoregister.nl/tiles/service/tms/1.0.0/brtachtergrondkaart", new WkstNederlandSchema());
Oct 9, 2013 at 4:52 PM
you do not need a key for PDOK. I just tested this example and it still works for me.
Oct 9, 2013 at 8:28 PM
Hey Paul

You mean it would work on a dutch projection.... right now my project appears for the coast of africa in the atlantic ocean :o)
Oct 10, 2013 at 7:36 AM
I have as ArcGis 10.1 user managed to load teh PDOK extension and yes it can be very handy.... and found this in the

http://geodata.nationaalgeoregister.nl/wmsc?LAYERS=brtachtergrondkaart
Oct 10, 2013 at 8:03 AM
I cant find teh spot i guess...

in form1.vb i find this....
 REM ***************************************************************************************************************************************
    REM * OPEN STREET MAP AND SATTELITE
    REM ***************************************************************************************************************************************
    Private mapSatellite As Joska.BruTileLayer
    Private Sub BruTileNone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BruTileNone.Click
        Me.myVenster.Layers.Remove(mapSatellite)
    End Sub
    Private Sub BruTileAerial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BruTileAerial.Click
        mapSatellite = Joska.BruTileLayer.CreateBingAerialLayer()
        Me.myVenster.Projection = mapSatellite.Projection
        Me.myVenster.Layers.Add(mapSatellite)
    End Sub

    Private Sub BruTileOpenStreetMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BruTileOpenStreetMap.Click
        mapSatellite = Joska.BruTileLayer.CreateOsmLayer()
        Me.myVenster.Projection = mapSatellite.Projection
        Me.myVenster.Layers.Add(mapSatellite)
    End Sub
and in BrutileLayer.cs this

``` namespace Joska
{
[Serializable]
public class BruTileLayer : DotSpatial.Controls.IMapLayer
{
    /// <summary>
    /// Creates a Bing Maps Roads layer using the "Staging" url
    /// </summary>
    public static BruTileLayer CreateBingRoadsLayer()
    {
        return CreateBingRoadsLayer(String.Empty);
    }

    /// <summary>
    /// Creates a Bing Maps Roads layer using the standard url. You need to have a valid token
    /// </summary>
    /// <param name="token">The token for Bing Maps access</param>
    public static BruTileLayer CreateBingRoadsLayer(string token)
    {
        string url = string.IsNullOrWhiteSpace(token)
                         ? BingRequest.UrlBingStaging
                         : BingRequest.UrlBing;

        return new BruTileLayer(
            new BingTileSource(new BingRequest(url, "", BingMapType.Roads)),
            new MemoryCache<byte[]>(100, 200));
    }

    /// <summary>
    /// Creates a Bing Maps hybird layer using the "Staging" url
    /// </summary>
    public static BruTileLayer CreateBingHybridLayer()
    {
        return CreateBingHybridLayer(String.Empty);
    }
    /// <summary>
    /// Creates a Bing Maps hybrid layer using the standard url. You need to have a valid token
    /// </summary>
    /// <param name="token">The token for Bing Maps access</param>
    public static BruTileLayer CreateBingHybridLayer(string token)
    {
        string url = string.IsNullOrWhiteSpace(token)
                         ? BingRequest.UrlBingStaging
                         : BingRequest.UrlBing;

        return new BruTileLayer(
            new BingTileSource(new BingRequest(url, "", BingMapType.Hybrid)),
            new MemoryCache<byte[]>(100, 200));
    }

    /// <summary>
    /// Creates a Bing Maps aerial layer using the "Staging" url
    /// </summary>
    public static BruTileLayer CreateBingAerialLayer()
    {
        return CreateBingAerialLayer(String.Empty);
    }

    /// <summary>
    /// Creates a Bing Maps aerial layer using the standard url. You need to have a valid token
    /// </summary>
    /// <param name="token">The token for Bing Maps access</param>
    public static BruTileLayer CreateBingAerialLayer(string token)
    {
        string url = string.IsNullOrWhiteSpace(token)
                         ? BingRequest.UrlBingStaging
                         : BingRequest.UrlBing;

        return new BruTileLayer(
            new BingTileSource(new BingRequest(url, "", BingMapType.Aerial)),
            new MemoryCache<byte[]>(100, 200));
    }


    public static BruTileLayer CreateOsmLayer()
    {
        return new BruTileLayer(new OsmTileSource(), new MemoryCache<byte[]>(100, 200));
    }


    public ITileSource TileSource { get; private set; }
    public ITileCache<byte[]> TileCache { get; private set; }
    public bool ShowErrorInTile = true;

    /// <summary>
    /// Creates an instance of this class with an OpenStreetMap tile source and
    /// a MemoryCache.
    /// </summary>
    public BruTileLayer()
        :this(new OsmTileSource(), new MemoryCache<byte[]>(100,200))
    {
    }

    /// <summary>
    /// Creates an instance of this class
    /// </summary>
    /// <param name="tileSource">The tile source to use</param>
    /// <param name="tileCache">The tile cache to use</param>
    public BruTileLayer(ITileSource tileSource, ITileCache<byte[]> tileCache)
    {
        TileSource = tileSource;
        TileCache = tileCache;
        int epsgCode;
        if (int.TryParse(TileSource.Schema.Srs.Substring(5), out epsgCode))
        {
            _projection = new ProjectionInfo();
            _projection = ProjectionInfo.FromEpsgCode(epsgCode);
            //_projection.ReadEpsgCode(epsgCode); Modificado por camiza
        }
        else
            _projection = KnownCoordinateSystems.Projected.World.WebMercator;
        LegendItemVisible = true;

    }

    /// <summary>
    /// Tests this object against the comparison object.  If any of the 
    /// value type members are different, or if any of the properties
    /// are IMatchable and do not match, then this returns false.
    /// </summary>
    /// <param name="other">The other IMatcheable object of the same type</param>
    /// <param name="mismatchedProperties">The list of property names that do not match</param>
    /// <returns>Boolean, true if the properties are comparably equal.</returns>
    public bool Matches(IMatchable other, out List<string> mismatchedProperties)
    {
        var matches = true;

        mismatchedProperties = new List<string>();
        var otherBruTileLayer = other as BruTileLayer;
        if (otherBruTileLayer == null)
        {
            AddAllProperties(mismatchedProperties);
            return false;
        }

        if (!ReferenceEquals(TileSource, otherBruTileLayer.TileSource))
        {
            mismatchedProperties.Add("TileSource");
            matches = false;
        }

        if (!ReferenceEquals(TileCache, otherBruTileLayer.TileCache))
        {
            mismatchedProperties.Add("TileCache");
            matches = false;
        }

        if (ShowErrorInTile != otherBruTileLayer.ShowErrorInTile)
        {
            mismatchedProperties.Add("ShowErrorInTile");
            matches = false;
        }

        return matches;
    }

    private static void AddAllProperties(List<string> properties)
    {
        properties.AddRange(new [] { "TileSource", "TileCache", "ShowErrorsInTile" });
    }

    /// <summary>
    /// This method will set the values for this class with random values that are
    /// within acceptable parameters for this class.
    /// </summary>
    /// <param name="generator">An existing random number generator so that the random seed can be controlled</param>
    public void Randomize(Random generator)
    {
    }

    /// <summary>
    /// Erstellt ein neues Objekt, das eine Kopie der aktuellen Instanz darstellt.
    /// </summary>
    /// <returns>
    /// Ein neues Objekt, das eine Kopie dieser Instanz darstellt.
    /// </returns>
    /// <filterpriority>2</filterpriority>
    public object Clone()
    {
        return new BruTileLayer(TileSource, TileCache) {ShowErrorInTile = ShowErrorInTile};
    }

    /// <summary>
    /// This copies the public descriptor properties from the specified object to
    /// this object.
    /// </summary>
    /// <param name="other">An object that has properties that match the public properties on this object.</param>
    public void CopyProperties(object other)
    {
        var otherBrutileLayer = other as BruTileLayer;
        if (otherBrutileLayer == null)
            throw new ArgumentException();
    }

    public event EventHandler ItemChanged;
    public event EventHandler RemoveItem;

    private ILegendItem _parentItem;
    /// <summary>
    /// Gets the parent item relative to this item.
    /// </summary>
    public ILegendItem GetParentItem()
    {
        return _parentItem;
    }

    /// <summary>
    /// Sets teh parent legend item for this item
    /// </summary>
    /// <param name="value"></param>
    public void SetParentItem(ILegendItem value)
    {
        _parentItem = value;
    }

    /// <summary>
    /// Tests the specified legend item to determine whether or not
    /// it can be dropped into the current item.
    /// </summary>
    /// <param name="item">Any object that implements ILegendItem</param>
    /// <returns>Boolean that is true if a drag-drop of the specified item will be allowed.</returns>
    public bool CanReceiveItem(ILegendItem item)
    {
        return false;
    }

    /// <summary>
    /// Instructs this legend item to perform custom drawing for any symbols.
    /// </summary>
    /// <param name="g">A Graphics surface to draw on</param>
    /// <param name="box">The rectangular coordinates that confine the symbol.</param>
    public void LegendSymbol_Painted(Graphics g, Recta
Oct 10, 2013 at 8:04 AM
So really i cant find the spot to add the url....
Oct 10, 2013 at 8:13 AM
This didnt do anything special as well...

        public static BruTileLayer CreateOsmLayer()
        {
            return new BruTileLayer(new TmsTileSource("http://geodata.nationaalgeoregister.nl/tiles/service/tms/1.0.0/brtachtergrondkaart", new WkstNederlandSchema()), new MemoryCache<byte[]>(100, 200));
        }
Jan 29, 2014 at 2:30 PM
Still I am a bit confused on how to use the brutilelayer.

I am working with dotspatial 1.6 and could not make it work. I really could not recompile the dotspatial.controls.brutilelayer with DS 1.6, it throws me 15 errors about googlemaptype and googletilesource and something else.

Then I tried with Felix and Adriaanse dotspatial.plugins.brutilelayer... but really I did not understand how to use it by coding (in my application I don't use automatic plugins load as in demomap, instead I prefer to add single capability by myself to my toolbar).

Is there a basic coding to add a googlemap view layer to my map? like the instructions given by camiza Feb 23, 2013 at 5:54 AM?

Thank you
Oscar
Jan 29, 2014 at 7:34 PM
GoogleMap has been removed from BruTile. The implementation relied on Maps API v2 which was discontinued end of November last year.
Using it violated the license terms anyway.

The old BruTileLayer code relied on BruTile version 0.6 to 0.7.4, IIRC. Nowadays BruTile has reached 0.9 and has been refactored a lot so the old code won't work with new BruTile.

I'll check if I can get my latest effort to work without Extension.

Felix
Feb 25, 2014 at 10:05 AM
Dear All,
I am using dotspatial 1.0 for desktop application and i did not find the dotspatial.controls.brutilelayer.dll for ds 1.0, but i have downloaded a file which is giving the error of higher version. Can u guide me...?
I have brutile.dll for ds 1.0.

Regards,
Dheeraj
Apr 13, 2014 at 1:22 AM
Like with most things about dotspatial we could use more solid documentation on a step by step how to dothese things
Aug 27, 2015 at 6:43 PM
Edited Aug 27, 2015 at 6:45 PM
Hi,
Here is how I got the basemap (OpenStreetMap tile map layer) working with DotSpatial 1.7:

1) download the code from https://github.com/FObermaier/DotSpatial.Plugins
2) build the solution with Visual Studio - the outputs will be in Debug/Application Extension
3) Create a new Windows Forms application with a map control (make sure all the references are from DotSpatial 1.7)
4) Add a reference to DotSpatial.Plugins.BruTile.dll
5) Add the code to your form:

using DotSpatial.Plugins.BruTileLayer
........
private void Form1_Load(object sender, EventArgs e)
        {
            BruTileLayer baseMap = BruTileLayer.CreateOsmMapnicLayer();
            map1.Layers.Add(baseMap);
        }
Now the map will show the Bing map and when you zoom in it'll show more detail...
Sep 13, 2015 at 10:47 AM
Hi,

I am using the dotspatial.plugins.brutilelayer from Felix and it works perfect with my application.

I am looking for a way to configure the grid lines displayed between the Open Street map tiles.
Can I configure the color or hide the grid?

I call the layer this way
Dim _btLayer As DotSpatial.Plugins.BruTileLayer.BruTileLayer
_btLayer = DotSpatial.Plugins.BruTileLayer.BruTileLayer.CreateKnownLayer(BruTile.Predefined.KnownTileSource.OpenStreetMap, "")
Thank you

Thomas
Sep 14, 2015 at 9:01 PM
Edited Sep 14, 2015 at 9:01 PM
There currently is not. I've added the orange frames around the tiles for debugging purposes.
[MethodImpl(MethodImplOptions.Synchronized)]
private void DrawTile(MapArgs args, TileInfo info, Resolution resolution, byte[] buffer, TileReprojector tr = null)
{
    /*
     * Some code
     */

    if (outBitmap != bitmap) outBitmap.Dispose();
    // new:
    if (FrameTile)
    {
        var pen = FramePen ?? Pens.Orange;
        args.Device.DrawRectangle(pen, rect);    
    }
}

/// <summary>
/// Gets or sets a value indicating whether to frame the tile or not
/// </summary>
bool FrameTile { get; set; }

/// <summary>
/// Gets or sets a value indicating the Pen to frame the tile with
/// </summary>
System.Drawing.Pen FramePen { get; set; }

Sep 24, 2015 at 6:34 PM
Thank you Felix, so I can change the color easy for my Application.

There is an other issue, with the new DotSpatial.Plugins.BruTileLayer

The old one, when I saved a Project to a dspx file and load again the DotSpatial.Plugins.BruTileLayer was loaded with the Project.

Now all the shp layers are loaded but the DotSpatial.Plugins.BruTileLayer not.

I load the DotSpatial.Plugins.BruTileLayer this way.
        Private Sub _buttonAddOSMLayer_ExecuteEvent(ByVal sender As Object, ByVal e As ExecuteEventArgs)

            Dim _btLayer As DotSpatial.Plugins.BruTileLayer.BruTileLayer
           
            Map1.FunctionMode = FunctionMode.None

           _btLayer = DotSpatial.Plugins.BruTileLayer.BruTileLayer.CreateKnownLayer(BruTile.Predefined.KnownTileSource.OpenStreetMap, "")

            _btLayer.LegendText = "Open Street Map"

            Map1.Projection = KnownCoordinateSystems.Projected.World.WebMercator

            Map1.Layers.Add(_btLayer)
            Map1.MapFrame.ZoomIn()
            Map1.Refresh()

        End Sub
This works perfect as before and now the BruTile layer is also shown at the Print Layout Dialog (the old one not)

Have you tested to create a dspx file with the DotSpatial.Plugins.BruTileLayer ?

Thanks
Sep 25, 2015 at 7:16 AM
Have you tested to create a dspx file with the DotSpatial.Plugins.BruTileLayer ?
At least not thouroughly enough. Unfortunatly the lead BruTile developer made a lot of changes under the hood that screwed up most of the necessary reflection code to get the values needed to serialize properly.

I will have a look asap.
Sep 26, 2015 at 12:12 PM
Thank you, Felix

The DotSpatial.Plugins.BruTileLayer is an important part of my DS appilcation.
Nov 18, 2015 at 11:40 AM
I updated the plugin. On my machine serialization to a map document now works, Could you please verify?
Nov 19, 2015 at 6:13 PM
Yes it works perfekt with my aplication too. Many thanks!!
Feb 26, 2016 at 3:27 PM
Hi Felix,

it seems to me that last versions of the Brutile plugin makes layers interaction slow.
The thing that is most evident is when I create a new layer (say point layer) with shape editor plugin. Each new point I add to a new layer takes some seconds to appear if I have a background bing map loaded

Any hint on this?

Thank you
Oscar
Mar 21, 2016 at 3:40 PM
Dear All,

to close my issue I report a hint given to me by Felix.
Hello Oscar,

I assume you do some zooming and/or panning prior to creating or editing your geometries. Therefore, with every click you make, you somehow modify the viewport which leads to a heavy reprojection of the bing maps layer, You can avoid that if you set Map1.FunctionMode = FunctionMode.None.

If you do that there is no noticable time lapse, at least on my machine.
This was exactly the origin of the problem I encountered

Thank you Felix

Oscar
Mar 24, 2016 at 2:10 PM
Does the BrutileLayer.Plugin support ordinary WMS too?
Mar 29, 2016 at 6:44 AM
No, it does not.
There are classes that can parse WMS Server results.
WebMap plugins WMS capabilities are based on these.