2017-11-09 5 views
0

GoogleマップAPIの新機能です。 Googleマップのデータレイヤーにラベルを配置する必要があります。私はこの問題を解決するために任意のJavaScriptコードを書くことは可能です理解する必要がありますか?Googleマップのレイヤーにラベルやマーカーを追加する方法はありますか?

new google.maps.Marker({ 
     position: e.latLng, 
     map: map, 
     icon: { 
     path: resultPath, 
     fillColor: resultColor, 
     fillOpacity: .2, 
     strokeColor: 'white', 
     strokeWeight: .5, 
     scale: 10 
     } 
    }); 

「map:map」ではなく、上記のコードからすべてのレイヤーを使用できますか?

答えて

0

google.maps.Dataレイヤーには、共通のオーバーレイオブジェクト(マーカー、ポリライン、ポリゴン、円、矩形)はありません。 google.maps.Data.FeatureオブジェクトまたはGeoJSON有効リテラルを表示します。あなたは、例えば、あなたのマーカーのスタイリングについて

var geoJsonFeature = { 
    type:'Feature', 
    geometry:{ 
     type:'Point', 
     coordinates:[e.latLng.lng(), e.latLng.lat()] 
    } 
} 

google.maps.data.addGeoJson(geoJsonFeature); 

を行うことにより、データ層にマーカーを追加することができ

、あなたがのために、そう

google.maps.data.setStyle(function(Feature) { 

    return { 
     icon: { 
     path: Feature.getProperty('resultPath'), 
     fillColor: Feature.getProperty('resultColor'), 
     fillOpacity: .2, 
     strokeColor: 'white', 
     strokeWeight: .5, 
     scale: 10 
    } 
    };   

}); 

としてdatalayerのスタイルを設定することができます各データレイヤーgoogle.maps.data.Featureを追加します。マーカのスタイルを変えたい場合は、事前にパスとfillColorを

var geoJsonFeature = { 
    type:'Feature', 
    properties: { 
     path: resultPath, 
     fillColor: resultColor 
    }, 
    geometry:{ 
     type:'Point', 
     coordinates:[e.latLng.lng(), e.latLng.lat()] 
    } 
} 
0

いいえ、あなたはthe documentationあたりgoogle.maps.Mapまたはgoogle.maps.StreetViewPanoramaオブジェクトでなければならない、ことはできません。

マップ
タイプ:Map | StreetViewPanorama
マーカーを表示する地図。

+0

ご返信ありがとうございます –

関連する問題