OpenStreetMap 点未显示在具有开放图层的地图上

发布于 2024-12-18 00:52:10 字数 870 浏览 1 评论 0原文

var map;
var vectors;
var point;
var drag;

可以使用任何长和纬度

function mapCreate(lon,lat){
            map = new OpenLayers.Map("map1");
            var osm = new OpenLayers.Layer.OSM();
            //create a vector
            vectors = new OpenLayers.Layer.Vector("Vector Layer");
            map.addLayer(osm);
            var center = new OpenLayers.LonLat(lon,lat).transform(
                new OpenLayers.Projection("EPSG:4326"),
                map.getProjectionObject()
            );

为该点指定一个纬度长

point = new OpenLayers.Geometry.Point(lat,lon);

将点添加到向量

        vectors.addFeatures([new OpenLayers.Feature.Vector(point)]);

        map.setCenter(center, 15);
        //add vectors to map
        map.addLayer(vectors);

    }

我是否遗漏了什么?

var map;
var vectors;
var point;
var drag;

Any long and Lat can be used

function mapCreate(lon,lat){
            map = new OpenLayers.Map("map1");
            var osm = new OpenLayers.Layer.OSM();
            //create a vector
            vectors = new OpenLayers.Layer.Vector("Vector Layer");
            map.addLayer(osm);
            var center = new OpenLayers.LonLat(lon,lat).transform(
                new OpenLayers.Projection("EPSG:4326"),
                map.getProjectionObject()
            );

Assign a lat long to the point

point = new OpenLayers.Geometry.Point(lat,lon);

Add point to vectors

        vectors.addFeatures([new OpenLayers.Feature.Vector(point)]);

        map.setCenter(center, 15);
        //add vectors to map
        map.addLayer(vectors);

    }

Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕花眠 2024-12-25 00:52:10

你在看完整地图吗?您很有可能将该点的位置设置为纬度/经度。 OpenLayers LonLat 对象如此命名只是为了欺骗像您这样的无辜用户,让他们认为它会自动转换纬度经度,或者期望它们,或者其他什么。不要相信它,重新投影到地图的投影中。

Are you looking at the full map? There's a high chance that you're setting the point's location as lat/lon. The OpenLayers LonLat object is so named only to trick innocent users like you into thinking that it automatically converts latitude longitude, or expects them, or something. Don't trust it, reproject into the projection of your map.

仙女山的月亮 2024-12-25 00:52:10

我认为收集是必要的,但看起来你有纬度和纬度隆交换了。一个点必须有 lon,然后有 lat。

feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Collection([new OpenLayers.Geometry.Point(0, 0)]), {});
vectors.addFeatures([feature]);

I thought Collection were necessary, but looks like you have lat & lon swapped. A point must have lon, then lat.

feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Collection([new OpenLayers.Geometry.Point(0, 0)]), {});
vectors.addFeatures([feature]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文