[英]OpenStreetMap point not showing on map with open layers
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);
}
我想念什么嗎?
您在看完整的地圖嗎? 您很有可能將點的位置設置為緯度/經度。 OpenLayers LonLat對象的命名僅是為了欺騙像您這樣的無辜用戶,使他們認為它會自動轉換緯度經度,或期望它們或類似的東西。 不信任它,重新投影到地圖的投影中。
我以為Collection是必需的,但看起來您已將lat&lon換了。 點必須有lon,然后是lat。
feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Collection([new OpenLayers.Geometry.Point(0, 0)]), {});
vectors.addFeatures([feature]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.