Add support to Permalink control to automatically create Permalink inside map div if no element is given. This isn't pretty, but it's a good way to quickly/easily add a permalink to your map.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@847 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -34,8 +34,8 @@
|
|||||||
map.addControl(new OpenLayers.Control.PanZoomBar());
|
map.addControl(new OpenLayers.Control.PanZoomBar());
|
||||||
map.addControl(new OpenLayers.Control.MouseToolbar());
|
map.addControl(new OpenLayers.Control.MouseToolbar());
|
||||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||||
|
map.addControl(new OpenLayers.Control.Permalink());
|
||||||
map.addControl(new OpenLayers.Control.Permalink($('permalink')));
|
map.addControl(new OpenLayers.Control.Permalink($('permalink')));
|
||||||
// map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
|
||||||
if (!map.getCenter()) map.zoomToMaxExtent();
|
if (!map.getCenter()) map.zoomToMaxExtent();
|
||||||
}
|
}
|
||||||
// -->
|
// -->
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body onload="init()">
|
<body onload="init()">
|
||||||
<h1>OpenLayers Example</h1>
|
<h1>OpenLayers Example</h1>
|
||||||
<a href="" id="permalink">Permalink</a><br />
|
<a style="float:right" href="" id="permalink">Permalink</a>
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ OpenLayers.Control.Permalink.prototype =
|
|||||||
},
|
},
|
||||||
|
|
||||||
draw: function() {
|
draw: function() {
|
||||||
this.map.events.register( 'moveend', this, this.updateLink);
|
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
||||||
var args = this.getArgs();
|
var args = this.getArgs();
|
||||||
if (args.lat && args.lon) {
|
if (args.lat && args.lon) {
|
||||||
this.map.setCenter(
|
this.map.setCenter(
|
||||||
@@ -27,6 +27,21 @@ OpenLayers.Control.Permalink.prototype =
|
|||||||
if (args.zoom) {
|
if (args.zoom) {
|
||||||
this.map.zoomTo(parseInt(args.zoom));
|
this.map.zoomTo(parseInt(args.zoom));
|
||||||
}
|
}
|
||||||
|
if (!this.element) {
|
||||||
|
this.element = document.createElement("a");
|
||||||
|
this.div.style.right = "3px";
|
||||||
|
this.div.style.bottom = "3px";
|
||||||
|
this.div.style.left = "";
|
||||||
|
this.div.style.top = "";
|
||||||
|
this.div.style.display = "block";
|
||||||
|
this.div.style.position = "absolute";
|
||||||
|
this.element.style.fontSize="smaller";
|
||||||
|
this.element.innerHTML = "Permalink";
|
||||||
|
this.element.href="";
|
||||||
|
this.div.appendChild(this.element);
|
||||||
|
}
|
||||||
|
this.map.events.register( 'moveend', this, this.updateLink);
|
||||||
|
return this.div;
|
||||||
},
|
},
|
||||||
|
|
||||||
getArgs: function() {
|
getArgs: function() {
|
||||||
|
|||||||
@@ -36,6 +36,14 @@
|
|||||||
$('edit_permalink').href = './edit.html?lat=0&lon=1.75781&zoom=2';
|
$('edit_permalink').href = './edit.html?lat=0&lon=1.75781&zoom=2';
|
||||||
t.eq($('permalink').href, $('edit_permalink').href, "Panning sets permalink with base");
|
t.eq($('permalink').href, $('edit_permalink').href, "Panning sets permalink with base");
|
||||||
}
|
}
|
||||||
|
function test_03_Control_Permalink_noElement (t) {
|
||||||
|
t.plan( 2 );
|
||||||
|
control = new OpenLayers.Control.Permalink( );
|
||||||
|
t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
|
||||||
|
map = new OpenLayers.Map($('map'));
|
||||||
|
map.addControl(control);
|
||||||
|
t.eq(map.controls[2].div.firstChild.nodeName, "A", "Permalink control creates div with 'a' inside." );
|
||||||
|
}
|
||||||
// -->
|
// -->
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user