Add working code for Markers -- marker layer and marker object. Also add markers.html to demo use of markers functionality.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@107 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -3,25 +3,35 @@ OpenLayers.Layer.Marker.prototype =
|
||||
Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
// markers: store internal marker list
|
||||
markers:null,
|
||||
markers: [],
|
||||
|
||||
initialize: function(name) {
|
||||
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
// Implement this. It may not need to do anything usually.
|
||||
moveTo:function(bounds,zoomChanged) {
|
||||
|
||||
moveTo: function(bounds,zoomChanged) {
|
||||
if (zoomChanged) {
|
||||
this.div.innerHTML="";
|
||||
for(i=0; i < this.markers.length; i++) {
|
||||
this.drawMarker(this.markers[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
addMarker:function(marker) {
|
||||
addMarker: function(marker) {
|
||||
this.markers.append(marker);
|
||||
if (this.map && this.map.getExtent()) {
|
||||
this.drawMarker(marker);
|
||||
}
|
||||
},
|
||||
drawMarker: function(marker) {
|
||||
var resolution = this.map.getResolution();
|
||||
var extent = this.map.getExtent();
|
||||
var pixel = new OpenLayers.Pixel(
|
||||
resolution * (this.lonlat.lon - extent.minlon),
|
||||
resolution * (extent.maxlat - this.lonlat.lat)
|
||||
1/resolution * (marker.lonlat.lon - extent.minlon),
|
||||
1/resolution * (extent.maxlat - marker.lonlat.lat)
|
||||
);
|
||||
var m = marker.generateMarker(pixel);
|
||||
this.div.appendChild(m);
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
@@ -28,8 +28,15 @@ OpenLayers.Marker.prototype = {
|
||||
this.lonlat = lonlat;
|
||||
},
|
||||
generateMarker: function(pixel) {
|
||||
var markerObject;
|
||||
// Create a div here, and set the location to the pixel above
|
||||
// Create a div here, and set the location to the pixel above modified
|
||||
// by the icon size.
|
||||
var markerObject = OpenLayers.Util.createImage(
|
||||
this.icon.url,
|
||||
this.icon.size,
|
||||
new OpenLayers.Pixel(
|
||||
pixel.x-(this.icon.size.w/2),
|
||||
pixel.y-this.icon.size.h)
|
||||
);
|
||||
return markerObject;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user