[英]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.