zoukankan      html  css  js  c++  java
  • openlayers之矢量加载标记点

        var style = new OpenLayers.Style(
            {
                graphicWidth: 30,
                graphicHeight: 30,
                //graphicYOffset: -35,
                label: "${name}",
                fontSize: "9pt",
                fontWeight: "bold",
                labelYOffset: "-20"

            },
            {
                rules: [
                    new OpenLayers.Rule({

                        elseFilter: true,
                        symbolizer: {
                            externalGraphic: "${img}"
                        }
                    })
                ]
            }
        );

      var  vector = new OpenLayers.Layer.Vector(vectorName, {
            styleMap: new OpenLayers.StyleMap(style)
        });
        map.addLayer(vector);


        //需要修改
        var features = new Array(400);

     var ic = "Images/Icon/car_yellow_0.png";

        for (var i = 0; i < 400; i++) {
                    var sHtml = "<tr><td valign=\"top\">test</td><td valign=\"top\">" + i.toString() + "</td></tr>";
                    px = Math.random() * (122 - 121 + 0.001) + 121;
                    py = Math.random() * (30 - 29 + 0.001) + 29;

         var name="test"+i.toString();
                    var ll = tranformTo900913(px, py);

            features[i] = new OpenLayers.Feature.Vector(
                new OpenLayers.Geometry.Point(
                    lonlat.lon, lonlat.lat
                ), {
                    name: name,
                    img: ic,
                    html: sHtml

                }
            );

        } 

        selectControl = new OpenLayers.Control.SelectFeature(vector);  //添加点击标记事件
        map.addControl(selectControl);
        selectControl.activate();

        vector.events.on({   //画popup窗
            featureselected: function (e) {
                feature = e.feature;
                popup = new OpenLayers.Popup.FramedCloud("featurePopup",
                                             feature.geometry.getBounds().getCenterLonLat(),
                                             new OpenLayers.Size(300, 300),
                                             feature.attributes.html,
                                             null, true, function (e) {

                                                 selectControl.unselect(this.feature);
                                             });
                feature.popup = popup;
                popup.feature = feature;
                map.addPopup(popup);
            },
            featureunselected: function (e) {
                feature = e.feature;
                if (feature.popup) {
                    popup.feature = null;
                    map.removePopup(feature.popup);
                    feature.popup.destroy();
                    feature.popup = null;
                }
            }
        });


        vector.addFeatures(features);

    }

  • 相关阅读:
    python转换emoji字符串
    python位运算符详细介绍
    python制作动态排序图
    docker安装mysql
    yum安装centos-7版nginx
    pysimplegui模块实现倒计时UI框
    pysimplegui模块实现进度条
    python枚举的应用enum
    第0-0课
    SV -- Array 数组
  • 原文地址:https://www.cnblogs.com/ruoshui/p/2252411.html
Copyright © 2011-2022 走看看