0

我一直在为我的工作使用 Winform GEPlugin 控件示例。

http://code.google.com/p/winforms-geplugin-control-library/wiki/ExampleForm

我的问题是我想移动我的地标(在 C# 中,而不是 KML 中),我尝试了很多但它不起作用。请为此建议我一些解决方案。代码示例也会有所帮助。

4

1 回答 1

0

我想我们可以通过java脚本来移动它,在winform-GE Plugin中有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>

你可以试试这些脚本,如果你能通过给出纬度和经度来移动,那么请告诉我

于 2013-01-18T08:47:48.017 回答