Changeset 8282 in genesis


Ignore:
Timestamp:
Aug 9, 2010, 9:08:03 PM (14 years ago)
Author:
rick
Message:

Working KML example, much nicer as all other formats

Location:
nodes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nodes/make-map.py

    r8280 r8282  
    6464
    6565def make_graph():
     66  f = open('kmlfile.kml', 'w')
     67  f.write("""
     68<?xml version="1.0" encoding="UTF-8"?>
     69<kml xmlns="http://earth.google.com/kml/2.0">
     70  <Document>
     71    <name>KML Samples</name>
     72    <open>1</open>
     73    <description>Unleash your creativity with the help of these examples!</description>
     74    <Style id="downArrowIcon">
     75      <IconStyle>
     76        <Icon>
     77          <href>http://maps.google.com/mapfiles/kml/pal4/icon28.png</href>
     78        </Icon>
     79      </IconStyle>
     80    </Style>
     81    <Style id="globeIcon">
     82      <IconStyle>
     83        <Icon>
     84          <href>http://maps.google.com/mapfiles/kml/pal3/icon19.png</href>
     85        </Icon>
     86      </IconStyle>
     87      <LineStyle>
     88        <width>2</width>
     89      </LineStyle>
     90    </Style>
     91    <Style id="transPurpleLineGreenPoly">
     92      <LineStyle>
     93        <color>7fff00ff</color>
     94        <width>4</width>
     95      </LineStyle>
     96      <PolyStyle>
     97        <color>7f00ff00</color>
     98      </PolyStyle>
     99    </Style>
     100    <Style id="yellowLineGreenPoly">
     101      <LineStyle>
     102        <color>7f00ffff</color>
     103        <width>4</width>
     104      </LineStyle>
     105      <PolyStyle>
     106        <color>7f00ff00</color>
     107      </PolyStyle>
     108    </Style>
     109    <Style id="thickBlackLine">
     110      <LineStyle>
     111        <color>87000000</color>
     112        <width>10</width>
     113      </LineStyle>
     114    </Style>
     115    <Style id="redLineBluePoly">
     116      <LineStyle>
     117        <color>ff0000ff</color>
     118      </LineStyle>
     119      <PolyStyle>
     120        <color>ffff0000</color>
     121      </PolyStyle>
     122    </Style>
     123    <Style id="blueLineRedPoly">
     124      <LineStyle>
     125        <color>ffff0000</color>
     126      </LineStyle>
     127      <PolyStyle>
     128        <color>ff0000ff</color>
     129      </PolyStyle>
     130    </Style>
     131    <Style id="transRedPoly">
     132      <LineStyle>
     133        <width>1.5</width>
     134      </LineStyle>
     135      <PolyStyle>
     136        <color>7d0000ff</color>
     137      </PolyStyle>
     138    </Style>
     139    <Style id="transBluePoly">
     140      <LineStyle>
     141        <width>1.5</width>
     142      </LineStyle>
     143      <PolyStyle>
     144        <color>7dff0000</color>
     145      </PolyStyle>
     146    </Style>
     147    <Style id="transGreenPoly">
     148      <LineStyle>
     149        <width>1.5</width>
     150      </LineStyle>
     151      <PolyStyle>
     152        <color>7d00ff00</color>
     153      </PolyStyle>
     154    </Style>
     155    <Style id="transYellowPoly">
     156      <LineStyle>
     157        <width>1.5</width>
     158      </LineStyle>
     159      <PolyStyle>
     160        <color>7d00ffff</color>
     161      </PolyStyle>
     162    </Style>
     163    <Style id="noDrivingDirections">
     164      <BalloonStyle>
     165        <text><![CDATA[
     166          <b>$[name]</b>
     167          <br /><br />
     168          $[description]
     169        ]]></text>
     170      </BalloonStyle>
     171    </Style>
     172    <Folder>
     173      <name>Paths</name>
     174      <visibility>0</visibility>
     175      <description>Examples of paths. Note that the tessellate tag is by default
     176        set to 0. If you want to create tessellated lines, they must be authored
     177        (or edited) directly in KML.</description>
     178    """)
     179
    66180  poel = {}
    67181  link_type = {}
     
    94208      lam, phi = rd2etrs(datadump['rdnap_x'], datadump['rdnap_y'])
    95209      node[host] = (lam, phi)
     210      f.write("""
     211                <Placemark>
     212                        <name>Blue Icon</name>
     213                        <description>Just another blue icon.</description>
     214                        <styleUrl>./styles.kml#blueIcons</styleUrl>
     215                        <Point>
     216                                <coordinates>%s,%s,630</coordinates>
     217                        </Point>
     218                </Placemark>
     219   """ % (lam, phi))
    96220      nodes += [("POINT(%s, %s)" % (lam, phi))]
    97221  except (KeyError, ValueError), e:
     
    113237    for index,lid in enumerate(leden[:-1]):
    114238      for buur in leden[index + 1:]:
    115         links += ["LINESTRING(%s %s,%s %s)" % (node[lid][0], node[lid][1], node[buur][0], node[buur][1])]
    116 
    117   f = open('wktfile.txt', 'w')
    118   f.write("GEOMETRYCOLLECTION(\n")
    119   f.write(",\n".join(nodes))
    120   f.write(",\n".join(links))
    121   f.write(")\n")
     239        f.write("""
     240      <Placemark>
     241        <name>Untessellated</name>
     242        <visibility>0</visibility>
     243        <description><![CDATA[If the <tessellate> tag has a value of 0, the line follow a simple straight-line path from point to point]]></description>
     244        <LineString>
     245          <tessellate>0</tessellate>
     246          <coordinates> %s, %s, 0
     247            %s , %s, 0 </coordinates>
     248        </LineString>
     249      </Placemark>
     250      """ % (node[lid][0], node[lid][1], node[buur][0], node[buur][1]))
     251  f.write("""
     252    </Folder>
     253  </Document>
     254</kml>
     255  """)
    122256  f.close()
    123257
  • nodes/nodemap.html

    r8280 r8282  
    99      }
    1010    </style>
    11     <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
     11    <!-- <script src="http://www.openlayers.org/api/OpenLayers.js"></script> -->
     12    <script src="http://openlayers.org/dev/OpenLayers.js"</script>
     13
    1214    <script>
    1315      function init() {
     
    1618        map.addLayer(mapnik);
    1719
    18         var pois = new OpenLayers.Layer.Text( "My Points",
    19                            { location:"./textfile.txt",
    20                              projection: map.displayProjection
    21                            });
    22         map.addLayer(pois);
     20        //layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
     21        //        "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
     22        //map.addLayer(layer);
     23        //var pois = new OpenLayers.Layer.Text( "My Points",
     24        //                   { location:"./textfile.txt",
     25        //                     projection: map.displayProjection
     26        //                   });
     27        //map.addLayer(pois);
    2328
    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));
     29        var kml = new OpenLayers.Layer.GML("KML", "./kmlfile.kml",
     30            { format: OpenLayers.Format.KML,
     31              formatOptions: {
     32                extractStyles: true,
     33                extractAttributes: true,
     34                maxDepth: 2
     35              }
     36            });
     37        map.addLayer(kml);
    2838
    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);
    4239
    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        }
     40        //var vectors = new OpenLayers.Layer.Vector("Vector Layer")
     41        //map.addLayer(vectors);
     42        //map.addControl(new OpenLayers.Control.MousePosition());
     43        //map.addControl(new OpenLayers.Control.EditingToolbar(vectors));
     44
     45        //var in_options = {
     46        //  'internalProjection': map.baseLayer.projection,
     47        //  'externalProjection': new OpenLayers.Projection("EPSG:4326")
     48        //};
     49        //var wkt = new OpenLayers.Format.WKT(in_options);
     50        //var txtFile = new XMLHttpRequest();
     51        //txtFile.open("GET", "./wktfile.txt", false);
     52        //// txtFile.onreadystatechange = function() {
     53        ////   if(txtFile.readyState == 4) {
     54        ////     alert(txtFile.responseText);
     55        ////   }
     56        //// }
     57        //txtFile.send(null);
     58
     59        //var features = wkt.read(txtFile.responseText.replace(/\n/g,''));
     60        //var bounds;
     61        //
     62        //if (features) {
     63        //  if(features.constructor != Array) {
     64        //   features = [features];
     65        //  }
     66        //  for(var i=0; i<features.length; ++i) {
     67        //    if (!bounds) {
     68        //      bounds = features[i].geometry.getBounds();
     69        //    }
     70        //    bounds.extend(features[i].geometry.getBounds());
     71        //  }
     72        //  vectors.addFeatures(features);
     73        //  map.zoomToExtent(bounds);
     74        //} else {
     75        //   alert("ERROR in WTK");
     76        //}
    6177
    6278         map.setCenter(new OpenLayers.LonLat(4.40,52.186) // Center of the map
Note: See TracChangeset for help on using the changeset viewer.