<%@ Page="" Language="C#" AutoEventWireup="true" %>
<%@ Register="" Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script src="http://maps.google.com/maps?file=api&v=2&key=YourKey" type="text/javascript"></script>
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="http://ui.jquery.com/latest/ui/effects.core.js" type="text/javascript"></script>
<script src="http://ui.jquery.com/latest/ui/effects.explode.js" type="text/javascript"></script>
<script src="http://ui.jquery.com/latest/ui/ui.core.js" type="text/javascript"></script>
<script src="http://ui.jquery.com/latest/ui/ui.draggable.js" type="text/javascript"></script>
<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;">
<head runat="server">
<title>Silverlight Google Geocode/StreetView</title>
<script type="text/javascript">
$(document).ready(function() {
$('#txtAddress').keypress(function(e) {
if (e.which == 13) {
$('#btnFindAddress').click();
e.preventDefault();
}
});
});
function runEffect(x,y,divID) {
//run the effect
$("#" + divID).css({ left: x, top: y });
$("#" + divID).effect('bounce');
//set draggable
$("#" + divID).draggable({ cursor: 'crosshair'});
$("#" + divID).draggable('disable');
};
var geocoder;
function FindAddress(address) {
geocoder = new GClientGeocoder();
geocoder.getLocations(address, addAddressToMap);
}
function addAddressToMap(response) {
if (!response response.Status.code != 200) {
alert("No Address found");
} else {
place = response.Placemark[0];
var lon = place.Point.coordinates[0];
var lat = place.Point.coordinates[1];
var address = place.address;
slControl.Content.slApplication.FindIndirizzo(lon, lat, address);
}
}
function streetView(lat, lon, x, y, divID) {
//alert("Message received from Silverlight:" + divID);
var latlng = new GLatLng(lat, lon);
var svp = new GStreetviewClient();
svp.getNearestPanoramaLatLng(latlng,
function(newPoint) {
if (newPoint == null) {
alert("Street View Not Available For This Location");
return;
}
var divMain = document.createElement('div');
divMain.setAttribute("id", divID + "_Contain");
divMain.setAttribute("style", "position:absolute; z-index:1000; height: 325px; width: 300px;background-color:#888888");
var btnDraggable = document.createElement('input');
btnDraggable.setAttribute("id", divID + "_Move");
btnDraggable.setAttribute("type", "button");
btnDraggable.setAttribute("style", "position:relative;z-index:1000;height: 25px; width: 60px;left:5px;top:5px");
btnDraggable.setAttribute("value", "unlock");
btnDraggable.setAttribute("onclick", "var a = $get('" + divID + "_Move');var b = $('#" + divID + "_Contain');if (a.value =='unlock') {a.value = 'lock'; b.draggable('enable');}else{a.value = 'unlock';b.draggable('disable');}");
divMain.appendChild(btnDraggable);
var btnClose = document.createElement('input');
btnClose.setAttribute("id", divID + "_Close");
btnClose.setAttribute("type", "button");
btnClose.setAttribute("style", "position:relative;z-index:1000;height: 25px; width: 60px;left:180px;top:5px");
btnClose.setAttribute("value", "close");
btnClose.setAttribute("onclick", "var a = $get('" + divID + "_Contain');a.style.display='none';");
divMain.appendChild(btnClose);
var divSV = document.createElement('div');
divSV.setAttribute("id", divID);
divSV.setAttribute("style", "position:relative;z-index:1000;height: 290px; width: 290px;left:5px;top:5px");
divMain.appendChild(divSV);
document.forms[0].insertBefore(divMain, $get("controlSL"));
panoramaOptions = { latlng: newPoint };
svp = new GStreetviewPanorama(divSV);
GEvent.addListener(svp, "error", StreetViewError);
var myPov = { yaw: 176.03773913343627, pitch: -0.13590989423507835 };
svp.setLocationAndPOV(latlng, myPov);
runEffect(x, y, divID + "_Contain");
});
}
function StreetViewError(errorCode) {
if (errorCode == 603) {
alert("Error: Flash doesn't appear to be supported by your browser");
return;
}
if (errorCode == 600) {
alert("Street View Not Available For This Location");
return;
}
}
var slControl = null;
function pluginLoaded(sender){
slControl = sender.get_element();
};
</script>
</head>
<body style="height:100%;margin:0;">
<form id="form1" runat="server" style="height:100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div id ="controlSL" style="height:100%;">
<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/saGoogleGeocode.xap" Windowless ="true" OnPluginLoaded="pluginLoaded" MinimumVersion="2.0.31005.0" Width="100%" Height="97%" />
<input id="txtAddress" type="text" />
<input id="btnFindAddress" type="button" value="Find address (Google)" onclick="FindAddress($get('txtAddress').value);" />
</div>
</form>
</body>
</html>
Page.xaml
using System;
using System.Windows.Browser;
using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
//Domenico Ciavarella www.studioat.it
namespace saGoogleGeocode
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
[ScriptableMember()]
public void FindIndirizzo(double lon, double lat, string address)
{
Graphic graphic = new Graphic();
graphic.Symbol = StrobeMarkerSymbol;
graphic.Attributes.Add("Address", address);
MapPoint pt = new MapPoint(lon, lat,new SpatialReference(4326));
graphic.Geometry = pt;
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
graphicsLayer.Graphics.Add(graphic);
MyMap.ZoomTo(pt.Envelope(0.005));
//if you project point
//GeometryService geometryService = new GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
//geometryService.ProjectCompleted += GeometryService_ProjectCompleted;
//graphic.Geometry = new MapPoint(lon, lat, new SpatialReference(4326));
//IList<Graphic> graphics = new List<Graphic>() { graphic };
//geometryService.ProjectAsync(graphics, new SpatialReference(3003)); //<---your wkid
}
private void MyMap_MouseClick(object sender, Map.MouseEventArgs e)
{
MapPoint p = e.MapPoint;
string divId = Guid.NewGuid().ToString();
HtmlPage.Window.Invoke("streetView", p.Y, p.X, e.ScreenPoint.X, e.ScreenPoint.Y,divId);
}
}
public static class Utility
{
public static Envelope Envelope(this MapPoint pt, double expand)
{
return new Envelope(pt.X - expand, pt.Y - expand, pt.X + expand, pt.Y + expand);
}
}
}
Scarica qui la soluzione
Nessun commento:
Posta un commento