openlayers-Markers
来源:广州中睿信息技术有限公司官网
发布时间:2012/10/21 23:25:16 编辑:admin 阅读 325
varmapvarmyMarkersvardataSetfunctionaddMarkers(data,mapBase,markersLayer){dataSet=datamap=mapBaseif


var map;
var myMarkers;
var dataSet;

function addMarkers(data, mapBase, markersLayer) {
    dataSet = data;
    map = mapBase;

if(myMarkers ==null){

 myMarkers = new OpenLayers.Layer.Vector("车");
   map.addLayer(markers);

}
    myMarkers = markersLayer;
    add();
}

function add() {

    var size = new OpenLayers.Size(30, 30);
    var calculateOffset = function (size) {
        return new OpenLayers.Pixel(-(size.w / 2), -(size.h / 2));
    };

    //需要修改
    for (var i = 0; i < dataSet.length; i++) {

        var d = {};
        d.id = dataSet[i].VehicleID.toString();

        var num = Math.floor(dataSet[i].Direction / 5) * 5;

       var ic = "http://www.cnblogs.com/Images/Icon/bus_blue/bus_blue_45.png";
        d.icon = new OpenLayers.Icon(
                ic,
                size, null, calculateOffset);

        var lonlat = new OpenLayers.LonLat(dataSet[i].Longitude,
                                             dataSet[i].Latitude);
        var sHtml = "<div id=\"markerNews\">"
        + "车牌号:" + dataSet[i].VehicleID + "<br />"
        + "方向:" + Math.floor(dataSet[i].Direction / 5)*5 + "<br />"
        + "速度:"+dataSet[i].Speed+"<br />"
        + "驾驶员:" + dataSet[i].DriverName + "<br />"
        + "车辆类型:" + dataSet[i].VehicleModelName
        + "</div>";
        //end

        var feature = new OpenLayers.Feature(myMarkers, lonlat, d);
        feature.closeBox = true;
        feature.data.popupContentHTML = sHtml;

        var marker = feature.createMarker();
        marker.events.register('click', feature, markerClick);
        myMarkers.addMarker(marker);
    }

    //    setTimeout(add, time);
}

//不变
function markerClick(evt) {
    var p = this.createPopup(this.closeBox);
    var ll = p.lonlat;
    var sHtml = p.contentHTML;
    var popup;
    var len = map.popups.length;
    var feature = new OpenLayers.Feature(myMarkers, ll);

    for (var j = 0; j < len; j++) {
        popup = map.popups[j];
        map.removePopup(popup);

        if (popup.feature) {
            popup.feature.popup.destroy();
            popup.feature.popup = null;
            popup.feature = null;
        }
        popup = null;
    }

    popup = new OpenLayers.Popup.FramedCloud("featurePopup",
                                             ll,
                                             new OpenLayers.Size(200, 200),
                                             sHtml,
                                             null, true);
    feature.popup = popup;
    popup.feature = feature;
    map.addPopup(popup);
    OpenLayers.Event.stop(evt);

}

联系我们CONTACT 扫一扫
愿景:成为最专业的软件研发服务领航者
中睿信息技术有限公司 广州•深圳 Tel:020-38931912 务实 Pragmatic
广州:广州市天河区翰景路1号金星大厦18层中睿信息 Fax:020-38931912 专业 Professional
深圳:深圳市福田区车公庙有色金属大厦509~510 Tel:0755-25855012 诚信 Integrity
所有权声明:PMI, PMP, Project Management Professional, PMI-ACP, PMI-PBA和PMBOK是项目管理协会(Project Management Institute, Inc.)的注册标志。
版权所有:广州中睿信息技术有限公司 粤ICP备13082838号-2