首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenLayers GeoRSS解析-所有的点都在彼此的顶部

OpenLayers GeoRSS解析-所有的点都在彼此的顶部
EN

Stack Overflow用户
提问于 2012-01-23 19:20:18
回答 1查看 1.2K关注 0票数 2

我正在学习OpenGeo的OpenLayers教程,并且正在努力使用一个矢量层,它可以读取地震位置的GeoRSS编码的XML文件--在这类教程中似乎用得很多。映射生成一个点(在0,0处),仔细观察,它似乎是文件中堆叠在一起的所有点,所以很明显,在XML和OpenLayers中的点的转换之间出现了问题。

代码如下:

代码语言:javascript
复制
var geographic = new OpenLayers.Projection("EPSG:4326");
var mercator = new OpenLayers.Projection("EPSG:900913");

var world = new OpenLayers.Bounds(-180, -89, 180, 89).transform(
    geographic, mercator
);

var center = new OpenLayers.LonLat('.$centerMapLat.','.$centerMapLon.').transform(
    geographic, mercator
);

var options = {
    projection: mercator,
    units: "m",
    maxExtent: world
};

var map = new OpenLayers.Map("map-id", options);

var osm = new OpenLayers.Layer.OSM();
map.addLayer(osm);
map.addControl(new OpenLayers.Control.LayerSwitcher()); 
map.setCenter(center, 2);

var mapdata = new OpenLayers.Layer.Vector("Map Data", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "7day-M2.5.xml",
        format: new OpenLayers.Format.GeoRSS()
    })
});
map.addLayer(mapdata);

XML文件的格式如下:

代码语言:javascript
复制
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss">

<updated>2012-01-23T09:43:22Z</updated>
<title>USGS M 2.5+ Earthquakes</title>
<subtitle>Real-time, worldwide earthquake list for the past 7 days</subtitle>
<link rel="self" href="http://earthquake.usgs.gov/earthquakes/catalogs/7day-M2.5.xml"/>
<link href="http://earthquake.usgs.gov/earthquakes/"/>
<author><name>U.S. Geological Survey</name></author>

<id>http://earthquake.usgs.gov/</id>
<icon>/favicon.ico</icon>
<entry>
    <id>urn:earthquake-usgs-gov:ak:10395995</id>
    <title>M 2.7, Alaska Peninsula</title>
    <updated>2012-01-23T09:38:43Z</updated>
    <link rel="alternate" type="text/html" href="http://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/ak10395995.php"/>
    <summary type="html">
    <![CDATA[<img src="http://earthquake.usgs.gov/images/globes/60_-155.jpg" alt="57.806&#176;N 156.412&#176;W" align="left" hspace="20" />
    <p>Monday, January 23, 2012 09:38:43 UTC<br>Monday, January 23, 2012 12:38:43 AM at epicenter</p>
    <p><strong>Depth</strong>: 122.70 km (76.24 mi)</p>]]></summary><georss:point>57.8058 -156.4123</georss:point>
    <georss:elev>-122700</georss:elev>
    <category label="Age" term="Past hour"/>
</entry>

[:]

</feed>

在标签之间放置什么值似乎并不重要,也不管我剪切了多少字段,点总是出现在0,0处。我可以通过在firebug中手动编辑坐标来移动光点-这是在html中为每个点呈现的内容:

代码语言:javascript
复制
<circle id="OpenLayers.Geometry.Point_424" 
    cx="4.738678387182473" cy="237.58907791425827" 
    r="6" fill="#ee9900" fill-opacity="0.4" stroke="#ee9900" stroke-opacity="1" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="none" pointer-events="visiblePainted" cursor="inherit">

我强烈怀疑我做错了什么,所以希望能进行一次理智的检查。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-23 22:57:19

问题是,虽然地图和背景层的投影是"EPSG:900913“,但从GeoRSS加载的点在"EPSG:4326”中。

EPSG:900913坐标如下: 20037508,20037508。在EPSG:4326中,坐标范围在-180到180之间,这就是为什么看起来地图上所有的点都在0,0左右。

解决方案是在创建向量层时通过指定投影来重新投影GeoRSS点:

代码语言:javascript
复制
var mapdata = new OpenLayers.Layer.Vector("Map Data", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "7day-M2.5.xml",
        format: new OpenLayers.Format.GeoRSS()
    }),
    projection: geographic
});
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8970819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档