Error: getTileUrl

Map Plus helps, usage, issues, bug report, downloads...

Error: getTileUrl

Postby tonamigon » 2018-10-22 13:12

Hello. Greetings from Japan. I'm sorry, my English is not good.

I want to add a layer of rain cloud radar as an online map (JS).
https://weather.yahoo.co.jp/weather/zoomradar/

I edited the Java Script field as below.
But an error has occurred. "Script must contains function definition of "getTileUrl(zoom, x, y)"
What is the problem? I am happy if you give me advice.

--
function getTileUrl(z, x, y)
{
var dt = new Date() ;
var yyyy= dt.getFullYear() ;
var mm = dt.getMonth()+1 ;
var dd = dt.getDate() ;

var h = dt.getHours() ;
var m = dt.getMinutes() ;

var im = parseInt(m / 10) * 10 ;

var str = yyyy.toString().substr(-2)
+ (0+mm).toString().substr(-2)
+ (0+dd).toString().substr(-2)
+ (0+h).toString().substr(-2)
+ (0+im).toString().substr(-2) ;

return "https://map.c.yimg.jp/wms/weather250?x="+x+"&y="+((1<<(z)) - y - 1 - (1<<(z-1)))+"&z="+(z+1)+"&date=“+str”;
}
User avatar
tonamigon
★★
 
Posts: 2
Joined: 2018-10-22 12:56

Re: Error: getTileUrl

Postby Zax » 2018-10-23 1:32

Here is a script error which makes the getTileUrl function invalid (not properly closed) so that the app could not detect it.

The error is:
1. The last 2 double-quote characters are not ASCII characters for JS strings, they are () and (), not the (") .
2. The last double-quote character is useless and invalid and should be removed.

What's more, after a simple review of the website, there is something else you should edit to make the your script logic correct:
as shown bellow:
Code: [Select all]
var str = yyyy.toString()
    + ('0'+mm).toString().substr(-2)
    + ('0'+dd).toString().substr(-2)
    + ('0'+h).toString().substr(-2)
    + ('0'+im).toString().substr(-2);
 
Javascript

which shows:
1) The yyyy have to be 4-digital long.
2) Add a string of "0", not number of 0 to the front of each date unit to make a fixed length date components of 2-digital

Here comes the final scripts:
Code: [Select all]
var name = "Yahoo Weather Japan";
var minZoom = 1;
var maxZoom = 15;
var projection = "WM";
function getTileUrl(z, x, y)
{
    var dt = new Date() ;
    var yyyy= dt.getFullYear() ;
    var mm = dt.getMonth()+1;
    var dd = dt.getDate() ;

    var h = dt.getHours() ;
    var m = dt.getMinutes() ;

    var im = parseInt(m / 10) * 10 ;

    var str = yyyy.toString()
    + ('0'+mm).toString().substr(-2)
    + ('0'+dd).toString().substr(-2)
    + ('0'+h).toString().substr(-2)
    + ('0'+im).toString().substr(-2);
    //https://map.c.yimg.jp/wms/weather250?x=110&y=14&z=8&date=201810230945
    return "https://map.c.yimg.jp/wms/weather250?x="+x+"&y="+((1<<(z)) - y - 1 - (1<<(z-1)))+"&z="+(z+1)+"&date="+str;
}

 
Javascript


By the way:
It is suggested to use the Online Map Editor tool to configure, debug and preview a custom online map before importing to the app, which is more convenient.

How to Use?
Visit the tool with a web browser at http://duweis.com/tool/editor/mapsource.html
Switch to the Javascript tab (on the left) and Preview tab (on the right) > choose "Google Road" in the map drop list > zoom in and pan the preview map to the region that you are interested and your custom map has content for > choose "Custom Map" in the map drop list, paste your scripts to the text box on the left, and click the "refresh" button (on the right) to test your script and preview the map.

If the script works, you should see the map content displayed in the preview box > Now switch to the "QRCode" tab on the right, and click "generate" to get a QRCode image > Lanuch the app on your iphone/ipad > go to User Data > add > Import From QRCode > point the camera to the qr-code and start importing.


What's more, for these realtime maps, since the underneath map engine you are using (the Apple's MapKit) caches map content without our control, which means even if you have set the "Cache Expire" of this map as "1 Minute", the map would not update the content automatically 1 minute later, and you have to manually select the map in User Data or Custom Maps list, and choose "Reload On Map" for a content refresh.
Zax Zeng
Duwei Technology
User avatar
Zax
★★★★★
 
Posts: 1122
Joined: 2011-07-27 0:54

Re: Error: getTileUrl

Postby tonamigon » 2018-10-23 1:55

Hi Zax,

Thank you for your quick response. The script worked fine. I appreciate the wonderful application and your wonderful support.
I also thank you for the guidance of the map editor. I did not know about this function. I will attach the generated QR-code.
Attachments
Yahoo Weather Japan.png
Yahoo Weather Japan.png
Yahoo Weather Japan.png (45.6 KiB) Viewed 197 times
User avatar
tonamigon
★★
 
Posts: 2
Joined: 2018-10-22 12:56


Return to Map Plus - Forums

cron