我一直在使用Winform GEPlugin控件示例进行工作。
http://code.google.com/p/winforms-geplugin-control-library/wiki/ExampleForm
我的问题是我想移动我的地标(在C#中,而不是KML),我尝试了很多,但它不起作用。 请建议我解决这个问题。代码示例也会有所帮助。
答案 0 :(得分:0)
我想我们可以通过java脚本移动它,在winform-GE插件中有一些函数,如injectJavascript和invokeJavascript,我们可以利用这些函数来执行javascript函数..
即使我无法完全移动它,但我能够创建一个新的地标并删除之前的地标,这将让人感觉地标正在移动。
<script
src="http://www.google.com/jsapi?key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw"
type="text/javascript"></script>
<script type="text/javascript">
function addSampleButton(caption, clickHandler) {
var btn = document.createElement('input');
btn.type = 'button';
btn.value = caption;
if (btn.attachEvent)
btn.attachEvent('onclick', clickHandler);
else
btn.addEventListener('click', clickHandler, false);
// add the button to the Sample UI
document.getElementById('sample-ui').appendChild(btn);
}
function addSampleUIHtml(html) {
document.getElementById('sample-ui').innerHTML += html;
}
</script>
<script type="text/javascript">
var ge;
var placemark;
var counter = 0;
google.load("earth", "1");
function init() {
google.earth.createInstance('map3d', initCallback, failureCallback);
addSampleButton('Create a Placemark!', buttonClick);
addSampleButton('Remove last Placemark!', RemovebuttonClick);
}
function initCallback(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
// add a navigation control
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
// add some layers
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
// Get the current view.
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
lookAt.setRange(1000);
// Set new latitude and longitude values.
lookAt.setLatitude(11.50);
lookAt.setLongitude(79.50);
// Update the view in Google Earth.
ge.getView().setAbstractView(lookAt);
createPlacemark();
document.getElementById('installed-plugin-version').innerHTML = ge
.getPluginVersion().toString();
}
function failureCallback(errorCode) {
}
function removePlacemark() {
//counter--;
// alert("placemark" + (counter -1));
ge.getFeatures().removeChild(placemark);
}
function createPlacemark() {
if (counter != 0)
removePlacemark();
placemark = ge.createPlacemark('');
placemark.setName("placemark" + counter);
ge.getFeatures().appendChild(placemark);
// Create style map for placemark
var icon = ge.createIcon('');
icon
.setHref('http://www.veryicon.com/icon/png/Transport/Transport%201/Car.png');
var style = ge.createStyle('');
style.getIconStyle().setIcon(icon);
placemark.setStyleSelector(style);
// Create point
var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
var point = ge.createPoint('');
point.setLatitude(la.getLatitude());
point.setLongitude(la.getLongitude());
placemark.setGeometry(point);
placemark.
counter++;
}
function buttonClick() {
createPlacemark();
}
function RemovebuttonClick() {
removePlacemark();
}
</script>
您可以尝试这些脚本,如果您可以通过给出纬度和经度来移动,那么请告诉我