MediaWiki:MapFrame.js

Từ Wikivoyage

Chú ý: Sau khi lưu trang, có thể bạn sẽ phải xóa bộ nhớ đệm của trình duyệt để xem các thay đổi.

  • Firefox / Safari: Nhấn giữ phím Shift trong khi nhấn Tải lại (Reload), hoặc nhấn tổ hợp Ctrl-F5 hay Ctrl-R (⌘R trên Mac)
  • Google Chrome: Nhấn tổ hợp Ctrl-Shift-R (⇧⌘R trên Mac)
  • Internet Explorer / Edge: Nhấn giữ phím Ctrl trong khi nhấn Làm tươi (Refresh), hoặc nhấn tổ hợp Ctrl-F5
  • Opera: Nhấn tổ hợp Ctrl-F5.
/* Place importScript('MediaWiki:MapFrame.js'); into MediaWiki:Common.js */
/* Usage: inserts an iframe into a div with id "mapdiv", in conjunction with Template:MapFrame
          for embeddable dynamic maps. Relies on HTML5 data parameters.  */                    

function insertIFrame() {
    var exhtml = 'http://maps.wikivoyage-ev.org/w/poimap2.php?';
    var map = $('#mapdiv');
    if ( map.length ) {
        validateMap(map);
        var exsrc = exhtml+'lat='+map.data("lat")+'&lon='+map.data("long")
            +'&zoom='+map.data("zoom")+'&layer='+map.data("layer")+'&lang='+mw.config.get('wgContentLanguage')+'&name='+mw.config.get('wgPageName');
 
        var ifstr = '<iframe src="'+exsrc+'" width="'+map.data("width")+'" height="'+map.data("height")
            +'" style="border:0"></iframe>';
        map.html(ifstr);
        if ( map.data("layer").indexOf('O') < 0 ) {
            $('.vcard a').attr('href', function () { return this.href.replace('layer=O','layer='+map.data("layer")[0]) });
        }
    }
}

function validateMap(map) {
    if (!$.isNumeric(map.data("lat"))) map.data("lat", 51.47766);
    if (!$.isNumeric(map.data("long"))) map.data("long", -0.00115);
    if (!$.isNumeric(map.data("zoom"))) map.data("zoom", 14);
    if (!$.isNumeric(map.data("height"))) map.data("height", 420);
    if (!$.isNumeric(map.data("width"))) map.data("width", 420);
    if (map.data("layer").length > 8) map.data("layer", 'O');
}

$(document).ready(insertIFrame);