我是网络映射的新手,并尝试使用一些代码将openlayers地图包含到div中,包括来自php的openlayers代码。它将显示div,但地图会在地图上显示。如何纠正我的代码呢? php包含在map div中
<?php include_once("gps_track.php") ; ?>
#map{
clear:both;
float:left;
border:3px solid #330066;
height:500px;
width:70%;
}
并在css右侧有属性部分
#attribute{
float:right;
border:3px solid #334353;
height:500px;
width:28%;
}
我应该使用openlayes的额外div作为css吗?
js代码是:
var lat=27.6167
var lon=85.5500
var zoom=13
var map;
function init() {
map = new OpenLayers.Map ("map", {
controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Attribution()],
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
maxResolution: 156543.0399,
numZoomLevels: 19,
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
} );
layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
map.addLayer(layerMapnik);
layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
map.addLayer(layerCycleMap);
layerMarkers = new OpenLayers.Layer.Markers("Markers");
map.addLayer(layerMarkers);
var google_map_layer = new OpenLayers.Layer.Google(
'Google Map Layer',
{}
);
var google_hybrid_layer=new OpenLayers.Layer.Google(
'Google Hybrid',
{type:google.maps.MapTypeId.HYBRID}
);
map.addLayer(google_map_layer);
map.addLayer(google_hybrid_layer);
// Add the Layer with the GPX Track
var lgpx = new OpenLayers.Layer.Vector("Kathmandu University", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "ku.gpx",
format: new OpenLayers.Format.GPX()
}),
style: {strokeColor: "green", strokeWidth: 5, strokeOpacity: 0.5},
projection: new OpenLayers.Projection("EPSG:4326")
});
//Adding vector layer for editing
var vector_layer=new OpenLayers.Layer.Vector(
'Editable Vectors'
);
//add a vector editing control
map.addControl(new OpenLayers.Control.EditingToolbar(vector_layer));
map.addLayer(vector_layer);
map.addLayer(lgpx);
var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
map.setCenter(lonLat, zoom);
var size = new OpenLayers.Size(21, 25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://www.openstreetmap.org/openlayers/img/marker.png',size,offset);
layerMarkers.addMarker(new OpenLayers.Marker(lonLat,icon));
}
popup= new OpenLayers.Popup("This is gps track",
new OpenLayers.LonLat(85.5500,27.6167),
new OpenLayers.Size(200,200),
"Dhulikhel",
true);
map.addPopup(popup);
alert("sorry no alert");
</script>