• openlayersMarkers



    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);

    }

  • 相关阅读:
    java工具类4-分布式id生成器
    java工具类3-签名加密
    java工具类2-获取文件base64
    Java SE入门(十)——继承与抽象
    Java SE入门(九)——静态和代码块
    Java SE入门(八)——IO流基础
    Java SE入门(七)——Java集合与实例
    Java SE入门(六)——常用基础API
    Java SE入门(五)——面向对象基础
    Java SE入门(四)——函数与方法
  • 原文地址:https://www.cnblogs.com/ruoshui/p/openlayers.html
Copyright © 2020-2023  润新知