基于 ImageMapType 的 Google 地图 V3 KML 图层

发布于 2024-11-15 02:30:34 字数 1056 浏览 0 评论 0原文

我通过 MapTiler 创建了一个相当小的自定义地图,并且使用 GMap 渲染它非常容易。所需的几行代码的基础知识如下。

我也有一个可爱的小 KML 图层,它渲染得很好。

然而......在我的一生中,我无法让两个图层一起显示。一旦指示 KML 进行渲染,自定义地图图层就会消失。 Firebug 甚至告诉我,甚至没有要求我的自定义图块!理想情况下,我需要在自定义地图图层上使用 KML 图层。它将显示一些英国地标的位置。

在我的脑海深处,我正在考虑投影类型和冲突,但是当两个图层分别在底图上正确渲染时,我真的一无所知。

谁能给我有关 Google 地图 V3 中自定义地图类型上的 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);
 }

I have a pretty little custom map created through MapTiler and it was dead easy to get it to render with GMaps. The basics of the few lines of code needed are below.

I have a lovely little KML layer too which renders fine.

However.... for the life of me I can't get both layers to display together. As soon as the KML is instructed to render, the custom map layer disappears. Firebug even tells me that my custom tiles are not even requested! Ideally I need the KML layer over my custom map layer. It's going to show where a few UK landmarks are located.

At the back of my mind I'm thinking projection types and conflicts, but when both layers render correctly on the base map individually, I really am left in the dark.

Can anyone give me advice on KML layers over Custom Map Types in Google Maps V3?

Thank you

  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);
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别再吹冷风 2024-11-22 02:30:34

解决了。只是别当个白痴。

    <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>

Solved. Just don't be an idiot.

    <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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文