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

    }

  • 相关阅读:
    【小程序】---- 使用 Echarts 的方式
    【小程序】---- 使用 Vant 的方式
    WebSocket协议 与 IO多路复用
    python 实现发送邮件功能
    记一次Hadoop安装部署过程
    docker容器中布置静态网站
    [DL]面向稀有事件的 Logistic Regression 模型校准
    [Statistic] 置信度
    Leetcode1137. 第 N 个泰波那契数
    Leetcode1394. 找出数组中的幸运数
  • 原文地址:https://www.cnblogs.com/ruoshui/p/openlayers.html
Copyright © 2020-2023  润新知