[8292] | 1 | <html>
|
---|
[8280] | 2 | <head>
|
---|
[8283] | 3 | <title>Wireless Leiden Nodemap using OpenLayers.org and OpenSteetmap.org</title>
|
---|
[8280] | 4 | <style type="text/css">
|
---|
| 5 | html, body, #basicMap {
|
---|
| 6 | width: 100%;
|
---|
| 7 | height: 100%;
|
---|
| 8 | margin: 0;
|
---|
| 9 | }
|
---|
| 10 | </style>
|
---|
[8291] | 11 | <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAKRiFs2kXKhTkKZkE_ms9rhTdBXm62xfhQU7Dk6ZBFSzYdmSteRQWjLqZhwX8afHvGpd4N3iKql6w8g" type="text/javascript"></script>
|
---|
[8282] | 12 |
|
---|
[8453] | 13 | <script src="../lib/Firebug/firebug.js"></script>
|
---|
| 14 | <script src="http://openlayers.org/dev/OpenLayers.js"</script>
|
---|
[8283] | 15 |
|
---|
[8280] | 16 | <script>
|
---|
[8304] | 17 | var url_pal3 = "http://maps.google.com/mapfiles/kml/pal3/";
|
---|
| 18 | var map, rulerControl, clickControl;
|
---|
[8303] | 19 | var mapnik, wms;
|
---|
[8283] | 20 | var projection_wgs = new OpenLayers.Projection("EPSG:4326"); // WGS 1984
|
---|
| 21 | var projection_smp = new OpenLayers.Projection("EPSG:900913"); // Spherical Mercator Projection
|
---|
| 22 |
|
---|
[8303] | 23 | var current_opacity = 0.5;
|
---|
| 24 | var max_opacity = 0.9;
|
---|
| 25 | var min_opacity = 0.1;
|
---|
| 26 |
|
---|
[8304] | 27 | OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
|
---|
| 28 | defaultHandlerOptions: {
|
---|
| 29 | 'single': true,
|
---|
| 30 | 'double': false,
|
---|
| 31 | 'pixelTolerance': 0,
|
---|
| 32 | 'stopSingle': false,
|
---|
| 33 | 'stopDouble': false
|
---|
| 34 | },
|
---|
[8303] | 35 |
|
---|
[8304] | 36 | initialize: function(options) {
|
---|
| 37 | this.handlerOptions = OpenLayers.Util.extend(
|
---|
| 38 | {}, this.defaultHandlerOptions
|
---|
| 39 | );
|
---|
| 40 | OpenLayers.Control.prototype.initialize.apply(
|
---|
| 41 | this, arguments
|
---|
| 42 | );
|
---|
| 43 | this.handler = new OpenLayers.Handler.Click(
|
---|
| 44 | this, {
|
---|
| 45 | 'click': this.trigger
|
---|
| 46 | }, this.handlerOptions
|
---|
| 47 | );
|
---|
| 48 | },
|
---|
| 49 |
|
---|
| 50 | trigger: function(e) {
|
---|
| 51 | var lonlat = map.getLonLatFromViewPortPx(e.xy);
|
---|
| 52 | lonlat = lonlat.transform( projection_smp, projection_wgs);
|
---|
| 53 | var url = coordConvert(lonlat.lon, lonlat.lat);
|
---|
| 54 | alert("You clicked near " + lonlat.lon + " N, " +
|
---|
| 55 | + lonlat.lat + " E\n\n" +
|
---|
| 56 | 'Copy/paste URL in NEW browser window to get your RDNAP coordinates\n\n' + url);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | });
|
---|
| 60 |
|
---|
| 61 |
|
---|
[8303] | 62 | function setOpacity(new_opacity) {
|
---|
| 63 | current_opacity = new_opacity;
|
---|
| 64 | mapnik.setOpacity(new_opacity);
|
---|
| 65 | wms.setOpacity(new_opacity);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | function changeOpacity(by_opacity) {
|
---|
| 69 | var new_opacity = current_opacity + by_opacity;
|
---|
| 70 | new_opacity = Math.min(max_opacity, Math.max(min_opacity, new_opacity));
|
---|
| 71 | setOpacity(new_opacity);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[8280] | 74 | function init() {
|
---|
| 75 | map = new OpenLayers.Map("basicMap");
|
---|
| 76 |
|
---|
[8283] | 77 | var world_bound = new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34);
|
---|
[8303] | 78 | // Development focus maps
|
---|
| 79 | mapnik = new OpenLayers.Layer.OSM("OpenStreetMap");
|
---|
| 80 | wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
---|
| 81 | "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
|
---|
| 82 |
|
---|
| 83 | // Added extra's
|
---|
[8283] | 84 | var google_sat = new OpenLayers.Layer.Google("Google Satellite" ,
|
---|
| 85 | { type: G_SATELLITE_MAP,
|
---|
| 86 | sphericalMercator: true,
|
---|
| 87 | maxExtent: world_bound,
|
---|
[8303] | 88 | wrapDateLine: false,
|
---|
| 89 | });
|
---|
[8283] | 90 | var google_normal = new OpenLayers.Layer.Google("Google Normal" ,
|
---|
| 91 | { type: G_NORMAL_MAP,
|
---|
| 92 | sphericalMercator: true,
|
---|
| 93 | maxExtent: world_bound,
|
---|
[8303] | 94 | wrapDateLine: false
|
---|
| 95 | });
|
---|
[8283] | 96 |
|
---|
[8303] | 97 |
|
---|
| 98 | map.addLayers([mapnik, wms, google_sat, google_normal]);
|
---|
| 99 | setOpacity(0.5);
|
---|
[8283] | 100 | defaultFocus();
|
---|
| 101 |
|
---|
| 102 |
|
---|
[8282] | 103 | //var pois = new OpenLayers.Layer.Text( "My Points",
|
---|
| 104 | // { location:"./textfile.txt",
|
---|
| 105 | // projection: map.displayProjection
|
---|
| 106 | // });
|
---|
| 107 | //map.addLayer(pois);
|
---|
[8280] | 108 |
|
---|
[8283] | 109 | //function parseKML(req) {
|
---|
| 110 | // alert(req.responseText);
|
---|
| 111 | //};
|
---|
| 112 | //alert(OpenLayers.loadURL("./kmlfile.kml", "", null, parseKML));
|
---|
| 113 |
|
---|
[8453] | 114 | function ignoreInterlink(cluster, feature) {
|
---|
| 115 | if (feature.attributes.name.indexOf('Interlink') != -1) {
|
---|
| 116 | return(false);
|
---|
| 117 | } else {
|
---|
| 118 | return strategy.shouldClusterOrig(cluster, feature); }
|
---|
| 119 | };
|
---|
| 120 |
|
---|
[8447] | 121 | strategy = new OpenLayers.Strategy.Cluster();
|
---|
[8453] | 122 | strategy.shouldClusterOrig = strategy.shouldCluster;
|
---|
| 123 | strategy.shouldCluster = ignoreInterlink;
|
---|
| 124 | strategy.distance = 10;
|
---|
| 125 | strategy.threshold = 2;
|
---|
[8447] | 126 |
|
---|
[8453] | 127 | var symbolizer = OpenLayers.Util.applyDefaults(
|
---|
| 128 | {externalGraphic: "http://www.google.com/mapfiles/kml/paddle/grn-stars-lv.png", pointRadius: 8, fillOpacity: 1},
|
---|
| 129 | OpenLayers.Feature.Vector.style["default"]);
|
---|
| 130 | var styleMap = new OpenLayers.StyleMap({"default": symbolizer, "select": {pointRadius: 16,fillOpacity: 1}});
|
---|
| 131 |
|
---|
[8307] | 132 | // Hack to get around all kind of caching fails
|
---|
| 133 | var epoch = new Date().getTime();
|
---|
| 134 | var kml = new OpenLayers.Layer.GML("KML", "./kmlfile.kml?time=" + epoch,
|
---|
[8447] | 135 | { strategies: [strategy],
|
---|
[8453] | 136 | styleMap: styleMap,
|
---|
[8447] | 137 | format: OpenLayers.Format.KML,
|
---|
[8282] | 138 | formatOptions: {
|
---|
| 139 | extractStyles: true,
|
---|
| 140 | extractAttributes: true,
|
---|
[8285] | 141 | maxDepth: 5
|
---|
[8282] | 142 | }
|
---|
| 143 | });
|
---|
| 144 | map.addLayer(kml);
|
---|
[8280] | 145 |
|
---|
[8285] | 146 | select = new OpenLayers.Control.SelectFeature(kml);
|
---|
| 147 | kml.events.on( {
|
---|
| 148 | "featureselected": onKMLFeatureSelect,
|
---|
| 149 | "featureunselected": onKMLFeatureUnselect
|
---|
| 150 | });
|
---|
| 151 | map.addControl(select);
|
---|
| 152 | select.activate();
|
---|
[8280] | 153 |
|
---|
[8304] | 154 | clickControl = new OpenLayers.Control.Click();
|
---|
| 155 | map.addControl(clickControl);
|
---|
| 156 | clickControl.deactivate();
|
---|
| 157 |
|
---|
| 158 |
|
---|
[8283] | 159 | var vectors = new OpenLayers.Layer.Vector("Vector Layer")
|
---|
| 160 | map.addLayer(vectors);
|
---|
| 161 | map.addControl(new OpenLayers.Control.MousePosition({ 'displayProjection' : projection_wgs }));
|
---|
| 162 | map.addControl(new OpenLayers.Control.EditingToolbar(vectors));
|
---|
| 163 | map.addControl(new OpenLayers.Control.LayerSwitcher());
|
---|
| 164 | map.addControl(new OpenLayers.Control.OverviewMap());
|
---|
| 165 | map.addControl(new OpenLayers.Control.Permalink());
|
---|
| 166 | map.addControl(new OpenLayers.Control.ScaleLine());
|
---|
| 167 | map.addControl(new OpenLayers.Control.KeyboardDefaults());
|
---|
[8285] | 168 | map.addControl(new OpenLayers.Control.ZoomBox());
|
---|
[8280] | 169 |
|
---|
[8304] | 170 |
|
---|
[8282] | 171 | //var in_options = {
|
---|
| 172 | // 'internalProjection': map.baseLayer.projection,
|
---|
| 173 | // 'externalProjection': new OpenLayers.Projection("EPSG:4326")
|
---|
| 174 | //};
|
---|
| 175 | //var wkt = new OpenLayers.Format.WKT(in_options);
|
---|
| 176 | //var txtFile = new XMLHttpRequest();
|
---|
| 177 | //txtFile.open("GET", "./wktfile.txt", false);
|
---|
| 178 | //// txtFile.onreadystatechange = function() {
|
---|
| 179 | //// if(txtFile.readyState == 4) {
|
---|
| 180 | //// alert(txtFile.responseText);
|
---|
| 181 | //// }
|
---|
| 182 | //// }
|
---|
| 183 | //txtFile.send(null);
|
---|
| 184 |
|
---|
| 185 | //var features = wkt.read(txtFile.responseText.replace(/\n/g,''));
|
---|
| 186 | //var bounds;
|
---|
| 187 | //
|
---|
| 188 | //if (features) {
|
---|
| 189 | // if(features.constructor != Array) {
|
---|
| 190 | // features = [features];
|
---|
| 191 | // }
|
---|
| 192 | // for(var i=0; i<features.length; ++i) {
|
---|
| 193 | // if (!bounds) {
|
---|
| 194 | // bounds = features[i].geometry.getBounds();
|
---|
| 195 | // }
|
---|
| 196 | // bounds.extend(features[i].geometry.getBounds());
|
---|
| 197 | // }
|
---|
| 198 | // vectors.addFeatures(features);
|
---|
| 199 | // map.zoomToExtent(bounds);
|
---|
| 200 | //} else {
|
---|
| 201 | // alert("ERROR in WTK");
|
---|
| 202 | //}
|
---|
| 203 |
|
---|
[8283] | 204 |
|
---|
| 205 | // style the sketch fancy
|
---|
| 206 | var sketchSymbolizers = {
|
---|
| 207 | "Point": {
|
---|
| 208 | pointRadius: 4,
|
---|
| 209 | graphicName: "square",
|
---|
| 210 | fillColor: "white",
|
---|
| 211 | fillOpacity: 1,
|
---|
| 212 | strokeWidth: 1,
|
---|
| 213 | strokeOpacity: 1,
|
---|
| 214 | strokeColor: "#333333"
|
---|
| 215 | },
|
---|
| 216 | "Line": {
|
---|
| 217 | strokeWidth: 3,
|
---|
| 218 | strokeOpacity: 1,
|
---|
| 219 | strokeColor: "#666666",
|
---|
| 220 | strokeDashstyle: "dash"
|
---|
| 221 | },
|
---|
| 222 | "Polygon": {
|
---|
| 223 | strokeWidth: 2,
|
---|
| 224 | strokeOpacity: 1,
|
---|
| 225 | strokeColor: "#666666",
|
---|
| 226 | fillColor: "white",
|
---|
| 227 | fillOpacity: 0.3
|
---|
| 228 | }
|
---|
| 229 | };
|
---|
| 230 | var style = new OpenLayers.Style();
|
---|
| 231 | style.addRules([
|
---|
| 232 | new OpenLayers.Rule({symbolizer: sketchSymbolizers})
|
---|
| 233 | ]);
|
---|
| 234 | var styleMap = new OpenLayers.StyleMap({"default": style});
|
---|
| 235 |
|
---|
| 236 | rulerControl = new OpenLayers.Control.Measure(
|
---|
| 237 | OpenLayers.Handler.Path, {
|
---|
| 238 | persist: true,
|
---|
| 239 | handlerOptions: {
|
---|
| 240 | layerOptions: {styleMap: styleMap}
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
[8280] | 243 | );
|
---|
[8283] | 244 |
|
---|
| 245 | rulerControl.events.on({
|
---|
| 246 | "measure": handleMeasurements,
|
---|
| 247 | "measurepartial": handleMeasurements
|
---|
| 248 | });
|
---|
| 249 | map.addControl(rulerControl);
|
---|
[8280] | 250 | }
|
---|
[8283] | 251 |
|
---|
| 252 | function resize() {
|
---|
| 253 | size = new OpenLayers.Size(size.w + 10, size.h + 10);
|
---|
| 254 | icon.setSize(size);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
[8285] | 257 | function onPopupClose(evt) {
|
---|
| 258 | select.unselectAll();
|
---|
| 259 | }
|
---|
[8283] | 260 |
|
---|
[8285] | 261 |
|
---|
| 262 | function onKMLFeatureSelect(event) {
|
---|
| 263 | var feature = event.feature;
|
---|
[8447] | 264 | var content = "";
|
---|
| 265 | if (feature.cluster) {
|
---|
| 266 | for (var i = 0; i < feature.cluster.length; i++) {
|
---|
| 267 | var node = feature.cluster[i];
|
---|
| 268 | var content = content + "<h2>" + node.attributes.name + "</h2>" + node.attributes.description + "<br />";
|
---|
| 269 | }
|
---|
| 270 | } else {
|
---|
| 271 | var content = "<h2>" + feature.attributes.name + "</h2>" + feature.attributes.description;
|
---|
| 272 | }
|
---|
[8285] | 273 | popup = new OpenLayers.Popup.FramedCloud("chicken",
|
---|
| 274 | feature.geometry.getBounds().getCenterLonLat(),
|
---|
| 275 | new OpenLayers.Size(100,100),
|
---|
| 276 | content,
|
---|
| 277 | null, true, onPopupClose);
|
---|
| 278 | feature.popup = popup;
|
---|
| 279 | map.addPopup(popup);
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | function onKMLFeatureUnselect(event) {
|
---|
| 283 | var feature = event.feature;
|
---|
| 284 | if(feature.popup) {
|
---|
| 285 | map.removePopup(feature.popup);
|
---|
| 286 | feature.popup.destroy();
|
---|
| 287 | delete feature.popup;
|
---|
| 288 | }
|
---|
| 289 | }
|
---|
| 290 |
|
---|
[8283] | 291 | function handleMeasurements(event) {
|
---|
| 292 | // For some reason 'delayed' events get posted even though the object
|
---|
| 293 | // is deactivated
|
---|
| 294 | if (!rulerControl.active) {
|
---|
| 295 | return;
|
---|
| 296 | }
|
---|
| 297 | var geometry = event.geometry;
|
---|
| 298 | var units = event.units;
|
---|
| 299 | var order = event.order;
|
---|
| 300 | var measure = event.measure;
|
---|
| 301 | var element = document.getElementById('output');
|
---|
| 302 | out = measure.toFixed(3) + " " + units;
|
---|
| 303 | if(order == 2) {
|
---|
| 304 | out += "<sup>2</" + "sup>";
|
---|
| 305 | } else {
|
---|
| 306 | }
|
---|
| 307 | element.innerHTML = out;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
[8304] | 310 | function toggleClickControl() {
|
---|
| 311 | if (!clickControl.active) {
|
---|
| 312 | clickControl.activate();
|
---|
| 313 | document.getElementById('click').src = url_pal3 + "icon32.png";
|
---|
| 314 | } else {
|
---|
| 315 | clickControl.deactivate();
|
---|
| 316 | document.getElementById('click').src = url_pal3 + "icon28.png";
|
---|
| 317 |
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 |
|
---|
[8283] | 321 | function toggleRulerControl() {
|
---|
| 322 | if (!rulerControl.active) {
|
---|
| 323 | rulerControl.activate();
|
---|
| 324 | document.getElementById('ruler').src = "ruler_on.png";
|
---|
| 325 | } else {
|
---|
| 326 | rulerControl.deactivate();
|
---|
| 327 | document.getElementById('ruler').src = "ruler_off.png";
|
---|
[8305] | 328 | document.getElementById('output').innerHTML = "";
|
---|
[8283] | 329 | }
|
---|
| 330 | }
|
---|
[8304] | 331 |
|
---|
[8283] | 332 | function defaultFocus() {
|
---|
| 333 | map.setCenter(new OpenLayers.LonLat(4.50,52.186) // Center of the map
|
---|
| 334 | .transform( projection_wgs, projection_smp), 12 // Zoom level
|
---|
| 335 | );
|
---|
| 336 | }
|
---|
| 337 |
|
---|
[8285] | 338 | function toggleInfo() {
|
---|
| 339 | var e = document.getElementById('infofield');
|
---|
| 340 | if (e.style.visibility == "hidden") {
|
---|
| 341 | e.style.visibility = "visible";
|
---|
| 342 | } else {
|
---|
| 343 | e.style.visibility = "hidden";
|
---|
| 344 | };
|
---|
| 345 | }
|
---|
| 346 |
|
---|
[8304] | 347 | function coordConvert(lam, phi) {
|
---|
| 348 | var lam_deg = Math.floor(lam);
|
---|
| 349 | var t = (lam - lam_deg) * 60;
|
---|
| 350 | var lam_min = Math.floor(t);
|
---|
| 351 | var lam_sec = (t - lam_min) * 60;
|
---|
| 352 |
|
---|
| 353 | var phi_deg = Math.floor(phi);
|
---|
| 354 | var t = (phi - phi_deg) * 60;
|
---|
| 355 | var phi_min = Math.floor(t);
|
---|
| 356 | var phi_sec = (t - phi_min) * 60;
|
---|
| 357 |
|
---|
| 358 | var url = "http://www.rdnap.nl/cgi-bin/rdetrs.pl?func=etrs2rd&h=0" +
|
---|
| 359 | "&lam_deg=" + lam_deg +
|
---|
| 360 | "&lam_min=" + lam_min +
|
---|
| 361 | "&lam_sec=" + lam_sec +
|
---|
| 362 | "&phi_deg=" + phi_deg +
|
---|
| 363 | "&phi_min=" + phi_min +
|
---|
| 364 | "&phi_sec=" + phi_sec
|
---|
| 365 | ;
|
---|
| 366 | return(url);
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 |
|
---|
[8283] | 370 | // http://openlayers.org/dev/examples/strategy-cluster-threshold.html
|
---|
[8280] | 371 | </script>
|
---|
| 372 | </head>
|
---|
| 373 | <body onload="init();">
|
---|
[8283] | 374 | <div id="basicMap">
|
---|
[8285] | 375 | <div id="controller" style="position: absolute; top: 10px; left : 80px; z-index:1004">
|
---|
| 376 | <img id="ruler" src="ruler_off.png" onClick="toggleRulerControl()" />
|
---|
[8304] | 377 | <img height="22" src="http://maps.google.com/mapfiles/kml/pal3/icon23.png" title="Reset focus" onclick="defaultFocus()"/>
|
---|
| 378 | <img height="22" src="http://maps.google.com/mapfiles/kml/pal3/icon36.png" title="Information" onclick="toggleInfo()" />
|
---|
| 379 | <img id="click" height="22" src="http://maps.google.com/mapfiles/kml/pal3/icon28.png" title="Coordinate converter" onclick="toggleClickControl()" />
|
---|
[8285] | 380 | <div id="output"></div>
|
---|
| 381 | </div>
|
---|
| 382 | <div id="infofield" style="position: absolute; bottom: 40px; left : 10px; z-index:1004; background-color: red; visibility: hidden">
|
---|
| 383 | <ul>
|
---|
| 384 | <li>holding down shift, whilst dragging the mouse to do box zooming</li>
|
---|
| 385 | <li>Keyboard Navigation is enabled</li>
|
---|
[8303] | 386 | <li>Contrast of background: <a title="decrease opacity" href="javascript: changeOpacity(-0.1);">Decrease</a> or <a title="increase opacity" href="javascript: changeOpacity(0.1);">Increase</a></li>
|
---|
| 387 |
|
---|
| 388 |
|
---|
[8285] | 389 | </ul>
|
---|
| 390 | </div>
|
---|
[8283] | 391 | </div>
|
---|
[8280] | 392 | </body>
|
---|
| 393 | </html>
|
---|