Ajax 将arcgis online API中的geojson添加到openlayer地图

Ajax 将arcgis online API中的geojson添加到openlayer地图,ajax,openlayers,geojson,Ajax,Openlayers,Geojson,我正在尝试使用arcgis online REST API获取geojson数据(轨迹的点坐标) var data = { }; // sends AJAX request and forwards the returned data to the visualiser data.requestJSON = function(requestParameters) { $.ajax({ url: "https://services.arcgis.com/.....

我正在尝试使用arcgis online REST API获取geojson数据(轨迹的点坐标)

var data = {
};
// sends AJAX request and forwards the returned data to the visualiser
data.requestJSON = function(requestParameters) {
    $.ajax({
        url: "https://services.arcgis.com/........=*&f=geojson" ,
        method: 'GET',
        success: function(response) {
            visualizer.sendDataToMap(response);
        },
        error: function(error) {
        }
    });
};

geojson数据应该在另一个.js中处理并添加到地图中。 但是我不能把数据转换成向量。 我在论坛上找到了一些有用的答案,但仍然不起作用

var visualizer = {}
//prepare the data for visualisation
    visualizer.sendDataToMap = function(jsonData) {

        console.log("jsondata",jsonData);

        var track = new ol.source.Vector({
            features: new ol.format.GeoJSON().readFeatures(jsonData)
          });

        console.log("track",track);
}
控制台中显示的来自ajax请求的geojson数据看起来好像传递了正确的数据。

但根据我在论坛中找到的一些代码行,将其转换为向量似乎不起作用。我不理解console.log

有人能给我一个提示怎么做吗

控制台错误消息如下所示

ol.js:319 Uncaught TypeError: b.R is not a function
    at mn.l.Va (ol.js:319)
    at Object.visualizer.sendDataToMap (visualizer.js:40)
    at Object.success (dataProvider.js:10)
    at i (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at z (jquery.min.js:4)
    at XMLHttpRequest.<anonymous> (jquery.min.js:4)
ol.js:319未捕获类型错误:b.R不是函数
弗吉尼亚州明尼苏达州(ol.js:319)
在Object.visualizer.sendDataToMap(visualizer.js:40)
在Object.success(dataProvider.js:10)
at i(jquery.min.js:2)
在Object.fireWith[as resolveWith](jquery.min.js:2)
在z(jquery.min.js:4)
在XMLHttpRequest。(jquery.min.js:4)
或许有人也这么做了,可以提供一个我可以尝试效仿的例子。
谢谢。

矢量源对象的缩小转储没有多大帮助,但它确实表明代码在错误发生前已到达该行。在那一行之后,如何处理
track
?jsonData似乎是一个字符串,您必须使用JSON.parse对其进行解析。变量“track”应该添加到映射中。这应该是一条自行车道。我更进一步。似乎我需要使用
new ol.feature(track)
转换功能中的geojson几何体,至少我不再收到错误消息。尽管自行车路径在地图上仍然不可见。也许投影出了问题。我试图重新编程,但似乎不起作用
var track=new ol.source.Vector({features:{new ol.format.GeoJSON({dataProjection:'EPSG:4326',featureProjection:'EPSG:3857'})).readFeatures(jsonData)})
在readFeatures`中将投影指定为选项通常更可靠
新的ol.format.GeoJSON().readFeatures(jsonData,{dataProjection:'EPSG:4326',featureProjection:'EPSG:3857'})
您是否使用
track
作为
ol.layer.Vector
的源,然后将其添加到地图中,谢谢你的投影线,这很有帮助。至少我可以得到范围并缩放到数据应该出现的位置。是的,我想使用轨迹作为ol.layer.Vector的源。但是如果我直接尝试,我会得到一个错误:
ol.js:319 uncaughttypeerror:b.R不是一个函数
。如果一个广告先将它添加到一个
ol.Feature(track)
中,并将其用作源代码,我不会得到任何错误。不幸的是,这些点并没有出现在地图上。一定是遗漏了什么