我不明白为什么样式化的矢量图层是不可见的?似乎没有任何功能,但为什么呢?这段代码有错误吗?OSM,Google Layers 是可见的,我可以在 LayerSwitcher 中切换它们(并且覆盖层“Vectorlayer”也存在在那里)。图标的 URL 正确。
<html>
<head>
<meta charset="utf-8" />
<title>Index</title>
<link href="/Content/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script>
<script src="/Scripts/OpenLayers.js" type="text/javascript"></script>
<script type="text/javascript">
function Startit() {
var dislon = 30.4958316666667;
var dislat = 59.9168383333333;
var lonlat = new OpenLayers.LonLat(dislon, dislat);
var map = new OpenLayers.Map({div: "mapcontent",projection: new OpenLayers.Projection("EPSG:900913")});
var maposm = new OpenLayers.Layer.OSM("OSM");
var gmap = new OpenLayers.Layer.Google("Google", { numZoomLevels: 20 });
var ghyb = new OpenLayers.Layer.Google("Google Earth", { type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20 });
map.addLayers([maposm, gmap, ghyb]);
lonlat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
map.setCenter(lonlat, 11);
var lSwitch = new OpenLayers.Control.LayerSwitcher();
map.addControl(lSwitch);
var sdLayer = new OpenLayers.Layer.Vector("VectorLayer");
var cStyle = { externalGraphic: "/images/icons/blue.png", graphicWidth: 35, graphicHeight: 35 };
var currPoint = OpenLayers.Geometry.Point(dislon,dislat);
var ft = new OpenLayers.Feature.Vector(currPoint, null, cStyle);
map.addLayer(sdLayer);
sdLayer.addFeatures([ft]);
}
</script>
</head>
<body onload="Startit();">
<div id="mapcontent" style="width:500px;height:400px;"></div>
</body>
</html>