gpt4 book ai didi

jquery - 使用 jQuery 循环访问 GeoRSS 中的 GeoJSON 项目

转载 作者:行者123 更新时间:2023-12-01 04:12:04 25 4
gpt4 key购买 nike

我有一个 GeoRSS 提要,我正在尝试使用 jQuery 对其进行解析以创建一个 geoJSON 数组,然后我可以使用 Leaflet 将其添加到 MapBox map 中。

我想我已经成功地将 GeoRSS 转换为 GeoJSON 了,但是我似乎无法弄清楚如何循环遍历每个项目,以便我可以将其添加到我的 map 中。如果我取出循环部分,我会在 map 上绘制一个点 - RSS 提要中的最新条目。

任何指点将不胜感激!

这是我正在运行的代码:

$(document).ready(function(){
$.get('http://shifting-sands.com/feed/', function(rssdata) {
var $xml = $(rssdata);
$xml.find("title").each(function() {
var $this = $(this),
item = {
title: $this.find("title").text(),
link: $this.find("link").text(),
description: $this.find("description").text(),
pubDate: $this.find("pubDate").text(),
latitude: $this.find("lat").text(),
longitude: $this.find("long").text()
}

函数displayPosts(rssdata){ $.each(rssdata.rss.channel.item, 函数(i,item){

                //Read in the lat and long of each photo and stores it in a variable.
lat = item.latitude;
long = item.longitude;
title = item.title;
clickurl = item.link;
//Get the url for the image.
var htmlString = '<a href="' + clickurl + '">' + title + '</a>';
var contentString = '<div id="content">' + htmlString + '</div>';

//Create a new marker position using the Leaflet API.
var rssmarker = L.marker([lat, long]).addTo(map);

//Create a new info window using the Google Maps API

rssmarker.bindPopup(contentString).openPopup();
});
}

});
});

});

最佳答案

创建 GeoJSON 特征集合:


var featurecollection = { type: 'FeatureCollection', features: [] };

并在每次循环迭代中,将功能插入其中。

featurecollection.features.push({
type: 'Feature',
properties: {}, // any properties you want in the feature
geometry: [long, lat]
});

关于jquery - 使用 jQuery 循环访问 GeoRSS 中的 GeoJSON 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19216350/

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