Fill out more of Icon and Marker classes. In the XP world, supposedly we test first -- and I actually did in this case. Kind of a nifty trick: you work out what the function is supposed to do solely from the tests you want to write, and then you go and actually write the code that does it.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@87 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-05-17 12:16:23 +00:00
parent 605ba7a066
commit 66edc6dcb7
5 changed files with 80 additions and 5 deletions

View File

@@ -7,7 +7,8 @@ OpenLayers.Icon.prototype = {
// {OpenLayers.Size}: size of image
size:null,
initialize: function() {
initialize: function(url, size) {
this.size = size;
this.url = url;
}
}

View File

@@ -6,8 +6,35 @@ OpenLayers.Marker.prototype = {
// latlon: {OpenLayers.LatLon} location of object
latlon: null,
// events
events: null,
// map
map: null,
initialize: function(icon, latlon) {
this.icon = icon;
this.latlon = latlon;
},
initialize: function() {
}
draw: function() {
var resolution = this.map.getResolution();
var extent = this.map.getExtent();
if (this.latlon.lat > extent.minlat &&
this.latlon.lat < extent.maxlat &&
this.lonlon.lon > extent.minlon &&
this.lonlon.lon < extent.maxlon) {
var pixel = new OpenLayers.Pixel(
resolution * (this.latlon.lon - extent.minlon),
resolution * (extent.maxlat - this.latlon.lat)
);
// need to account for how much layer has moved...
/* Psuedocode:
div = map.markersDiv;
marker = OpenLayers.Util.createDiv('marker'+rand(), pixel, this.icon.size, null, this.icon.url);
div.appendChild(marker);
*/
}
}
}

View File

@@ -1,6 +1,8 @@
<ul id="testlist">
<li>test_LatLon.html</li>
<li>test_Pixel.html</li>
<li>test_Icon.html</li>
<li>test_Marker.html</li>
<li>test_Bounds.html</li>
<li>test_Events.html</li>
<li>test_Layer.html</li>

22
tests/test_Icon.html Normal file
View File

@@ -0,0 +1,22 @@
<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var icon;
function test_01_Icon_constructor (t) {
t.plan( 5 );
icon = new OpenLayers.Icon("",new OpenLayers.Size(5,6));
t.ok( icon instanceof OpenLayers.Icon, "new OpenLayers.Icon returns Icon object" );
t.ok( icon.size instanceof OpenLayers.Size, "icon.size returns Size object" );
t.eq( icon.size.w, 5, "icon.size.w returns correct value" );
t.eq( icon.size.h, 6, "icon.size.w returns correct value" );
t.eq( icon.url, "", "icon.url returns str object" );
}
// -->
</script>
</head>
<body>
</body>
</html>

23
tests/test_Marker.html Normal file
View File

@@ -0,0 +1,23 @@
<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var marker;
function test_01_Marker_constructor (t) {
t.plan( 5 );
marker = new OpenLayers.Marker(new OpenLayers.Icon(),new OpenLayers.LatLon(1,2));
t.ok( marker instanceof OpenLayers.Marker, "new OpenLayers.Marker returns Marker object" );
t.ok( marker.icon instanceof OpenLayers.Icon, "new marker.Icon returns Icon object" );
t.ok( marker.latlon instanceof OpenLayers.LatLon, "new marker.latlon returns LatLon object" );
t.eq( marker.latlon.lat, 1, "marker.latlon.lat returns correct lat" );
t.eq( marker.latlon.lon, 2, "marker.latlon.lon returns correct lon" );
}
// -->
</script>
</head>
<body>
</body>
</html>