关于OpenLayers加载本地切片的问题

1.不能够正常添加标记到地图上,当使用GOOGLE地图时

原因: 添加标记的时候需要加上中扩号-> map.addLayers([markers]);
var lon = 107.5781;
var lat = 36.8796;
var zoom = 2;
var map, layer,gmap,markers;
var objMouse;

var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
maxResolution: 156543.0339,
numZoomLevels: 10,
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
20037508.34, 20037508.34)
};

map = new OpenLayers.Map('map',options);
createPopup();
function createPopup()
{
markers = new OpenLayers.Layer.Markers( "Markers" );

markers.addMarker(GetMark(lon,lat));
markers.events.register('click', markers, function(){
popup = new OpenLayers.Popup("chicken",
new OpenLayers.LonLat(lon,lat),
new OpenLayers.Size(20,20),
"haha!!!",
true);
popup.autoSize=true;
map.addPopup(popup);
});
map.addLayers([markers]);
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);

}
function GetMark(lo,lat)
{
var size = new OpenLayers.Size(70,30);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://www.k1982.com/png/up/200905/20090513082309637.png',size,offset);
return new OpenLayers.Marker(new OpenLayers.LonLat(lon,lat),icon)
}

2.用Google的地图,添加标记时候用的经纬不能准确定位标记

像素值与实际经纬度值的互转

map.events.register('click',gmap,function(ev){
var lonLat=map.getLonLatFromPixel(ev.xy);
if (map.displayProjection) {
//将像素值转换成经纬度
lonLat.transform(map.getProjectionObject(),map.displayProjection );
//将经纬度转换成像素值
lonLat.transform(map.displayProjection,map.getProjectionObject());
}      
3.用经纬度来为地图添加标记

var laolat_v=new OpenLayers.LonLat(lo,la);
if (map.displayProjection) {
laolat_v.transform(map.displayProjection,map.getProjectionObject());
}
markers = new OpenLayers.Layer.Markers( "Markers" );
markers.addMarker(GetMark(laolat_v));
markers.events.register('click', markers, function(){
popup = new OpenLayers.Popup("chicken",
laolat_v,
new OpenLayers.Size(20,20),
"haha!!!",
true);
popup.autoSize=true;
map.addPopup(popup);
});
map.addLayers([markers]);


}
function GetMark(laolat_v)
{
var size = new OpenLayers.Size(70,30);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://www.k1982.com/png/up/200905/20090513082309637.png',size,offset);
var mk=new OpenLayers.Marker(laolat_v,icon)
//mk.visible=false;
return mk;
}

 

4、以对图片载入错误时图片框的颜色和图片框中默认的图片进行自定义

由OpenLayers.Util类控制,具体修改openlayers/theme/default/style.css 中

.olImageLoadError {
     background-color: pink;
    opacity: 0.5;
    filter: alpha(opacity=0); /* IE */
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值