【发布时间】:2016-02-27 09:19:31
【问题描述】:
下面是我的 vb.net 代码
ClientScript.RegisterStartupScript([GetType](), Guid.NewGuid().ToString(), "javascript:MarkerFunction('" & dt.Rows(i)("vehno") & "','" & dt.Rows(i)("trackdt") & "','" & Lat & "','" & Lon & "','" & VehImage & "','" & dt.Rows(i)("City") & "','" & dt.Rows(i)("Speed") & "');", True)
下面是我的JavaScript Function
<script type="text/javascript">
function init()
{
map = new OpenLayers.Map("basicMap");
var mapnik = new OpenLayers.Layer.OSM();
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var position = new OpenLayers.LonLat(78.0000,21.0000).transform( fromProjection, toProjection);
var zoom = 5;
map.addLayer(mapnik);
map.setCenter(position, zoom );
var vectorLayer = new OpenLayers.Layer.Vector("Overlay");
function MarkerFunction(VehNo,Trackdt,Lat,Lon,VehImage,City,Speed)
{
alert('hii');
var feature = new OpenLayers.Feature.Vector
(
new OpenLayers.Geometry.Point( lon, lat ).transform(fromProjection, toProjection),
{description: 'Vehicle No : ' + VehNo+'<br>Track Date : ' + Trackdt +'<br> City : '+ City + '<br> Speed : '+ Speed } ,
{externalGraphic: VehImage, graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25 }
);
vectorLayer.addFeatures(feature);
}
//Add a selector control to the vectorLayer with popup functions
var controls =
{
selector: new OpenLayers.Control.SelectFeature(vectorLayer, { onSelect: createPopup, onUnselect: destroyPopup })
};
function createPopup(feature)
{
feature.popup = new OpenLayers.Popup.FramedCloud("pop",
feature.geometry.getBounds().getCenterLonLat(),
null,
'<div class="markerContent">'+feature.attributes.description+'</div>',
null,
true,
function() { controls['selector'].unselectAll(); }
);
map.addPopup(feature.popup);
}
function destroyPopup(feature)
{
feature.popup.destroy();
feature.popup = null;
}
map.addControl(controls['selector']);
controls['selector'].activate();
map.addLayer(vectorLayer);
}
</script>
<body onload="init()">
<div id="basicMap">
</div>
</body>
我想从文件后面的代码中调用MarkerFunction 但我无法调用它。
我尝试了一切,但我不知道我的代码有什么问题。
任何帮助将不胜感激。提前致谢...
【问题讨论】:
-
你不能只从服务器代码中执行 JS 脚本。您可以使用 AJAX/WebSockets 等组合使它们进行通信。但这超出了您现在的范围。您需要几周的时间才能继续该计划
标签: javascript c# vb.net