【问题标题】:Why is fusionMap.js plugin changing the starting position of the Google map?为什么fusionMap.js插件会改变谷歌地图的起始位置?
【发布时间】:2014-11-18 11:04:22
【问题描述】:

所以我一直在尝试设计自定义谷歌地图(Fusion Tables)的样式。我终于找到了这个插件'fusionMap.js',它让我可以参考一些可以改变颜色等的选项。

除了包括 jQuery 和插件之外,我需要添加的唯一代码就是这个......

    $('#map').fusionMap({
        publishedtable: 'https://www.google.com/fusiontables/embedviz?q=select+col6+from+1lIBTAqiuRK_U3PM9_8IB0fJjiyXmdPFZR5Jh5vuw&viz=MAP&h=false&lat=51.50644271284457&lng=-0.11780194013670364&t=1&z=13&l=col6&y=2&tmplt=2&hml=ONE_COL_LAT_LNG', // Link to published map
        mapstyles: 'scripts/maps/paledown.js' // Path to map
    });

这很棒,并且可以设置地图的样式,但是当我去测试这个页面时,地图并没有从它应该的位置开始。奇怪的是,当您转到此代码中的 URL 时,它会正确显示....

https://www.google.com/fusiontables/embedviz?q=select+col6+from+1lIBTAqiuRK_U3PM9_8IB0fJjiyXmdPFZR5Jh5vuw&viz=MAP&h=false&lat=51.50644271284457&lng=-0.11780194013670364&t=1&z=13&l=col6&y=2&tmplt=2&hml=ONE_COL_LAT_LNG

...但是 jQuery 中似乎没有任何东西可以改变位置。有谁知道它为什么会移动,或者如果这不能正常工作,有没有人知道另一种方式来设置这些地图的样式?

这是一张色彩漂亮但位置错误的地图...http://thetally.efinancialnews.com/tallyassets/hedgefundmap/index.html

【问题讨论】:

    标签: javascript jquery html google-maps google-fusion-tables


    【解决方案1】:

    那是因为插件只适用于正坐标

    来自源代码:

    parseUrl: function(url){
        var lat = url.match(/lat=(\d*).(\d*)/);    // will only match positive numbers
        this.options.lat = lat[1] + '.' + lat[2];
    
        var lng = url.match(/lng=(\d*).(\d*)/);    // will only match positive numbers
        this.options.lng = lng[1] + '.' + lng[2];
    
        var styledId = url.match(/y=(\d*)/);
        this.options.styledId = parseInt(styledId[1]);
    
        var templateId = url.match(/tmplt=(\d*)/);
        this.options.templateId = parseInt(templateId[1]);
    
        var zoom = url.match(/&z=(\d*)/);
        this.options.zoom = parseInt(zoom[1]);
    
        var column = url.match(/col+(\d*)/);
        this.options.column = 'col'+column[1];
    
        var tableid = url.match(/from\+(.+)&viz/);
        this.options.tableid = tableid[1];
    },
    

    我无法在 jsfiddle 上设置示例,但为了证明我的假设,请查看以下链接,其中我已将经度值替换为零(如插件“所见”)。

    https://www.google.com/fusiontables/embedviz?q=select+col6+from+1lIBTAqiuRK_U3PM9_8IB0fJjiyXmdPFZR5Jh5vuw&viz=MAP&h=false&lat=51.50644271284457&lng=0&t=1&z=13&l=col6&y=2&tmplt=2&hml=ONE_COL_LAT_LNG

    要解决此问题,您必须稍微调整用于提取坐标的正则表达式。 只需在第一组中添加-?

    var lat = url.match(/lat=(-?\d*).(\d*)/);
    this.options.lat = lat[1] + '.' + lat[2];
    
    var lng = url.match(/lng=(-?\d*).(\d*)/);
    this.options.lng = lng[1] + '.' + lng[2];
    

    【讨论】:

    • 太棒了!我没想到有人会回答这个问题,谢谢
    • 我想知道你是否知道我如何包含默认的谷歌地图选项,例如禁用 UI,以及 fusionMaps 设置?...developers.google.com/maps/documentation/javascript/examples/…
    • 您必须在createMap() 中调整google.maps.Map(...) 的调用。该插件仅使用两个选项(中心、缩放)。在那里你必须开始调整。
    • 谢谢,你是个天才
    • 我也很好奇,但没有答案。如果您不介意,再问 1 个问题。你有没有添加过一个自定义图标来替换所有的红点。我找到了一些添加自定义标记的代码,但它要求提供该单一标记的坐标。有没有办法全部替换?这似乎是我的答案,developers.google.com/maps/tutorials/customizing/custom-markers,但不知道我将如何将其应用为地图范围的更改。不好意思一直缠着你
    猜你喜欢
    • 1970-01-01
    • 2021-07-30
    • 2015-09-16
    • 2017-06-24
    • 1970-01-01
    • 2014-07-30
    • 2015-03-23
    • 1970-01-01
    • 2014-10-02
    相关资源
    最近更新 更多