gpt4 book ai didi

javascript - 传单实时 : SyntaxError: JSON. 解析:意外字符

转载 作者:行者123 更新时间:2023-12-03 03:17:57 27 4
gpt4 key购买 nike

我有一张使用传单实时的 map 。

我按照github上的描述实时设置了传单。使用示例中的 url 效果很好,但是当我直接使用 json 字符串时,我会收到以下错误消息:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data undefined leaflet-realtime.min.js:4:3695

代码如下所示:

var geojsonFeature = {"geometry": {"type": "Point", "coordinates": [-64.90913344523922, 31.274686201725011]}, "type": "Feature", "properties": {}};


var map = L.map('map',
{
center: [<?php echo $StartNorth; ?>, <?php echo $StartEast; ?>],
zoom: <?php echo $StartZoomLevel; ?>,
layers: [BasemapAT_basemap, geoJSONLayerNone],

zoomControl: false,

contextmenu: true,
contextmenuWidth: 200,
contextmenuItems: [{
text: 'Koordinaten anzeigen',
callback: showCoordinates
}, {
text: 'Karte hier zentrieren',
callback: centerMap
}, '-', {
text: 'Zoom in',
icon: 'assets/leaflet-contextmenu/dist/images/zoom-in.png',
callback: zoomIn
}, {
text: 'Zoom out',
icon: 'assets/leaflet-contextmenu/dist/images/zoom-out.png',
callback: zoomOut
}]
}
)
realtime = L.realtime({
geojsonFeature,
//url: 'https://wanderdrone.appspot.com/',
crossOrigin: true,
type: 'json'
}, {
interval: 3 * 1000,
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
'icon': L.icon({
iconUrl: 'leaflet/images/marker-icon-vehicle.png',
iconSize: [16, 16],
iconAnchor: [1, 8],
popupAnchor: [7, 0]
})
});
}}).addTo(map);

理论上它应该有效,但我无法解释为什么不行。有人可以给我提示吗?

最佳答案

文档指出:

The source can be one of:

  1. a string with the URL to get data from
  2. an options object that is passed to fetch for fetching the data
  3. a function in case you need more freedom.

In case you use a function, the function should take two callbacks as arguments: fn(success, error), with the callbacks:

  1. a success callback that takes GeoJSON as argument: success( features)
  2. an error callback that should take an error object and an error message (string) as argument: error( error, message)

根据文档,您尝试的内容作为来源无效。您可以通过使用函数来做到这一点。或者还有:

update(<GeoJSON> featureData?)

这是您可以用来传递数据的方法。

关于javascript - 传单实时 : SyntaxError: JSON. 解析:意外字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46689728/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com