javascript - 从 Bing Maps API 中的 URL 添加 PolygonOptions 到 GeoJSON

标签 javascript bing-maps geojson

我正在尝试让样式在从外部文件加载多边形的 Bing map 上工作。该文档有两个示例,第一个是直接在 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.read() 的调用替换为对 GeoJson.readFromUrl() 的调用,但这失败了。该文档没有提供有关如何设置从文件加载的 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
            }
        });

注意回调函数和样式之间的“空”。如果需要使用 JSONP 请求您的文件,您可以在该字段中指定 JSONP URL 参数。

关于javascript - 从 Bing Maps API 中的 URL 添加 PolygonOptions 到 GeoJSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47576183/

相关文章:

javascript - 许多具有相同类 getDate 的 Datpicker

javascript - 重定向后选择选项

c# - 启动 Bing map 时应使用哪个 API

c# - 将 GeoJSON 响应转换为 FeatureCollection

javascript - 未捕获的 typeerror 对象没有方法 'on' : backbone. js

javascript - 使用JQuery获取json内容

php - 如果我将 Bing map 合并到 PHP-MySQL 驱动的网站中,那么网站上线后是否需要许可证?

c# - 为必应 map 的 Silverlight 应用程序创建热图

javascript - 如何通过传单查询立交桥面积?

python-3.x - 如何更改 altair 中 geo_shape 的限制(python vega-lite)