当前位置: 代码迷 >> Web前端 >> marker展示(openlayers+google)
  详细解决方案

marker展示(openlayers+google)

热度:380   发布时间:2012-08-07 14:54:48.0
marker显示(openlayers+google)
function initMap(type) {
var lon = centerPoint.split(',')[0];
var lat = centerPoint.split(',')[1];
var point = new OpenLayers.LonLat(lon,lat)
.transform(new OpenLayers.Projection("EPSG:4326"),
new OpenLayers.Projection("EPSG:900913"));
map = new OpenLayers.Map('map');
    var gmap = new OpenLayers.Layer.Google("街道地形",{numZoomLevels: 20,visibility: false});
    var gphy = new OpenLayers.Layer.Google("自然地形",{type: google.maps.MapTypeId.TERRAIN});
    var ghyb = new OpenLayers.Layer.Google("混合图层",{type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20});
    var gsat = new OpenLayers.Layer.Google("卫星图层",{type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22});
    map.addLayers([gmap, gphy, ghyb, gsat]);
    map.setCenter(point, zoom);
    map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition({element:$('location')}));
  map.addControl(new OpenLayers.Control.PanZoomBar());
  map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
  map.addControl(new OpenLayers.Control.PanZoom());
  if(type=='manager'){
  map.div.oncontextmenu=function(){return false;}
    map.events.register("contextmenu", null, addMarker);
}
markers=new OpenLayers.Layer.Markers("标注");
    map.addLayer(markers);
}


function initMarker(point,n,type){
    var size=new OpenLayers.Size(20,30); 
    var calculateOffset=function(size){return new OpenLayers.Pixel(-(size.w/2),-size.h);}; 
    var icon=new OpenLayers.Icon(url,size,null,calculateOffset);
    marker=new OpenLayers.Marker(point,icon);
    var feature=new OpenLayers.Feature(markers,point);
    feature.popupClass=OpenLayers.Class(OpenLayers.Popup.AnchoredBubble,{autoSize:true});
    var markerMove=function (e) {
    feature.data.popupContentHTML="testMarkerMove"; 
    feature.data.overflow="auto";
    popup=feature.createPopup(false);
    map.addPopup(popup);
    OpenLayers.Event.stop(e);
    }
    var markerClick=function(e){
    var feature2=new OpenLayers.Feature(markers,point);feature2.popupClass=OpenLayers.Class(OpenLayers.Popup.AnchoredBubble,{autoSize:true});
    feature2.data.popupContentHTML="testMarkerClick"; 
    feature2.data.overflow="auto";
    popup2=feature2.createPopup(true);
    map.addPopup(popup2);
    map.removePopup(popup);
    OpenLayers.Event.stop(e);
    };
    marker.events.register("mousemove", feature, markerMove);
    marker.events.register("mouseout", feature, function markerOut(){map.removePopup(popup);});
    marker.events.register("mousedown", null, markerClick);
    markers.addMarker(marker);
}
  相关解决方案