中心和在网页上缩放在Google地球中创建的KML文件

时间:2013-01-08 23:41:49

标签: wordpress google-maps coordinates kml

我在Google地球中创建了一个使用多边形定义多个区域的KML文件。我的计划是在我的wordpress网站上使用这个文件,以及用于wordpress的“综合谷歌地图插件”。然而,事实证明,虽然它的工作原理,根据开发人员,我无法设置中心或缩放。我想缩放到10,并以特定坐标为中心。我用谷歌搜索和研究,并不断提出一些脚本,但它有点令我困惑,我甚至会用它们做什么。这是我第一次涉足KML。有什么东西我可以添加到谷歌地球生成的KML文件中,这将允许我完成这个?任何帮助都会受到极大的赞赏。

2 个答案:

答案 0 :(得分:0)

如评论所述,使用WP插件时无法做任何事情。

但是当您在没有插件的情况下构建地图时,请使用地图的centerzoom选项来设置缩放和居中。

要防止地图平移到KML图层的内容,请将KML图层的选项preserveViewport设置为true。

示例:

map = new google.maps.Map(document.getElementById('map'), {
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  center: new google.maps.LatLng(52.519,13.406),
  zoom: 12
});
new google.maps.KmlLayer('http://example.com/example.xml',
                         {preserveViewport: true, map:map});

答案 1 :(得分:0)

请尝试使用WP Flexible Map。它允许您在KML地图上指定缩放,还可以访问地图对象,以便在加载后设置中心。

加载KML文件的短代码示例;注意:根据FAQ,我设置了一个id,稍后会从中导出JavaScript全局变量名。 [编辑:我是个白痴,我骗了错误的例子!固定]

[flexiblemap id="exmap" zoom="14" width="500" height="400"
    src="http://snippets.webaware.com.au/maps/example-toronto.kml"]

现在,将此代码添加到插件中(如果您愿意,还可以添加主题的functions.php):

add_filter('flexmap_shortcode_html', 'filterFlxmapShortcodeHtml', 10, 2);

/**
* append our script to the end of the map shortcode's HTML
* @param string $html
* @param array $attrs the shortcode's array of attributes/parameters
* @return string
*/
function filterFlxmapShortcodeHtml($html, $attrs) {
    $html .= <<<HTML
<script>
jQuery(window).load(function() {
    flxmap_exmap.setCenter(new google.maps.LatLng("12.345", "32.109"));
});
</script>

HTML;

    return $html;
}