[OpenLayers-Users] layer switcher and hover handler won't work
please help..
MeLv1n wAuRaN
melvinnesta at gmail.com
Tue Mar 31 21:48:44 EDT 2009
hi all,
can someone help me solve this problem? my layer switcher and hover handler
won't work, I don't know why.
Below is my code:
<html xmlns="http://www.9media.co.nr">
<head>
<title>Minahasa Utara</title>
<link rel="stylesheet" href="
http://localhost/openlayers/theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
<style type="text/css">
#map {
width: 100%;
height: 100%;
border: 1px solid black;
}
#controlToggle li {
list-style: none;
}
textarea.output {
text-align: left;
font-size: 12em;
overflow: auto;
}
</style>
<script src="http://localhost/openlayers/lib/Firebug/firebug.js
"></script>
<script src="http://localhost/openlayers/lib/OpenLayers.js"></script>
<script defer="defer" script type="text/javascript">
//Hover
OpenLayers.Control.Hover = OpenLayers.Class(OpenLayers.Control,
{
defaultHandlerOptions: {
'delay': 400,
'pixelTolerance': null,
'stopMove': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Hover(
this,
{'pause': this.onPause, 'move': this.onMove},
this.handlerOptions
);
},
onPause: function(evt) {
var output = document.getElementById(this.key +
'Output');
var msg = 'pause ' + evt.xy;
output.value = output.value + msg + "\r\n";
},
});
//Map
//var lon = 5;
//var lat = 5;
//var zoom = 5;
var map, controls, drawControls, layer_desa, layer_jalan, layer_atm,
layer_bank, layer_polisi, layer_rs, layer_term, layer_uni, layer_ow,
layer_htl;
function init(){
var options = {
projection: "EPSG:4326",
units: "m",
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(659950, 140743,
776058, 210476)
};
map = new OpenLayers.Map('map', options);
layer_desa = new OpenLayers.Layer.WMS( "Desa",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'desa',
transparent: "false", format: "image/png"},
{singleTile: true},
{isBaseLayer: true});
layer_jalan = new OpenLayers.Layer.WMS( "Jalan",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'jalan',
transparent: "true", format: "image/png"},
{singleTile: true});
layer_atm = new OpenLayers.Layer.WMS( "ATM",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'atm',
transparent: "true", format: "image/png"},
{singleTile: true});
layer_bank = new OpenLayers.Layer.WMS( "Bank",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'bank',
transparent: "true", format: "image/png"},
{singleTile: true});
layer_polisi = new OpenLayers.Layer.WMS( "Polisi",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'polisi',
transparent: "true", format: "image/png"},
{singleTile: true});
layer_rs = new OpenLayers.Layer.WMS( "Rumah Sakit",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'rumah sakit',
transparent: "true", format: "image/png"},
{singleTile: true});
layer_term = new OpenLayers.Layer.WMS( "Terminal",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'terminal',
transparent: "true", format: "image/png"},
{singleTile: true});
layer_uni = new OpenLayers.Layer.WMS( "Universitas",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'universitas',
transparent: "true", format: "image/png"},
{singleTile: true});
layer_ow = new OpenLayers.Layer.WMS( "Objek Wisata",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'objek wisata',
transparent: "true", format: "image/png"},
{singleTile: true});
layer_htl = new OpenLayers.Layer.WMS( "Hotel",
"
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Skripsi/coba.map",
{layers: 'hotel',
transparent: "true", format: "image/png"},
{singleTile: true});
map.addLayer(layer_desa);
map.addLayer(layer_jalan);
map.addLayer(layer_atm);
map.addLayer(layer_bank);
map.addLayer(layer_polisi);
map.addLayer(layer_rs);
map.addLayer(layer_term);
map.addLayer(layer_uni);
map.addLayer(layer_ow);
map.addLayer(layer_htl);
controls = {
'short': new OpenLayers.Control.Hover({
handlerOptions: {
'delay': 100
}
}),
};
var props = document.getElementById("props");
var control;
for(var key in controls) {
control = controls[key];
control.key = key;
map.addControl(control);
}
// map controls
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.ScaleLine());
map.addControl(new OpenLayers.Control.PanZoomBar());
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
map.zoomToMaxExtent();
//get layer details on click
map.events.register('click', map, function (e) {
OpenLayers.Util.getElement('nodeList').innerHTML = "Detail:
Loading...";
var url = layer_desa.getFullRequestString({
REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.se_xml",
BBOX: layer_desa.map.getExtent().toBBOX(),
X: e.xy.x,
Y: e.xy.y,
INFO_FORMAT: 'text/html',
QUERY_LAYERS: layer_desa.params.LAYERS,
WIDTH: layer_desa.map.size.w,
HEIGHT: layer_desa.map.size.h});
OpenLayers.loadURL(url, '', this, setHTML);
OpenLayers.Event.stop(e);
});
drawControls = {
selecthover: new OpenLayers.Control.SelectFeature(
layer_desa,
{
multiple: false, hover: true,
toggleKey: "ctrlKey",
multipleKey: "shiftKey"
}
)
};
}
function toggle(key) {
var control = controls[key];
if(control.active) {
control.deactivate();
} else {
control.activate();
}
var status = document.getElementById(key + "Status");
status.innerHTML = control.active ? "on" : "off";
var output = document.getElementById(key + "Output");
output.value = "on";
}
function setHTML(response) {
OpenLayers.Util.getElement('nodeList').innerHTML =
response.responseText;
}
</script>
</head>
<body onload="init()">
<div id="map" class="smallmap"></div>
<div id="nodeList">Detail: </div>
</body>
</html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090401/7e4dfff1/attachment.html
More information about the Users
mailing list