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

    }

  • 相关阅读:
    【Flink系列十二】使用OpenResty 在InfluxDB协议层拦截Flink指标
    【Azkaban优化】防止IP变化导致频繁登录
    困扰多年的Quartz重复调度的问题,终于找到原因
    【Flink系列十一】FlinkSQL Gateway以及支持Kerberos多租户的实现思路
    【Flink系列十三】FlinkKafkaConnector KafkaSource FlinkKafkaConsumer没有上报指标
    IDEA项目结构出现 0% methods,0% lines covered up
    java去重 up
    svndown下来项目但是导入不了maven包,解决办法 up
    新型病毒加强勒索病毒预防 up
    java list 时间排序, up
  • 原文地址:https://www.cnblogs.com/ruoshui/p/2252411.html
Copyright © 2020-2023  润新知