Anybody have a sample on how to hand-drawing lines on a Google map and save the result? It can be done, as you can see in
http://quikmaps.com
EMG
alvaro533 wrote:If you want to draw lines using the mouse at execution time you can convert mouse coordinates or screen coordinates to geographical coordinates and redraw the control with the new lines.
zoom[1]:=31.4283668948
for nFor=2 to 19
zoom[nFor]:= zoom[nFor-1]/2
next nFor
cHtml += [ map.setCenter(new GLatLng(]+str(latitude)+[,]+str(longitude)+[),]+str(nzoom)+[ ); ]+CRLF
latitude:= degrees + minutes/60 + seconds/3600
longitude:= degrees + minutes/60 + seconds/3600
lat_miles:= latitude*60
long_miles:= longitude*60*COS(0.017453*latitude)
x_pix:= long_miles / nZoom
y_pix:= lat_miles / nZoom
Long_miles:= x_pix * nzoom
Lat_miles:= y_pix * nzoom
Latitude:= lat_miles / 60
Longitude:= long_miles /60 / cos(0.017453*latitude)
cHtml += [ var marker = new GMarker(new GLatLng( ]+str(latitude)+","+str(longitude)+ [ )); ]+CRLF
cHtml += [ map.addOverlay(marker); ]+CRLF
cHtml += [ var html= ']+ cName + [<br/>' + '] + cLongname +['; ]+CRLF
cHtml += [ marker.bindInfoWindowHtml(html); ]+CRLF
alvaro533 wrote:I hope it helps.
// -------------------------------------------------------------------------- //
FUNCTION googlemaps(oWndp,como,nnum,nombre)
local oWnd2, oactivex
local icon2,cad
local ancho,alto
LOCAL cHtml
LOCAL nLat, nLon, nZoom , nZoom2
local nsele:=select()
local alineas,i
local latmax:=-90,latmin:=+90,lonmax:=-360,lonmin:=+360
local zoom[19]
zoom[1]:=31.4283668948
for i=2 to 19
zoom[i]:=zoom[i-1]/2
next i
IF !IsGoogleup()
MsgAlert("No hay Conexión a internet!"+CRLF+"No se puede usar GoogleMap")
RETURN nil
ENDIF
ancho:=oWndp:nwidth-55
alto:=oWndp:nheight-170
if como="ruta"
sele 0
use datos\flplin new inde datos\flplin alias (alineas:=getnewalias("flplin"))
DBSETRELATION("database", {|| (alineas)->id},"(alineas)->id")
OrdScope(0,nnum*1000)
OrdScope(1,nnum*1000+999)
go top
endif
nombre:=alltrim(nombre)
if empty(nombre)
nombre:="prueba"
endif
lmkdir("google")
nZoom := 13
DEFINE ICON ICON2 name "google"
cHtml := [ <html> <head> ]+CRLF
cHtml += [ <meta http-equiv="content-type" content="text/html; charset=utf-8"/> ]+CRLF
cHtml += [ <title>Google Maps</title> ]+CRLF
cHtml += [ <script src="http://maps.google.com/maps?file=api&v=2&key=1223" type="text/javascript"></script> ]+CRLF
cHtml += [ <script type="text/javascript"> ]+CRLF
cHtml += " function load() "+CRLF
cHtml += " { if (GBrowserIsCompatible()) "+CRLF
cHtml += [ { var map = new GMap2(document.getElementById("map"),G_SATELLITE_MAP); ] + CRLF
// cHtml += [ map.addControl(new GLargeMapControl3D()); ]+CRLF
cHtml += [ map.addControl(new GScaleControl()); ]+CRLF
cHtml += [ map.addControl(new GMapTypeControl()); ]+CRLF
// cHtml += [ map.addControl(new GMapTypeControl(),new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10))); ]+CRLF
cHtml += [ map.setCenter(new GLatLng(]+sc(database->LAT)+[,]+sc(database->LON)+[),]+sc(nzoom)+[ ); ]+CRLF
cHtml += [ map.setMapType(G_HYBRID_MAP); ]+CRLF
// -------------------------------------------------------------- POLILINEA
CHTML += " var polyline = new GPolyline([ "+CRLF
go top
do while !eof()
// CHTML += " new GLatLng( " + sc(database->LAT)+","+sc(database->LON)+" ) "
CHTML += " new GLatLng(parseFloat( " + sc(database->LAT)+"),parseFloat("+sc(database->LON)+") ) "
skip
if !eof()
CHTML += ","
endif
enddo
CHTML += " ], '#00ffff', 8); map.addOverlay(polyline); "+CRLF // ancho de la linea del poligono
go top
do while !eof()
cHtml += [ var marker = new GMarker(new GLatLng( ]+sc(database->LAT)+","+sc(database->LON)+ [ )); ]+CRLF
cHtml += [ map.addOverlay(marker); ]+CRLF
cHtml += [ var html= ']+ sc(database->name) + [<br/>' + '] + sc(database->longname) +['; ]+CRLF
// cHtml += [ marker.openInfoWindowHtml(html); ]+CRLF
cHtml += [ marker.bindInfoWindowHtml(html); ]+CRLF
skip
enddo
// ---------------------------------------------------------------botones ruta
cHtml += [ function TextualZoomControl() { } ]+CRLF
cHtml += [ TextualZoomControl.prototype = new GControl(); ]+CRLF
cHtml += [ TextualZoomControl.prototype.initialize = function(map) { ]+CRLF
cHtml += [ var container = document.createElement("div"); ]+CRLF
dbeval( { || latmax:=max(latmax, database->lat) , ;
latmin:=min(latmin, database->lat) , ;
lonmax:=max(lonmax, database->lon) , ;
lonmin:=min(lonmin, database->lon) })
nlat:=(latmax+latmin)/2
nlon:=(lonmax+lonmin)/2
latmax:= abs((latmax-latmin)*60) // millas a lo alto
lonmax:= abs(lonmax-lonmin)*60*COS(0.017453*nlat)
// millas a lo ancho
if ancho/alto*latmax > lonmax
nzoom2:=latmax/alto
else
nzoom2:=lonmax/ancho
endif
i:=19
do while .t.
if nzoom2>zoom[i]
i--
else
exit
endif
if i=1
exit
endif
enddo
nzoom2:=i
cHtml += [ var zoomInDiv = document.createElement("div"); this.setButtonStyle_(zoomInDiv); ]+CRLF
cHtml += [ container.appendChild(zoomInDiv); zoomInDiv.appendChild(document.createTextNode("-TODO-")); ]+CRLF
cHtml += [ GEvent.addDomListener(zoomInDiv, "click", function() {map.setCenter(new GLatLng(]+ sc(nlat) +[,]+ sc(nlon) +[),]+sc(nzoom2)+[ )}); ]+CRLF
go top
do while !eof()
cHtml += [ var zoomInDiv = document.createElement("div"); this.setButtonStyle_(zoomInDiv); ]+CRLF
cHtml += [ container.appendChild(zoomInDiv); zoomInDiv.appendChild(document.createTextNode("] +sc(subs(database->name,1,6)) +[")); ]+CRLF
cHtml += [ GEvent.addDomListener(zoomInDiv, "click", function() {map.setCenter(new GLatLng(]+sc(database->LAT)+[,]+sc(database->LON)+[),]+sc(nzoom)+[ )}); ]+CRLF
skip
enddo
go top
cHtml += [ map.getContainer().appendChild(container); return container; } ]+CRLF
cHtml += [ TextualZoomControl.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(7, 7)) ; } ]+CRLF
cHtml += [ TextualZoomControl.prototype.setButtonStyle_ = function(button) { button.style.color = "#0000cc"; ]+CRLF
cHtml += [ button.style.backgroundColor = "white"; button.style.font = "small Arial"; button.style.border = "1px solid black"; ]+CRLF
cHtml += [ button.style.padding = "2px"; button.style.marginBottom = "3px"; button.style.textAlign = "center"; ]+CRLF
cHtml += [ button.style.width = "6em"; ]+CRLF // ancho
cHtml += [ button.style.cursor = "pointer"; } ]+CRLF
cHtml += [ map.addControl(new TextualZoomControl()); ]+CRLF
CHTML += "var customUI = map.getDefaultUI(); customUI.controls.scalecontrol = false; map.setUI(customUI); "+CRLF
// arriba ponía false en lugar de true
CHTML += " } } "+ CRLF
CHTML += " </script> </head> "+CRLF
CHTML += [ <body scroll="no" bgcolor="#CCCCCC" topmargin="0" leftmargin="0" ] +CRLF
CHTML += [ onload="load()" onunload="GUnload()"> ] + CRLF
chtml += [ <div id="map" style="width:]+ sc(ancho) + [px;height:]+ sc(alto) +[px"></div> ] + CRLF
chtml += [ </body> </html> ]
// cHtml := STRTRAN(cHtml, "<<<ALTO>>>",sc(alto) )
MemoWrit("google\"+nombre+".htm",chtml)
DEFINE WINDOW oWnd2 MDICHILD of oWndp icon icon2 TITLE "Plan de Vuelo: "+nombre
oActiveX = TActiveX():New( oWnd2, "Shell.Explorer.2" )
// @ 0,0 button "salir" of oWnd2 size 60,20 pixel action oWnd2:end()
oActiveX:nwidth:=ancho
oActiveX:nheight:=alto
oActiveX:ntop:=0
// oWnd2:oClient = oActiveX // To fill the entire window surface
if .t.
oActiveX:Do("Navigate2",(CurDrive() + ":\"+CurDir()+"\google\"+nombre+".htm"))
else
oActiveX:Do("Navigate2",(CurDrive() + ":\"+CurDir()+"\MiHtml.htm"))
endif
oWnd2:nwidth:=ancho+12
oWnd2:nheight:=alto+38 // 38
oWnd2:bKeyDown = { | nKey | teclas(nKey,oWnd2) }
ACTIVATE WINDOW oWnd2 // on init (oWnd2:move(0,0,1200,1000),oWndp:refresh())
// ya está cerrada la base de datoa arriba y nsele
if como="ruta"
(alineas)->( DBCLOSEAREA() )
endif
select(nsele)
RETURN NIL
// -------------------------------------------------------------------------- //
Function IsGoogleup()
MsgWait( "Comprobando si hay conexión a internet","Espere",0.3 )
WSAStartup()
return GetHostByName( "www.google.com" ) != "0.0.0.0"
// -------------------------------------------------------------------------- //
function sc(cadena,long)
do case
case VALTYPE(cadena) == "C"
cadena:=alltrim(cadena)
case VALTYPE(cadena) == "N"
cadena:=alltrim(str(cadena))
case VALTYPE(cadena) == "L"
cadena:=if(cadena,".t.",".f.")
case VALTYPE(cadena) == "D"
cadena:=dtoc(cadena)
case VALTYPE(cadena) == "A"
cadena:="error, has mandado un array"
case VALTYPE(cadena) == "B"
cadena:="error, has mandado un codeblock"
case VALTYPE(cadena) == "U"
cadena:="** SIN DEFINIR **"
case cadena == nil
cadena:="**NIL**"
endcase
if long!= NIL
cadena:=subs(cadena+spac(long),1,long)
endif
return cadena
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=1223" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load(){
if (GBrowserIsCompatible())
// Variables para el mapa
var lat = 39.52;
var lon = 3.04;
var zoom = 10;
// Crear un nuevo mapa
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(lat, lon), zoom);
map.addControl(new GLargeMapControl());
GEvent.addListener(map, "singlerightclick", function(pixel)
{
var clickPoint = map.fromContainerPixelToLatLng(pixel);
alert(clickPoint.toUrlValue());
});
}
//]]> </script> </head>
<body scroll="no" bgcolor="#CCCCCC" topmargin="0" leftmargin="0"
onload="load()" onunload="GUnload()">
<div id="map" style="width: 754px;height: 521px"></div>
</body> </html>
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 88 guests