x

Polyline und Marker auf einer Karte


Geschrieben von Ghostrider82 (Gast) am 26. August 2010 20:38:51: [flux]

Hallöchen,

ich fische mir diverse Koordinaten aus einer Datenbank.

Diese Koordinaten werden dann per Polyline miteinander verbunden. Zudem möchte ich, dass jeder Wegpunkt mit einem Marker versehen wird.
Beides im einzelnen funktioniert, aber ich bekomme irgendwie nicht beides unter einen Hut.

Code -> Koordinaten zu einer Polyline:

<body onLoad="">
<div id="wrap">
<div id="header">
</div>
<div class="middle">
<p/>
<div id="gmap" class="mapstraction" style="height: 300px;width: 100%;"></div>
<script type="text/javascript">

function poly(map) { // ANFANG function poly(map)
map.setCenterAndZoom(new LatLonPoint(<?php echo $koord_n[$half_rows]; ?>,<?php echo $koord_e[$half_rows]; ?>), 13);
map.setMapType(Mapstraction.ROAD);
var myPoly = new Polyline([new LatLonPoint(<?php echo $koord_n[0]; ?>,<?php echo $koord_e[0]; ?>),

<?php
for($i=0;$i<$rows;$i++)
{
echo "new LatLonPoint($koord_n[$i],$koord_e[$i]),";
}
?>

new LatLonPoint(<?php echo $koord_n[$rows-1]; ?>,<?php echo $koord_e[$rows-1]; ?>)]);
map.addPolyline(myPoly);

} // ENDE function poly(map)

var gmapstraction = new Mapstraction('gmap','openlayers');
poly(gmapstraction)

</script>

<br/>
</div>
</body>

Separat funktioniert dieser.

Code -> Marker zu Koordinate:

<body>
<div id='mapdiv'></div>
<script src='http://www.openlayers.org/api/OpenLayers.js'></script>
<script>
map = new OpenLayers.Map('mapdiv');
map.addLayer(new OpenLayers.Layer.OSM());
var zoom=16;
var markers = new OpenLayers.Layer.Markers( 'Markers' );

<?php

for($i=0;$i<$rows;$i++)
{

echo "var size = new OpenLayers.Size(25,25);";
echo "var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);";
echo "var icon = new OpenLayers.Icon('337-5.png',size,offset); ";
echo "var lonLat = new OpenLayers.LonLat($koord_e[$i], $koord_n[$i]).transform(new OpenLayers.Projection(\"EPSG:4326\"),
map.getProjectionObject());\n";
echo "map.addLayer(markers);\n";
echo "markers.addMarker(new OpenLayers.Marker(lonLat,icon));\n";
}

>

map.setCenter (lonLat, zoom);

</script>
</body>

Funktioniert separat ebenfalls.

Mein Problem ist nun, dass ich es auch nach stundenlanger Tüftelei nicht schaffe, eine Polyline und Marker auf eine Karte zu plotten.

Kann jemand von euch sehen, worauf das zurückzuführen ist?

Vielen Dank auch diesmal im Voraus ;-)

Boris


Antworten: