簡體   English   中英

ImageMapType 上的 Google Maps V3 KML 圖層

[英]Google Maps V3 KML Layer over ImageMapType

我有一個通過 MapTiler 創建的非常小的自定義 map,用 GMaps 渲染它很容易。 所需的幾行代碼的基礎知識如下。

我也有一個可愛的小 KML 層,它渲染得很好。

但是....對於我的生活,我無法讓兩個圖層一起顯示。 一旦指示 KML 進行渲染,自定義 map 層就會消失。 Firebug 甚至告訴我,我的自定義圖塊甚至沒有被請求。 理想情況下,我需要 KML 層覆蓋我的自定義 map 層。 它將顯示一些英國地標的位置。

在我的腦海里,我在思考投影類型和沖突,但是當兩個圖層分別在基礎 map 上正確渲染時,我真的被蒙在鼓里了。

誰能給我關於 Google Maps V3 中自定義 Map 類型的 KML 層的建議?

謝謝

  var MyCustomMapType = new google.maps.ImageMapType({
 getTileUrl: function(tile, zoom) {
        return "/static/images/maps/uk/" + zoom+"/"+tile.x+"/"+ tile.y +".png";
 }, 
 tileSize: new google.maps.Size(256, 256),
  });

  function init(){

  var mapOpts = {
    zoom: 6,
    center: new google.maps.LatLng(53.94315470224928, -3.515625),
    mapTypeId: google.maps.MapTypeId.ROADMAP
};

map = new google.maps.Map(document.getElementById("map_canvas"), mapOpts);
map.overlayMapTypes.insertAt(0, MyCustomMapType);
var cathedrals = new google.maps.KmlLayer('http://pointing_at_my/kml/');

// as soon as this executes, ImageMapType layer disappears
cathedrals.setMap(map);
 }

解決了。 只是不要做一個白痴。

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">

        var map, cathedrals;

        var ukOverlay = new google.maps.ImageMapType({

            getTileUrl: function(coord, zoom) {

                var ymax = 1 << zoom;
                var y = ymax - coord.y -1;
                return "/static/images/maps/uk/" + zoom+"/"+coord.x+"/"+y+".png";

            }, 
            tileSize: new google.maps.Size(256, 256),
            isPng: true

       });

function init(){

    var mapOpts = {
        zoom: 6,
        center: new google.maps.LatLng(54.40315470224928, -3.515625),
        mapTypeId: google.maps.MapTypeId.HYBRID ,
        disableDefaultUI: false,
        mapTypeControl: false,
        scrollwheel: false,
        navigationControl: false,
        mapTypeControl: false,
        scaleControl: false,
        draggable: false
    };

    map = new google.maps.Map(document.getElementById("map_canvas"), mapOpts);
    cathedrals = new google.maps.KmlLayer('http://cathedralcafes.co.uk/kml/', {preserveViewport: true});
    map.overlayMapTypes.insertAt(0, ukOverlay);     
    cathedrals.setMap(map);
}

    </script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM