1 | <html>
|
---|
2 | <head>
|
---|
3 | <title>OpenLayers Demo</title>
|
---|
4 | <style type="text/css">
|
---|
5 | html, body, #basicMap {
|
---|
6 | width: 100%;
|
---|
7 | height: 100%;
|
---|
8 | margin: 0;
|
---|
9 | }
|
---|
10 | </style>
|
---|
11 | <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
|
---|
12 | <script>
|
---|
13 | function init() {
|
---|
14 | map = new OpenLayers.Map("basicMap");
|
---|
15 | var mapnik = new OpenLayers.Layer.OSM();
|
---|
16 | map.addLayer(mapnik);
|
---|
17 |
|
---|
18 | var pois = new OpenLayers.Layer.Text( "My Points",
|
---|
19 | { location:"./textfile.txt",
|
---|
20 | projection: map.displayProjection
|
---|
21 | });
|
---|
22 | map.addLayer(pois);
|
---|
23 |
|
---|
24 | var vectors = new OpenLayers.Layer.Vector("Vector Layer")
|
---|
25 | map.addLayer(vectors);
|
---|
26 | map.addControl(new OpenLayers.Control.MousePosition());
|
---|
27 | map.addControl(new OpenLayers.Control.EditingToolbar(vectors));
|
---|
28 |
|
---|
29 | var in_options = {
|
---|
30 | 'internalProjection': map.baseLayer.projection,
|
---|
31 | 'externalProjection': new OpenLayers.Projection("EPSG:4326")
|
---|
32 | };
|
---|
33 | var wkt = new OpenLayers.Format.WKT(in_options);
|
---|
34 | var txtFile = new XMLHttpRequest();
|
---|
35 | txtFile.open("GET", "./wktfile.txt", false);
|
---|
36 | // txtFile.onreadystatechange = function() {
|
---|
37 | // if(txtFile.readyState == 4) {
|
---|
38 | // alert(txtFile.responseText);
|
---|
39 | // }
|
---|
40 | // }
|
---|
41 | txtFile.send(null);
|
---|
42 |
|
---|
43 | var features = wkt.read(txtFile.responseText.replace(/\n/g,''));
|
---|
44 | var bounds;
|
---|
45 |
|
---|
46 | if (features) {
|
---|
47 | if(features.constructor != Array) {
|
---|
48 | features = [features];
|
---|
49 | }
|
---|
50 | for(var i=0; i<features.length; ++i) {
|
---|
51 | if (!bounds) {
|
---|
52 | bounds = features[i].geometry.getBounds();
|
---|
53 | }
|
---|
54 | bounds.extend(features[i].geometry.getBounds());
|
---|
55 | }
|
---|
56 | vectors.addFeatures(features);
|
---|
57 | map.zoomToExtent(bounds);
|
---|
58 | } else {
|
---|
59 | alert("ERROR in WTK");
|
---|
60 | }
|
---|
61 |
|
---|
62 | map.setCenter(new OpenLayers.LonLat(4.40,52.186) // Center of the map
|
---|
63 | .transform(
|
---|
64 | new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
|
---|
65 | new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
|
---|
66 | ), 11 // Zoom level
|
---|
67 | );
|
---|
68 | }
|
---|
69 | </script>
|
---|
70 | </head>
|
---|
71 | <body onload="init();">
|
---|
72 | <div id="basicMap"></div>
|
---|
73 | </body>
|
---|
74 | </html>
|
---|