簡體   English   中英

從Bing Maps API中的URL向GeoJSON添加PolygonOptions

[英]Add PolygonOptions to GeoJSON from URL in Bing Maps API

我正在嘗試使用Bing地圖上的樣式來加載外部文件中的多邊形。 該文檔有兩個例子,首先是直接在javascript中包含數據:

    //Load the GeoJson Module.
    Microsoft.Maps.loadModule('Microsoft.Maps.GeoJson', function () {

        //Parse the GeoJson object into a Bing Maps shape.
        var shape = Microsoft.Maps.GeoJson.read(myGeoJson, {
            polygonOptions: {
                fillColor: 'rgba(255,0,0,0.5)',
                strokeColor: 'white',
                strokeThickness: 5
            }
        });

        //Add the shape to the map.
        map.entities.push(shape);
    });

(其中'myGeoJson'是先前定義的變量)

第二個從文件中加載它:

    //Load GeoJSON module.
    Microsoft.Maps.loadModule('Microsoft.Maps.GeoJson', function () {

        //Read the GeoJSON file that is hosted on the same domain.
        Microsoft.Maps.GeoJson.readFromUrl('data/Countries.js',
            function (shapes) {
                //Add the shape(s) to the map.
                map.entities.push(shapes);
            });
    });

我希望能夠從文件加載,如第二個示例中所示,但在第一個示例中將其設置為樣式。

我在弄清楚如何做到這一點時遇到了麻煩。 我試過在第一個例子中通過調用GeoJson.readFromUrl()來簡單地替換對GeoJson.read()的調用,但是這個失敗了。 該文檔沒有提供任何關於如何設置從文件加載的geojson樣式的線索。

任何人都可以給我任何提示或提示嗎?

請嘗試以下方法:

//Load GeoJSON module.
    Microsoft.Maps.loadModule('Microsoft.Maps.GeoJson', function () {

        //Read the GeoJSON file that is hosted on the same domain.
        Microsoft.Maps.GeoJson.readFromUrl('data/Countries.js',
            function (shapes) {
                //Add the shape(s) to the map.
                map.entities.push(shapes);
            }, null, {
            polygonOptions: {
                fillColor: 'rgba(255,0,0,0.5)',
                strokeColor: 'white',
                strokeThickness: 5
            }
        });

注意回調函數和樣式之間的“null”。 如果需要使用JSONP請求文件,則可以在該字段中指定JSONP URL參數。

暫無
暫無

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

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