0

まず、私はフランス人で、私の英語はとても下手です....

私の Web サイトには 2 つのスタイル付きマップがあります。私のコードは次のとおりです。

    <script type="text/javascript">

        // Detection du navigateur utilisé, ainsi que l'affichage  
        <?php include("browser.js");?>

        // Début de la création de la map
        function initialiser() {

            <?php include("cartes.js");?>

            var Night = new google.maps.StyledMapType(Nuit,{name: "Nuit"});
            var Map = new google.maps.StyledMapType(Plan,{name: "Plan"});


            // Propriétés des identificateurs prédéfinis permettant de définir des options d'affichage
            var options = {
                center: new google.maps.LatLng(49.894524, 2.30195),
                zoom: 13,
                mapTypeControlOptions: {
                    mapTypeIds: [google.maps.MapTypeId.Plan, 'map_style1', 'map_style2', ]
                }
            };

            // Constructeur de la carte dans lequel la carte doit s'afficher ainsi que les options
            var carte = new google.maps.Map(document.getElementById("carte"), options);

            carte.mapTypes.set('map_style2', Night);
            carte.setMapTypeId('map_style2');               
            carte.mapTypes.set('map_style1', Map);
            carte.setMapTypeId('map_style1');


            <?php include("geolocalisation.js");?>

            <?php include("voitures.js");?>

        }

しかし、問題は 2 つのスタイル付きマップが存在することですが、常に機能しているわけではありません...おそらく、この API の制限でしょうか?

4

1 に答える 1

0

おそらく問題はここにあります:

mapTypeControlOptions: {
    mapTypeIds: [google.maps.MapTypeId.Plan, 'map_style1', 'map_style2', ]
}

既知の MapTypeId は、HYBRID、ROADMAP、SATELLITE、および TERRAIN です。あなたが持っていPlanます。

これを次のように変更できます。

    mapTypeControlOptions: {
        mapTypeIds: [
            google.maps.MapTypeId.ROADMAP, 'map_style1', 'map_style2'
        ]
    }

したがって、どこかに定義されたスタイルNuitとがあると仮定するとPlan、次のようになります。

var Nuit = [{ ...features style... }];
var Plan = [{ ...features style... }];

init 関数を次のように変更します。

function initialiser() {

    <?php include("cartes.js");?>

    var nightMap = new google.maps.StyledMapType(Nuit,{name: "Nuit"});
    var planMap = new google.maps.StyledMapType(Plan,{name: "Plan"});

    var options = {
        center: new google.maps.LatLng(49.894524, 2.30195),
        zoom: 13,
        mapTypeControlOptions: {
            mapTypeIds: [
                google.maps.MapTypeId.ROADMAP, 'map_style1', 'map_style2'
            ]
        }
    };

    var carte = new google.maps.Map(document.getElementById("carte"), options);

    carte.mapTypes.set('map_style2', nightMap);
    carte.setMapTypeId('map_style2');

    carte.mapTypes.set('map_style1', planMap);
    carte.setMapTypeId('map_style1');

    <?php include("geolocalisation.js");?>
    ...
于 2014-05-20T07:44:29.000 に答える