0

I have a Web GIS Server. As shown below, in general when a user connect to my WebGIS it makes the following routes :

  1. User enter GIS address (route 1).
  2. Download leaflet code page (route 2).
  3. Connect to OSM Server (route 3).
  4. Download tiles on laptop and view tiles (rout 4).

    Image for describe

        <!DOCTYPE html>
        <html>
        <head>
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
            <link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"/>
            <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" ></script></head>
     <body>
        <div id="mapid" style="width: 600px; height: 400px;"></div>
        <script>
         var mymap = L.map('mapid').setView([51.505, -0.09], 13);
         L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
          maxZoom: 18,
          tileSize: 512,
          zoomOffset: -1
         }).addTo(mymap);
        </script>
        </body></html>

How can I change routes in model A to B?

Of course I don't want to download any tiles on my server to user views tiles from my server. I think I should use something like proxy.

Display name
  • 1,228
  • 1
  • 18
  • 29
  • Welcome to SO! Why are you unhappy with the above described model (A)? – ghybs Apr 30 '20 at 12:34
  • for more safety. – John Kennedy Apr 30 '20 at 12:43
  • Safety of what? As a sys admin I would always distrust external resources going in my server. As a visitor I would trust more direct assets from an established source like OSM. One need very specific and strong rationale for diverging from common well established patterns. And be ready to invest and potentially make mistakes along the way. – ghybs Apr 30 '20 at 13:28
  • OSM just is an example. – John Kennedy Apr 30 '20 at 15:21
  • In case your Tile Source is commercial and provides you with a Client API key that you do not want to share with your visitors, sure a solution would be your model B, where you need to proxy and add your API key. In the end it is not worth the effort, compared to swapping keys in case of abuse (commercial solutions will let you regenerate keys easily, precisely for such scenario). – ghybs Apr 30 '20 at 16:10
  • OK @ghybs. How can i set proxy in leaflet? – John Kennedy Apr 30 '20 at 17:33
  • Your sketch is good: it shows that the work is mainly in your server. Leaflet is only for client side. – ghybs Apr 30 '20 at 18:59
  • I have proxy like : `ip =1.1.1.1 port=8081` and I want all tiles download from any tile server like OSM or other download from this proxy How can i do? – John Kennedy Apr 30 '20 at 19:37
  • Exact method depends on how your proxy works and is configured. Easiest is if it expects the target URL as an URL parameter: in that case, simply modify the Tile Layer URL template accordingly. If the target URL is expected as a request header, then you will need a custom Tile Layer implementation with creative querying of the image tiles, see e.g. https://stackoverflow.com/a/48460805/5108796 – ghybs Apr 30 '20 at 21:15
  • Thanks @ghybs . I dont need header. I need all users when connect to my webGis, tiles url `L.tileLayer('https://{s}.tile.anyserverexample.org/{z}/{x}/{y}.png'` connect with proxy ip and port . how can i set proxy on all tiles layer? – John Kennedy May 01 '20 at 06:38

0 Answers0