Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图API-覆盖自定义道路_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 谷歌地图API-覆盖自定义道路

Javascript 谷歌地图API-覆盖自定义道路,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我对谷歌地图API有一些问题。我设法用一个图像平铺制作了一个cutom贴图。看起来还可以。我只是想知道是否有办法在地图上覆盖道路 目前,我假设有两种方法可以做到这一点,要么是API中的一些内置函数,我很难找到它们。我已经找到了路径等,但我希望道路/街道有标签,缩放等调整大小,以及能够切换 另一个选择是做第二个图像平铺并覆盖该图像,我现在不知道该怎么做 如果有人对此有任何信息,或者可以为我指出正确的方向。非常感谢 /* <![CDATA[ */ /* Global variabl

我对谷歌地图API有一些问题。我设法用一个图像平铺制作了一个cutom贴图。看起来还可以。我只是想知道是否有办法在地图上覆盖道路

目前,我假设有两种方法可以做到这一点,要么是API中的一些内置函数,我很难找到它们。我已经找到了路径等,但我希望道路/街道有标签,缩放等调整大小,以及能够切换

另一个选择是做第二个图像平铺并覆盖该图像,我现在不知道该怎么做

如果有人对此有任何信息,或者可以为我指出正确的方向。非常感谢

 /* <![CDATA[ */

    /* Global variable that will contain the Google Maps object. */
    var map = null

    // Google Maps Demo object
    var Demo = Demo || {};

    // The path to your tile images.
    Demo.ImagesBaseUrl = './mapImage/mapTiles/';
    Demo.ImagesRoadsUrl = './mapImage/overlayRoads/';

    // NuviaMap class
    Demo.NuviaMap = function(container) {
        // Create map
        // This sets the default info for your map when it is initially loaded.
        map = new google.maps.Map(container, {
            zoom: 1,
            center: new google.maps.LatLng(0, 0),
            mapTypeControl: false,
            streetViewControl: false,
            zoomControl: true,
            zoomControlOptions: {
                style: google.maps.ZoomControlStyle.SMALL
            }
        });

        // Set custom tiles
        map.mapTypes.set('nuvia', new Demo.ImgMapType('nuvia', '#4E4E4E'));
        map.setMapTypeId('nuvia');

        // Loop through the marker info array and load them onto the map.
        for (var key in markers) {
            var markerData = markers[key];

            var marker = new google.maps.Marker({
                    position: new google.maps.LatLng(markerData.lat, markerData.lng),
                    map: map,
                    title: markerData.title,
                    flat: markerData.flat,
                    visible: true,
                    infoBubble: new InfoBubble({
                            maxWidth: 300,
                            content: (markerData.image ? '<img src="' + markerData.image + '" width="80" align="left">' : '') + '<h3>' + markerData.title + '</h3>' + (markerData.info ? '<p>' + markerData.info + '</p>' : ''),
                        shadowStyle: 1,
                        padding: '10px'
                    }),
                // You can use custom icons, default icons, etc. In my case since a city was a marker the circle icon works pretty well.
                // I adjust the scale / size of the icon depending on what kind of city it is on my map.
                icon: {
                    url: markerData.icon,
                }
            });
        // We need to trap the click event for the marker so we can pop up an info bubble.
        google.maps.event.addListener(marker, 'click', function() {
            this.infoBubble.open(map, this);
        });
        activeMarkers.push(marker);
    }

    // This is dumb. We only want the markers to display at certain zoom levels so this handled that. 
    // Google should have a way to specify zoom levels for markers. Maybe they do but I could not find them.
    google.maps.event.addListener(map, 'zoom_changed', function() {
        var currentZoom = map.getZoom();

        for (var i = 0; i < activeMarkers.length; i++) {
            var thisTitle = activeMarkers[i].title;

            if (markers[thisTitle]['zoom'][currentZoom])
                activeMarkers[i].setVisible(true);
            else
                activeMarkers[i].setVisible(false);
        }
    });

    // This handles the displaying of lat/lng info in the lat/lng info container defined above in the HTML.
    google.maps.event.addListener(map, 'click', function(event) {
        $('#latLng').html("Latitude: " + event.latLng.lat() + " " + ", longitude: " + event.latLng.lng());
    });
    // Listener to display the X/Y coordinates
    google.maps.event.addListener(map, 'mousemove', function (event) {
        displayCoord(event.latLng);            
    });
    };

    // ImgMapType class
    Demo.ImgMapType = function(theme, backgroundColor) {
        this.name = this._theme = theme;
        this._backgroundColor = backgroundColor;
    };

    // Let Google know what size our tiles are and what our min/max zoom levels should be.
    Demo.ImgMapType.prototype.tileSize = new google.maps.Size(256, 256);
    Demo.ImgMapType.prototype.minZoom = 1;
    Demo.ImgMapType.prototype.maxZoom = 5;

    // Load the proper tile.
    Demo.ImgMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
        var tilesCount = Math.pow(2, zoom);

        if (coord.x >= tilesCount || coord.x < 0 || coord.y >= tilesCount || coord.y < 0) {
            var div = ownerDocument.createElement('div');
            div.style.width = this.tileSize.width + 'px';
            div.style.height = this.tileSize.height + 'px';
            div.style.backgroundColor = this._backgroundColor;
            return div;
        }

        var img = ownerDocument.createElement('IMG');
        img.width = this.tileSize.width;
        img.height = this.tileSize.height;
        // This tells what tile image to load based on zoom and coord info.
        img.src = Demo.Utils.GetImageUrl('tile_' + zoom + '_' + coord.x + '-' + coord.y + '.png');

        return img;
    };

    // Just basically returns the image using the path set way above and the name of the actual image file.
    Demo.Utils = Demo.Utils || {};
    Demo.Utils.GetImageUrl = function(image) {
        return Demo.ImagesBaseUrl + image;
    };

    // Opacity.
    Demo.Utils.SetOpacity = function(obj, opacity /* 0 to 100 */ ) {
        obj.style.opacity = opacity / 100;
        obj.style.filter = 'alpha(opacity=' + opacity + ')';
    };

    // Create ye ol' map.
    google.maps.event.addDomListener(window, 'load', function() {
        var nuviaMap = new Demo.NuviaMap(document.getElementById('nuvia-map'));
    });

    console.log('Ready Builder');
    /* ]]> */

这是到目前为止我正在研究的JS,请看

你是在寻找普通道路,比如混合地图类型还是你自己的自定义道路,如标题所示?自定义道路,我想你可以说是“幻想”地图。所以定制地形,道路,一切。我认为图像平铺效果最好,因为我可以做多个图层,而且很容易做到,我只是不知道怎么做。我认为KML图层对你来说是个好方法。它基本上是作为瓷砖覆盖层工作的。这是关于它的文档:谢谢,这看起来不错,我将有一个剧本。非常感谢。