Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Use another map replace the google map? #13

Closed
1a57danc3 opened this issue Aug 21, 2021 · 11 comments
Closed

Use another map replace the google map? #13

1a57danc3 opened this issue Aug 21, 2021 · 11 comments

Comments

@1a57danc3
Copy link

1a57danc3 commented Aug 21, 2021

Mapbox satellite data is newest

@1a57danc3 1a57danc3 changed the title Use another map replace this plugin Use another map replace the gogole Aug 21, 2021
@1a57danc3 1a57danc3 changed the title Use another map replace the gogole Use another map replace the google map? Aug 21, 2021
@Artoria2e5
Copy link

Artoria2e5 commented Aug 22, 2021

For all the servers providing ESPG:3857 (Web Mercator) tiles, all you need is to change the lines (what happened to don't reat yourself?) at

url = f"https://mt1.google.com/vt/lyrs=s&x={tile_x}&y={tile_y}&z={level_of_detail}"
and
url = f"https://mt1.google.com/vt/lyrs=s&x={tileX}&y={tileY}&z={levelOfDetail}"

If you want Chinese sources like Baidu and Tianditu requiring coordinate-system conversion, see cntms.

@derekhe
Copy link
Owner

derekhe commented Aug 22, 2021

It should be ok. If you have credentials for mapbox, please change the code as your need.

@1a57danc3
Copy link
Author

@derekhe @Artoria2e5

Mapbox Tile URL Templates

https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?sku={yourSKUToken}&access_token={yourToken}

SKU Token and Access Token can apply mapbox free plan, 200,000 free tile requests per day.


This tool might be a GUI program(Use PyQt or PyInstaller package code to .exe file, to avoid user install python environment), and able to configure tile URL templates just like QGIS

Satellite Map Tile URL Templates

Google Map Satellite

https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}

Google Map Hybrid

https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}

Bing Map Satellite
http://ecn.t3.tiles.virtualearth.net/tiles/a{q}.jpeg?g=1


Non-Satellite Map Tile URL Templates

Google Map
https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}

OpenTopoMap

https://tile.opentopomap.org/{z}/{x}/{y}.png

OpenStreetMap

http://tile.openstreetmap.org/{z}/{x}/{y}.png

@derekhe
Copy link
Owner

derekhe commented Aug 22, 2021

For China, google map is best :)
I have use PyInstaller to create a exe file, but it reports virus when I update load to flightsim website. So I only give source code for that user. I recommended to use the exe file I made in release page.

@1a57danc3
Copy link
Author

I find a way to access Google Map satellite tile picture, avoid use local proxy.

Use Cloudflare Works service as reverse proxy


1. Add new worker script

const config = {
  basic: {
    upstream: 'https://mt3.google.com',
    mobileRedirect: 'https://mt3.google.com',
  },

  firewall: {
    blockedRegion: [],
    blockedIPAddress: [],
    scrapeShield: true,
  },

  routes: {
  },

  optimization: {
    cacheEverything: false,
    cacheTtl: 5,
    mirage: true,
    polish: 'off',
    minify: {
      javascript: true,
      css: true,
      html: true,
    },
  },
};

async function isMobile(userAgent) {
  const agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
  return agents.any((agent) => userAgent.indexOf(agent) > 0);
}

async function fetchAndApply(request) {
  const region = request.headers.get('cf-ipcountry') || '';
  const ipAddress = request.headers.get('cf-connecting-ip') || '';
  const userAgent = request.headers.get('user-agent') || '';

  if (region !== '' && config.firewall.blockedRegion.includes(region.toUpperCase())) {
    return new Response(
      'Access denied: booster.js is not available in your region.',
      {
        status: 403,
      },
    );
  } if (ipAddress !== '' && config.firewall.blockedIPAddress.includes(ipAddress)) {
    return new Response(
      'Access denied: Your IP address is blocked by booster.js.',
      {
        status: 403,
      },
    );
  }

  const requestURL = new URL(request.url);
  let upstreamURL = null;

  if (userAgent && isMobile(userAgent) === true) {
    upstreamURL = new URL(config.basic.mobileRedirect);
  } else if (region && region.toUpperCase() in config.routes) {
    upstreamURL = new URL(config.routes[region.toUpperCase()]);
  } else {
    upstreamURL = new URL(config.basic.upstream);
  }

  requestURL.protocol = upstreamURL.protocol;
  requestURL.host = upstreamURL.host;
  requestURL.pathname = upstreamURL.pathname + requestURL.pathname;

  let newRequest;
  if (request.method === 'GET' || request.method === 'HEAD') {
    newRequest = new Request(requestURL, {
      cf: {
        cacheEverything: config.optimization.cacheEverything,
        cacheTtl: config.optimization.cacheTtl,
        mirage: config.optimization.mirage,
        polish: config.optimization.polish,
        minify: config.optimization.minify,
        scrapeShield: config.firewall.scrapeShield,
      },
      method: request.method,
      headers: request.headers,
    });
  } else {
    const requestBody = await request.text();
    newRequest = new Request(requestURL, {
      cf: {
        cacheEverything: config.optimization.cacheEverything,
        cacheTtl: config.optimization.cacheTtl,
        mirage: config.optimization.mirage,
        polish: config.optimization.polish,
        minify: config.optimization.minify,
        scrapeShield: config.firewall.scrapeShield,
      },
      method: request.method,
      headers: request.headers,
      body: requestBody,
    });
  }

  const fetchedResponse = await fetch(newRequest);

  const modifiedResponseHeaders = new Headers(fetchedResponse.headers);
  if (modifiedResponseHeaders.has('x-pjax-url')) {
    const pjaxURL = new URL(modifiedResponseHeaders.get('x-pjax-url'));
    pjaxURL.protocol = requestURL.protocol;
    pjaxURL.host = requestURL.host;
    pjaxURL.pathname = pjaxURL.path.replace(requestURL.pathname, '/');

    modifiedResponseHeaders.set(
      'x-pjax-url',
      pjaxURL.href,
    );
  }

  return new Response(
    fetchedResponse.body,
    {
      headers: modifiedResponseHeaders,
      status: fetchedResponse.status,
      statusText: fetchedResponse.statusText,
    },
  );
}

// eslint-disable-next-line no-restricted-globals
addEventListener('fetch', (event) => {
  event.respondWith(fetchAndApply(event.request));
});

2. Go to your domain setting, set worker rule

https://{yourDomain}/*

And select exist worker script

3. Add CNAME record, turn on Cloudflare proxied

CNAME record target is {workerName}.{yourName}.workers.dev

4. Test

Origin

https://mt3.google.com/vt/lyrs=s&x=106&y=52&z=7

Reverse Proxied

https://gmap.gitcafe.org/vt/lyrs=s&x=106&y=52&z=7

@1a57danc3
Copy link
Author

For China, google map is best :)
I have use PyInstaller to create a exe file, but it reports virus when I update load to flightsim website. So I only give source code for that user. I recommended to use the exe file I made in release page.

I don't think so.


The new ZSQD is available now.

In Google Map satellite

image

In Mapbox satellite

image

@derekhe
Copy link
Owner

derekhe commented Aug 22, 2021

Interesting, I see ChengDu is quite old image in mapbox

@1a57danc3
Copy link
Author

1a57danc3 commented Aug 22, 2021

@derekhe
Fine, ╮(╯_╰)╭
If config file can set custom tile URL template, that's good.
And add a switch to control local proxy.

Such as :

[proxy]
# if you don't need proxy to access google or you want to use system proxy, please delete the following line
# if you use socks5 proxy, please set proxy value to true,  and the url is like socks5h://127.0.0.1:1080
#url = http://192.168.3.191:1082
proxy = true
url = socks5://192.168.3.191:1080

[map]
tile = https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?sku={yourSKUToken}&access_token={yourToken}

[offline]
# use https://www.google.com/maps to pickup
north_west = 46.357879198300516, 83.39287198273128
south_east = 22.89205887817234, 123.91045032827455
# from zoom level to zoom level. Max zoom level should be 18.
range = 5, 12
max_cache_size_G = 20
threads = 200

@derekhe
Copy link
Owner

derekhe commented Aug 22, 2021

@derekhe
Fine, ╮(╯_╰)╭
If config file can set custom tile URL template, that's good.

Such as :

[map]
tile = https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?sku={yourSKUToken}&access_token={yourToken}

Please pull request :)

@Artoria2e5
Copy link

Well, I mean, the cntms codebase should have all the features you guys need with respect to configuing URL templates. Just do a refactor, add some header and proxy settings and everything...

@derekhe
Copy link
Owner

derekhe commented Aug 25, 2021

Thanks guys for discussion, will close this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants