Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
标记图标的OpenLayers问题_Openlayers_Openstreetmap - Fatal编程技术网

标记图标的OpenLayers问题

标记图标的OpenLayers问题,openlayers,openstreetmap,Openlayers,Openstreetmap,我正在我的网站上创建OSM地图,并使用openlayer添加一些标记。。我的问题是,我总是得到相同的标记图标 <script type="text/javascript"> var map = new OpenLayers.Map("heatMap"); var mapnik = new OpenLayers.Layer.OSM(); map.addLayer(mapnik); map.setCenter(new OpenLayers.LonLat(-4

我正在我的网站上创建OSM地图,并使用openlayer添加一些标记。。我的问题是,我总是得到相同的标记图标

 <script type="text/javascript">

 var map = new OpenLayers.Map("heatMap");
    var mapnik = new OpenLayers.Layer.OSM();
    map.addLayer(mapnik);
    map.setCenter(new OpenLayers.LonLat(-4.0575942987957,54.390175926091) // Center of the map
      .transform(
        new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
        new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
      ), 6 // Zoom level
    );

    var markers = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markers);

    var icon1 = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset);
    var icon2 = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker-gold.png', size, offset);
    var icon3 = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker-green.png', size, offset);

    var lonLat1 = new OpenLayers.LonLat(-4.0575942987957,54.390175926091).transform(
                            new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
                            map.getProjectionObject() // to Spherical Mercator Projection
                            );

    var lonLat2 = new OpenLayers.LonLat(-3.0575942987957,54.390175926091).transform(
                            new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
                            map.getProjectionObject() // to Spherical Mercator Projection
                            );

    var lonLat3 = new OpenLayers.LonLat(-5.0575942987957,54.390175926091).transform(
                            new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
                            map.getProjectionObject() // to Spherical Mercator Projection
                            );

    var marker1 = new OpenLayers.Marker(lonLat1);
    var feature = new OpenLayers.Feature(markers, lonLat);
    feature.closeBox = true;
    feature.popupClass = OpenLayers.Class(OpenLayers.Popup.AnchoredBubble, { autoSize: true });
    feature.data.popupContentHTML = '<p>Marker1<p>';
    feature.data.overflow = "hidden";

    marker1.feature = feature;

    var markerClick = function (evt) {
        if (this.popup == null) {
            this.popup = this.createPopup(this.closeBox);
            map.addPopup(this.popup);
            this.popup.show();
        } else {
            this.popup.toggle();
        }
        OpenLayers.Event.stop(evt);
    };
    marker1.events.register("mousedown", feature, markerClick);

    var marker2 = new OpenLayers.Marker(lonLat2);
    var feature = new OpenLayers.Feature(markers, lonLat);
    feature.closeBox = true;
    feature.popupClass = OpenLayers.Class(OpenLayers.Popup.AnchoredBubble, { autoSize: true });
    feature.data.popupContentHTML = '<p>Marker2<p>';
    feature.data.overflow = "hidden";

    marker2.feature = feature;

    var markerClick = function (evt) {
        if (this.popup == null) {
            this.popup = this.createPopup(this.closeBox);
            map.addPopup(this.popup);
            this.popup.show();
        } else {
            this.popup.toggle();
        }
        OpenLayers.Event.stop(evt);
    };
    marker2.events.register("mousedown", feature, markerClick);

    var marker3 = new OpenLayers.Marker(lonLat3);
    var feature = new OpenLayers.Feature(markers, lonLat);
    feature.closeBox = true;
    feature.popupClass = OpenLayers.Class(OpenLayers.Popup.AnchoredBubble, { autoSize: true });
    feature.data.popupContentHTML = '<p>Marker 3<p>';
    feature.data.overflow = "hidden";

    marker3.feature = feature;

    var markerClick = function (evt) {
        if (this.popup == null) {
            this.popup = this.createPopup(this.closeBox);
            map.addPopup(this.popup);
            this.popup.show();
        } else {
            this.popup.toggle();
        }
        OpenLayers.Event.stop(evt);
    };
    marker3.events.register("mousedown", feature, markerClick);

    markers.addMarker(marker1, icon1);

    markers.addMarker(marker2, icon2);

    markers.addMarker(marker3, icon3);

var map=新的OpenLayers.map(“热图”);
var mapnik=new OpenLayers.Layer.OSM();
map.addLayer(mapnik);
map.setCenter(新OpenLayers.LonLat(-4.0575942987957,54.390175926091)//地图中心
.变换(
新OpenLayers.Projection(“EPSG:4326”),//从WGS 1984转换而来
新OpenLayers.Projection(“EPSG:900913”)//到球形墨卡托投影
),6//缩放级别
);
var markers=新的OpenLayers.Layer.markers(“markers”);
添加图层(标记);
var icon1=新的OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png,大小,偏移量);
var icon2=新的OpenLayers.Icon('http://www.openlayers.org/dev/img/marker-gold.png,大小,偏移量);
var icon3=新的OpenLayers.Icon('http://www.openlayers.org/dev/img/marker-green.png,大小,偏移量);
var lonLat1=新的OpenLayers.LonLat(-4.0575942987957,54.390175926091)。转换(
新OpenLayers.Projection(“EPSG:4326”),//从WGS 1984转换而来
map.getProjectionObject()//到球形墨卡托投影
);
var lonLat2=新的OpenLayers.LonLat(-3.0575942987957,54.390175926091)。转换(
新OpenLayers.Projection(“EPSG:4326”),//从WGS 1984转换而来
map.getProjectionObject()//到球形墨卡托投影
);
var lonLat3=新的OpenLayers.LonLat(-5.0575942987957,54.390175926091)。转换(
新OpenLayers.Projection(“EPSG:4326”),//从WGS 1984转换而来
map.getProjectionObject()//到球形墨卡托投影
);
var marker1=新的OpenLayers.Marker(lonLat1);
var feature=新的OpenLayers.feature(标记,lonLat);
feature.closeBox=true;
feature.popupClass=OpenLayers.Class(OpenLayers.Popup.anchoredubble,{autoSize:true});
feature.data.popupContentHTML='Marker1';
feature.data.overflow=“隐藏”;
marker1.feature=特征;
var markerClick=函数(evt){
if(this.popup==null){
this.popup=this.createPopup(this.closeBox);
map.addPopup(this.popup);
this.popup.show();
}否则{
this.popup.toggle();
}
OpenLayers.Event.stop(evt);
};
marker1.events.register(“mousedown”,feature,markerClick);
var marker2=新的OpenLayers.Marker(lonLat2);
var feature=新的OpenLayers.feature(标记,lonLat);
feature.closeBox=true;
feature.popupClass=OpenLayers.Class(OpenLayers.Popup.anchoredubble,{autoSize:true});
feature.data.popupContentHTML='Marker2';
feature.data.overflow=“隐藏”;
marker2.feature=特征;
var markerClick=函数(evt){
if(this.popup==null){
this.popup=this.createPopup(this.closeBox);
map.addPopup(this.popup);
this.popup.show();
}否则{
this.popup.toggle();
}
OpenLayers.Event.stop(evt);
};
marker2.events.register(“mousedown”,feature,markerClick);
var marker3=新的OpenLayers.Marker(lonLat3);
var feature=新的OpenLayers.feature(标记,lonLat);
feature.closeBox=true;
feature.popupClass=OpenLayers.Class(OpenLayers.Popup.anchoredubble,{autoSize:true});
feature.data.popupContentHTML='标记3';
feature.data.overflow=“隐藏”;
marker3.feature=特征;
var markerClick=函数(evt){
if(this.popup==null){
this.popup=this.createPopup(this.closeBox);
map.addPopup(this.popup);
this.popup.show();
}否则{
this.popup.toggle();
}
OpenLayers.Event.stop(evt);
};
marker3.events.register(“mousedown”,feature,markerClick);
markers.addMarker(marker1,icon1);
markers.addMarker(marker2,icon2);
markers.addMarker(marker3,icon3);

现在的问题是,所有三个标记都有相同的图标。。。有人能帮我吗..

在创建标记实例后更改图标

marker = new ....
var size = new OpenLayers.Size(25, 12);
var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
marker.icon = new OpenLayers.Icon("marker.png", size, offset);
//UPDATE AGAIN
marker.icon.size = size;
marker.icon.offset = offset;
marker.draw();