2 OSM Layers

Topics: Feature Requests
Nov 30, 2010 at 4:18 PM

Hello Radioman,

is it possible to add two layer on one map?

For example i have an OSM-Layer(Basis Layer) and additional i have rendered some tiles with informations about water and such things and have this one as layer on my OSM-Server.

e.g. return string.Format("http://172.16.10.251/tiles/w_gps_points/{1}/{2}/{3}.png", letter, zoom, pos.X, pos.Y);

but so i miss the map-layer.

Is there a possibility to load and show both?

Thanks

RobbeEDE

Coordinator
Nov 30, 2010 at 4:37 PM

try add your custom maptype

Dec 1, 2010 at 12:30 PM

Hello radioman,

to add an own maptype is not the problem, but to combine the basic map and one of these open-layers.

For example:

http://openlayers.org/dev/examples/baseLayers.html

here you can show/not show the additional layer "markers", these one are prerenderd and have there own tiles on the server. With this option it is possibile to show thousands of markers in a very fast way.

 

But i don't find the section in your code where the tiles are "painted" that i can add a class for load/paint custom-layers.

A future vision could be to render own tiles in background and show them or not.

Greetz Robbeede

 

Coordinator
Dec 1, 2010 at 4:55 PM

hm, well there is few places to add new layer, firs you must have new maptype with unique id, then if you combine two layers change function GMaps.GetAllLayersOfType(MapType type)

Dec 4, 2010 at 8:55 AM

Fantastic, works fine!

Thanks

Sep 4, 2011 at 12:13 PM

Where can i find the function "GMaps.GetAllLayersOfType(MapType type)"? It seems that it doesn't exists anymore!?

Coordinator
Sep 4, 2011 at 12:30 PM

maptypes was changed to MapProviders, it contains property Overlays, each map provider has it's own projection/etc... you can create easily your own provider without changing the core code

Sep 5, 2011 at 9:38 AM

Okay, implementing a new map provider was not that difficult thanks to your help. Because I'm using a local folder as "server" i wrote a new function "GetTileImageUsingFile" in "GMapProvider.cs".  In my own "XYZMapProvider.cs" the function "GetTileImage" was changed to use the new function "GetTileImageUsingFile" for not getting errors in the existing function "GetTileImageUsingHttp", when the URLs starts with "file://" (see appended code). 

But I don't get it with the overlays. :-(

I have multiple online and local MapProviders with different coverage. OSM as base map, aeronautical navigation charts covering a whole country and local aerodrome arrival and departure charts. I want to show or hide the country maps and the arrival and departure charts on top of each other at runtime depending on what the user wishes. Can you give me another hint how to do it? Thank you very much.


// new function "GetTileImageUsingFile" in "GMapProvider.cs":

      public PureImage GetTileImageUsingFile(string url)
      {
         PureImage ret = null;

         byte[] buff = System.IO.File.ReadAllBytes(url);
         System.IO.MemoryStream ms = new System.IO.MemoryStream();
         ms.Write(buff, 0, buff.Length);
         ret = TileImageProxy.FromStream(ms);
         if (ret != null)
         {
             ret.Data = ms;
         }

         return ret;
      }


// changed function "GetTileImage" in my own "XYZMapProvider.cs":

      public override PureImage GetTileImage(GPoint pos, int zoom)
      {
         string url = MakeTileImageUrl(pos, zoom, string.Empty);

         return GetTileImageUsingFile(url);
      }

 

Coordinator
Sep 5, 2011 at 10:48 AM

just create few providers with the same base in overlays and different top layer, then you can switch between providers, and some layers from user perspective will 'appear' and some will be 'hidden'

if(overlays == null)
{
 overlays = new GMapProvider[] { this, SecondProviderLayer };

if(overlays == null)
{
 overlays = new GMapProvider[] { FirstProvider, SecondProviderLayer };
 

etc.. 

Sep 9, 2011 at 9:12 AM

Thank you very much, radioman, now i got it. :-) This is really a great tool!

But there seems to be an issue with the memory cache (or I'm doing something wrong): When changing/adding/deleting the "MapProviders" in the "overlays" property, the GmapControl does not allways show the intended MapProviders which are active at that moment but seems to show tiles that are in memory. When zooming in or out to zoom levels which where not loaded before, it works, but returning to an previously loaded zoom leven shows the "old" MapProviders which are not in the overlay property anymore. Sending an "ReloadMap" does not help! Also "Manager.Mode" is set to "ServerOnly" already. The only way to get it behave in the intended way seems to set "Manager.UseMemoryCache" to "False"...

Is there an error with the memory cache while working with changing multiple MapProvider overlays or am I doing something wrong?

Thank you for your help!

Coordinator
Sep 9, 2011 at 9:19 AM

..you don't get the idea, you must create whole new provider with new guid and different overlay configuration, and only change map.Provider property on runtime, overlay list in provider itself is readonly and is not changing, otherwise cache database would be corrupted with the same id but different tiles from separate maps.

Sep 9, 2011 at 1:01 PM

Okay, the problem was that I made the overlay property writeable! So that was no good idea...

Oct 24, 2011 at 12:15 PM

Hello Radioman,

can you make an example in Demo? Perhaps how to make a custom Provider(For example the Label-Top-Layer) an switch on on / off.

Thank you very much.

EDE

Coordinator
Oct 24, 2011 at 1:19 PM

create two providers, with and without some layer, and switch between them

Jun 18, 2012 at 8:34 PM

Hi BlueCard - This is exactly what I am trying to get working: A custom map provider that reads map data from disk. Mine loads the data OK, but continues to tile the same image over and over. Did you get yours to work? I suspect I have not told the map control about the size of the image, but not sure how to do that.