Here is an example of use with HERE.COM REST API


Private $cInfo As New Collection


Public Sub Form_Open()
Dim hLayer As _MapTile

$cInfo!YOUR_APP_ID = ""   '<-- fill it
$cInfo!YOUR_APP_CODE = ""  '<--fill it

hLayer = MapView1.Map.AddTile("Here",
"http://{s}.aerial.maps.cit.api.here.com/maptile/2.1/blinetile/newest/satellite.day/{z}/{x}/{y}/256/png8?";
"app_id={YOUR_APP_ID}&app_code={YOUR_APP_CODE}", $cInfo)

hLayer.SubDomains = [1, 2, 3, 4]


hlayer = MapView1.Map.AddTile("Here",
"http://{s}.base.maps.cit.api.here.com/maptile/2.1/streettile/newest/normal.day/{z}/{x}/{y}/256/png8?";
"app_id={YOUR_APP_ID}&app_code={YOUR_APP_CODE}", $cInfo)

hLayer.SubDomains = [1, 2, 3, 4]

MapView1.Map.MaxZoom = 20

End



Just add a MapView to a form :-) and go !

For a google layer :
MapView1.Map.AddTile("GoogleMap",
"https://khms{s}.google.fr/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile";,
["version": "138"], "gm").SubDomains = ["0", "1", "2"]
MapView1.Map.AddTile("GoogleRoad",
"https://mts{s}.google.com/vt/lyrs=h@215000000&hl=fr&src=app&x={x}&y={y}&z={z}&s=Galile";).SubDomains
= ["0", "1"]


For an openstreet layer :

  With MapView1.Map.AddTile("OpenStreet",
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";, Null)
  '.Opacity = 0.5
  .Copyright = "OpenStreetMap contributors"
  .Opacity = 0.5
  End With



For a M$ Earth layer :

MapView1.Map.AddTile("Virtual Earth",
"http://ecn.dynamic.t{s}.tiles.virtualearth.net/comp/ch/{q}?mkt=fr-fr&it=G,VE,BX,L,LA&shading=hill&n=z&cb=1";).SubDomains
= ["0", "1", "2"]



{x}
is the Column of the tile

{y}
is the row of the tile

{z}
is the zoom level

{q}
is a computed quadkey

{s}
is a subserver list by default ["a","b","c"], it allow gb.map to use
multiple simultaneous call to a range of different server.


You can use a collection to pass some dynamics arguments. The
collection key is given in the pattern between {}.

You can give a cache name so the tiles are saved on your harddrive
and can be used offline.


they are more improvement in gb.map like wms and wmstile support but
it's experimental.

to center your map on a location you can do :

mapview.map.center = mappoint(lat, lon)

be carefull as mappoint is a decimal lat/lon value there is a tool to
convert a given sexagesimal value to a decimal value is the Geo class.

Fortunally Map support shapes too.

I have support for giving a specific pre initialised httpserver on the
need ... it's usefull for server that need authentication before using
with specific cookie file.

This is an hard example of this kind of use.



Public Sub Form_Open()
  Dim hClient As New HttpClient
  Dim _Lay As _MapTile
  Dim cArgs As New Collection
  Dim hBounds As New MapBounds
  Dim idep, iend As Integer
  Dim stext As String
  Dim a As String[]
  Dim hproj As Proj = Proj("epsg:4326")

  hClient.Async = False
  hClient.CookiesFile = Temp
  hClient.UpdateCookies = True

  hClient.URL = "http://www.cadastre.gouv.fr/scpc/rechercherPlan.do";
  hClient.Get()
  hClient.URL =
"http://www.cadastre.gouv.fr/scpc/listerCommune.do?codeDepartement=017&keepVolatileSession=&listeCommuneNatValeurVueFilterField=&listeCommuneNatValeurVueFilterValue=&offset=500";
  hClient.Get()
  hClient.URL =
"http://www.cadastre.gouv.fr/scpc/afficherCarteCommune.do?c=9B016&keepVolatileSession";
  hClient.Get()
  'récupération de la zone
  '
   sText = Replace(hClient.Peek(), "\t", "")

  idep = InStr(sText, "GeoBox(") + 7
 iEnd = InStr(sText, ")", idep)


 a = Split(Replace(Mid(sText, idep, iend - idep), "\n", ""))

 hBounds = Proj("IGNF:RGF93CC46").TransformMBounds(Proj("epsg:4326"),
MapBounds(MapPoint(CFloat(a[1]), CFloat(a[0])), MapPoint(CFloat(a[3]),
CFloat(a[2]))))




  MapView1.Map.AddTile("GoogleMap",
"https://khms{s}.google.fr/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile";,
["version": "134"]).SubDomains = ["0", "1", "2"]
  MapView1.Map.AddShape("mysh")

  MapView1.Map!mysh.Addpoint("pp", hBounds.NorthEast)

  MapView1.Map!mysh.Addpoint("pp2", hBounds.SouthWest)
  MapView1.Map.Zoom = 15
  MapView1.Map.Center = hBounds.NorthEast



  _Lay = MapView1.Map.AddTile("CAD", "http://www.cadastre.gouv.fr/scpc/wms";)



  With _Lay
    .WMSProjection = "IGNF:RGF93CC46"
    .SetCoockieFile(hClient.CookiesFile)
    .UseWebMapService = True
    .MaxBounds = hBounds
    .WMSArgs!version = "1.1"
    .WMSArgs!request = "GetMap"
    .WMSArgs!layers =
"CDIF:LS3,CDIF:LS2,CDIF:LS1,CDIF:PARCELLE,CDIF:NUMERO,CDIF:PT3,CDIF:PT2,CDIF:PT1,CDIF:LIEUDIT,CDIF:SUBSECTION,CDIF:SECTION,CDIF:COMMUNE"
    .WMSArgs!format = "image/png"
    .WMSArgs!width = "256"
    .WMSArgs!height = "256"
    .WMSArgs!exception = "application/vnd.ogc.se_inimage"
    .WMSArgs!styles =
"LS3_90,LS2_90,LS1_90,PARCELLE_90,NUMERO_90,PT3_90,PT2_90,PT1_90,LIEUDIT_90,SUBSECTION_90,SECTION_90,COMMUNE_90"
    .WMSArgs!bbox = "{lon},{lat2},{lon2},{lat}"


  End With

End



As you can see this component is quite complete but can miss many
things. For these missing part i need some users queries as i can't
know all needs.


' Gambas class file

Private $Map As New Map
Public Sub _new()
  'LoadFromPac
 $Map.AddTile("GoogleMap",
"https://khms{s}.google.fr/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile";,
["version": "128"], "gm").SubDomains = ["0", "1", "2"]
 $Map.AddTile("GoogleRoad",
"https://mts{s}.google.com/vt/lyrs=h@215000000&hl=fr&src=app&x={x}&y={y}&z={z}&s=Galile";).SubDomains
= ["0", "1"]
 $Map.AddShape("MyShape").Color = Color.green
  LoadFromFile($Map!MyShape)




End

Public Sub LoadFromFile(hShape As Object)

  'Dim hShape As New Shapes
  Dim hmappoints As New MapPoint[][]
  Dim hpoints As New MapPoint[]
  Dim s, t As String
  Dim i As Integer
  Dim c As Integer
  hshape.Color = Color.Green
  s = File.Load("./pointsparcelle")
  For Each t In Split(s, "\n")
    If t = "" Then
      hmappoints.Add(hpoints)
      hshape.AddPolygon(i, hmappoints)
      'hShape[i].Color = c
      'c += 600
      Inc i
      hmappoints = New MapPoint[][]
    hpoints = New MapPoint[]
    Else
      hpoints.Add(MapPoint(Scan(t, "* *")[1], Scan(t, "* *")[0]))
    Endif


  Next
  'Return hshape
End

Public Sub Form_Open()

  Dim i As Integer

  For i = 0 To $Map!MyShape.Max

    ListView1.Add(i, i, $Map.grab($Map!MyShape[i].Bounds, 120, 100).Picture)

  Next

End


This last example show  how to load shapes (it's my fields),
initialize a map object and then fill a listView with grabed picture
from the map in a gived Bound limits from the field size.

the map object automatiquely choose the good zoom level to fit the
shape size and the queried image size.

you can provide a padding in pixel too and a fixed zoom level.

Public Function Grab(Bounds As MapBounds, iWidth As Integer, iHeight
As Integer, Optional Padding As Integer, Optional Zoom As Integer) As
Image


Really Gambas is powerfull :-)

------------------------------------------------------------------------------
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to