Jump to content
Sign in to follow this  
faustf

embedded page html +jscript in gui

Recommended Posts

faustf

hi guys ,

i want embed  a  pageweb  inside a gui  but  i think javascript  not  work or probably i use  wrong way for do that , because  i dont have  experience about this

anyone could help me ????   thankz

this a script

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.14.2
    Author:         faustf

    Script Function:
     V2

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiStatusBar.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

#include "include\Sqlite3Pw.au3"
#include "include\UDFPlus.au3"


Opt("GuiOnEventMode", 1)
Opt("GUICloseOnESC", 0)
Opt("GUIResizeMode", 128)


_GUI()

Func _GUI()

    Local $oIE = _IECreateEmbedded()

    $Form1 = GUICreate("Form1", 1215, 622, 385, 297) ; Scanner Immobiliare
    $MenuItem1 = GUICtrlCreateMenu("&File")
    $Tab1 = GUICtrlCreateTab(1, 1, 1213, 579)
    $TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
    $Group1 = GUICtrlCreateGroup("", 5, 23, 945, 553)

    GUICtrlCreateObj($oIE, 10, 40, 935, 530)

    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $List1 = GUICtrlCreateList("", 952, 272, 258, 305)
    $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 956, 28, 97, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Checkbox1", 956, 44, 97, 17)
    $Checkbox3 = GUICtrlCreateCheckbox("Checkbox1", 956, 60, 97, 17)
    $Checkbox4 = GUICtrlCreateCheckbox("Checkbox1", 956, 77, 97, 17)
    $Button1 = GUICtrlCreateButton("Button1", 1136, 160, 59, 21)
    $TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
    $TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
    GUICtrlCreateTabItem("")
    $StatusBar1 = _GUICtrlStatusBar_Create($Form1)
    GUISetState(@SW_SHOW)
    _IENavigate($oIE, "about:blank")
    ;Local $aLHTML = FileReadToArray( @ScriptDir & "\gmaps-drawing-tools-places.htm")
    ;Local $sLHTML
    ;_ArrayDisplay($aLHTML)

Local $sHTML = "<!DOCTYPE html>"
$sHTML &= "<!-- http://gmaps-samples-v3.googlecode.com/svn/trunk/drawing/drawing-tools.html -->" & @CRLF
$sHTML &= "<!-- https://developers.google.com/maps/documentation/javascript/examples/places-searchbox -->" & @CRLF
$sHTML &= "<html>" & @CRLF
$sHTML &= "<head>" & @CRLF
$sHTML &= '<meta name="viewport" content=" initial - scale = 1.0, user - scalable = no">' & @CRLF
$sHTML &= '<meta charset="UTF - 8">' & @CRLF
$sHTML &= "<title>Drawing Tools (B)</title>" & @CRLF
$sHTML &= "<!-- NOTE: two libraries to load are comma-separated; otherwise last mention of the query string arg overwrites the previous -->" & @CRLF
$sHTML &= '<script type="text / javascript"' & @CRLF
$sHTML &= '  src="http : / / maps.google.com / maps / api / js ? sensor = False & v = 3.21.5a & libraries = drawing & signed_in = True & libraries = places, drawing"></script>' & @CRLF
$sHTML &= '<style type="text / css">' & @CRLF
$sHTML &= "#map, html, body {" & @CRLF
$sHTML &= "padding: 0;" & @CRLF
$sHTML &= "margin: 0;" & @CRLF
$sHTML &= "height: 100%;" & @CRLF
$sHTML &= "}" & @CRLF
$sHTML &= "#panel {" & @CRLF
$sHTML &= "width: 200px;" & @CRLF
$sHTML &= "font-family: Arial, sans-serif;" & @CRLF
$sHTML &= "font-size: 13px;" & @CRLF
$sHTML &= "float: right;" & @CRLF
$sHTML &= "margin: 10px;" & @CRLF
$sHTML &= "}" & @CRLF
$sHTML &= "      #color-palette {" & @CRLF
$sHTML &= "clear: both;" & @CRLF
$sHTML &= "}" & @CRLF
$sHTML &= "      .color-button {" & @CRLF
$sHTML &= "width: 14px;" & @CRLF
$sHTML &= "height: 14px;" & @CRLF
$sHTML &= "font-size: 0;" & @CRLF
$sHTML &= "margin: 2px;" & @CRLF
$sHTML &= "float: left;" & @CRLF
$sHTML &= "cursor: pointer;" & @CRLF
$sHTML &= "}" & @CRLF
$sHTML &= "#delete-button {" & @CRLF
$sHTML &= "margin-top: 5px;" & @CRLF
$sHTML &= "}" & @CRLF
$sHTML &= "</style>" & @CRLF
$sHTML &= '<script type="text / javascript">' & @CRLF
$sHTML &= "var drawingManager;" & @CRLF
$sHTML &= "var selectedShape;" & @CRLF
$sHTML &= "var colors = ['#1E90FF', '#FF1493', '#32CD32', '#FF8C00', '#4B0082'];" & @CRLF
$sHTML &= "var selectedColor;" & @CRLF
$sHTML &= "var colorButtons = {};" & @CRLF
$sHTML &= "      function clearSelection() {" & @CRLF
$sHTML &= "if (selectedShape) {" & @CRLF
$sHTML &= "if (typeof selectedShape.setEditable == 'function') {" & @CRLF
$sHTML &= "selectedShape.setEditable(false);" & @CRLF
$sHTML &= "}" & @CRLF
$sHTML &= "selectedShape = null;" & @CRLF
$sHTML &= "}" & @CRLF
$sHTML &= 'curseldiv.innerHTML = " < b > cursel < /b > :";' & @CRLF
$sHTML &= "}" & @CRLF
$sHTML &= "      function updateCurSelText(shape) {" & @CRLF
$sHTML &= "  posstr = "" + selectedShape.position;" & @CRLF
$sHTML &= "  if (typeof selectedShape.position == 'object') {" & @CRLF
$sHTML &= "    posstr = selectedShape.position.toUrlValue();" & @CRLF
$sHTML &= "   }" & @CRLF
$sHTML &= "   pathstr = "" + selectedShape.getPath;" & @CRLF
$sHTML &= "   if (typeof selectedShape.getPath == 'function') {" & @CRLF
$sHTML &= '     pathstr = "[";' & @CRLF
$sHTML &= "     for (var i = 0; i < selectedShape.getPath().getLength(); i++) {" & @CRLF
$sHTML &= '      pathstr += selectedShape.getPath().getAt(i).toUrlValue() + ", ";' & @CRLF
$sHTML &= "    }" & @CRLF
$sHTML &= '     pathstr += "] ";' & @CRLF
$sHTML &= "   }" & @CRLF
$sHTML &= "   bndstr = "" + selectedShape.getBounds;" & @CRLF
$sHTML &= "    cntstr = "" + selectedShape.getBounds;" & @CRLF
$sHTML &= "    if (typeof selectedShape.getBounds == 'function') {" & @CRLF
$sHTML &= "      var tmpbounds = selectedShape.getBounds();" & @CRLF
$sHTML &= "     cntstr = "" + tmpbounds.getCenter().toUrlValue();" & @CRLF
$sHTML &= '    bndstr = "[NE : " + tmpbounds.getNorthEast().toUrlValue() + " SW : " + tmpbounds.getSouthWest().toUrlValue() + "] ";' & @CRLF
$sHTML &= "   }" & @CRLF
$sHTML &= "    cntrstr = "" + selectedShape.getCenter;" & @CRLF
$sHTML &= "   if (typeof selectedShape.getCenter == 'function') {" & @CRLF
$sHTML &= "      cntrstr = "" + selectedShape.getCenter().toUrlValue();" & @CRLF
$sHTML &= "    }" & @CRLF
$sHTML &= "     radstr = "" + selectedShape.getRadius;" & @CRLF
$sHTML &= "     if (typeof selectedShape.getRadius == 'function') {" & @CRLF
$sHTML &= "       radstr = "" + selectedShape.getRadius();" & @CRLF
$sHTML &= "    }" & @CRLF
$sHTML &= '     curseldiv.innerHTML = " < b > cursel < /b > : " + selectedShape.type + " " + selectedShape + " ; <i>pos</i>: " + posstr + " ; <i>path</i>: " + pathstr + " ; <i>bounds</i>: " + bndstr + " ; <i>Cb</i>: " + cntstr + " ; <i>radius</i>: " + radstr + " ; <i>Cr</i>: " + cntrstr ;' & @CRLF
$sHTML &= "    }" & @CRLF
$sHTML &= "      function setSelection(shape, isNotMarker) {" & @CRLF
$sHTML &= "   clearSelection();" & @CRLF
$sHTML &= "    selectedShape = shape;" & @CRLF
$sHTML &= "    if (isNotMarker)" & @CRLF
$sHTML &= "       shape.setEditable(true);" & @CRLF
$sHTML &= "     selectColor(shape.get('fillColor') || shape.get('strokeColor'));" & @CRLF
$sHTML &= "     updateCurSelText(shape);" & @CRLF
$sHTML &= "    }" & @CRLF
$sHTML &= "      function deleteSelectedShape() {" & @CRLF
$sHTML &= "     if (selectedShape) {" & @CRLF
$sHTML &= "        selectedShape.setMap(null);" & @CRLF
$sHTML &= "      }" & @CRLF
$sHTML &= "     }" & @CRLF
$sHTML &= "      function selectColor(color) {" & @CRLF
$sHTML &= "   selectedColor = color;" & @CRLF
$sHTML &= "    for (var i = 0; i < colors.length; ++i) {" & @CRLF
$sHTML &= "      var currColor = colors[i];" & @CRLF
$sHTML &= "      colorButtons[currColor].style.border = currColor == color ? '2px solid #789' : '2px solid #fff';" & @CRLF
$sHTML &= "      }" & @CRLF
$sHTML &= "      var polylineOptions = drawingManager.get('polylineOptions');" & @CRLF
$sHTML &= "      polylineOptions.strokeColor = color;" & @CRLF
$sHTML &= "      drawingManager.set('polylineOptions', polylineOptions);" & @CRLF
$sHTML &= "        var rectangleOptions = drawingManager.get('rectangleOptions');" & @CRLF
$sHTML &= "     rectangleOptions.fillColor = color;" & @CRLF
$sHTML &= "     drawingManager.set('rectangleOptions', rectangleOptions);" & @CRLF
$sHTML &= "        var circleOptions = drawingManager.get('circleOptions');" & @CRLF
$sHTML &= "     circleOptions.fillColor = color;" & @CRLF
$sHTML &= "     drawingManager.set('circleOptions', circleOptions);" & @CRLF
$sHTML &= "        var polygonOptions = drawingManager.get('polygonOptions');" & @CRLF
$sHTML &= "     polygonOptions.fillColor = color;" & @CRLF
$sHTML &= "     drawingManager.set('polygonOptions', polygonOptions);" & @CRLF
$sHTML &= "  }" & @CRLF
$sHTML &= "      function setSelectedShapeColor(color) {" & @CRLF
$sHTML &= "   if (selectedShape) {" & @CRLF
$sHTML &= "     if (selectedShape.type == google.maps.drawing.OverlayType.POLYLINE) {" & @CRLF
$sHTML &= "      selectedShape.set('strokeColor', color);" & @CRLF
$sHTML &= "     } else {" & @CRLF
$sHTML &= "        selectedShape.set('fillColor', color);" & @CRLF
$sHTML &= "      }" & @CRLF
$sHTML &= "    }" & @CRLF
$sHTML &= "   }" & @CRLF
$sHTML &= "      function makeColorButton(color) {" & @CRLF
$sHTML &= "    var button = document.createElement('span');" & @CRLF
$sHTML &= "   button.className = 'color-button';" & @CRLF
$sHTML &= "   button.style.backgroundColor = color;" & @CRLF
$sHTML &= "   google.maps.event.addDomListener(button, 'click', function() {" & @CRLF
$sHTML &= "    selectColor(color);" & @CRLF
$sHTML &= "    setSelectedShapeColor(color);" & @CRLF
$sHTML &= "   });" & @CRLF
$sHTML &= "        return button;" & @CRLF
$sHTML &= " }" & @CRLF
$sHTML &= "       function buildColorPalette() {" & @CRLF
$sHTML &= "var colorPalette = document.getElementById('color-palette');" & @CRLF
$sHTML &= "for (var i = 0; i < colors.length; ++i) {" & @CRLF
$sHTML &= "var currColor = colors[i];" & @CRLF
$sHTML &= "  var colorButton = makeColorButton(currColor);" & @CRLF
$sHTML &= "      colorPalette.appendChild(colorButton);" & @CRLF
$sHTML &= "        colorButtons[currColor] = colorButton;" & @CRLF
$sHTML &= "     }" & @CRLF
$sHTML &= "     selectColor(colors[0]);" & @CRLF
$sHTML &= "     }" & @CRLF
$sHTML &= "var map; " & @CRLF
$sHTML &= "var placeMarkers = [];" & @CRLF
$sHTML &= "var input;" & @CRLF
$sHTML &= "var searchBox;" & @CRLF
$sHTML &= "var curposdiv;" & @CRLF
$sHTML &= "var curseldiv;" & @CRLF
$sHTML &= "      function deletePlacesSearchResults() {" & @CRLF
$sHTML &= "for (var i = 0, marker; marker = placeMarkers[i]; i++) {" & @CRLF
$sHTML &= "marker.setMap(null);" & @CRLF
$sHTML &= "  }" & @CRLF
$sHTML &= "  placeMarkers = [];" & @CRLF
$sHTML &= "  input.value = '';" & @CRLF
$sHTML &= " }" & @CRLF
$sHTML &= "function initialize() {" & @CRLF
$sHTML &= "map = new google.maps.Map(document.getElementById('map'), {" & @CRLF
$sHTML &= "     zoom: 12," & @CRLF
$sHTML &= "      center: new google.maps.LatLng(43.7289,10.8113)," & @CRLF
$sHTML &= "     mapTypeId: google.maps.MapTypeId.ROADMAP," & @CRLF
$sHTML &= "      disableDefaultUI: false," & @CRLF
$sHTML &= "        zoomControl: true" & @CRLF
$sHTML &= "    });" & @CRLF
$sHTML &= "    curposdiv = document.getElementById('curpos');" & @CRLF
$sHTML &= "    curseldiv = document.getElementById('cursel');" & @CRLF
$sHTML &= "        var polyOptions = {" & @CRLF
$sHTML &= "     strokeWeight: 0," & @CRLF
$sHTML &= "      fillOpacity: 0.45," & @CRLF
$sHTML &= "      editable: true" & @CRLF
$sHTML &= "    };" & @CRLF
$sHTML &= "   drawingManager = new google.maps.drawing.DrawingManager({" & @CRLF
$sHTML &= "    drawingMode: google.maps.drawing.OverlayType.POLYGON," & @CRLF
$sHTML &= "     markerOptions: {" & @CRLF
$sHTML &= "    draggable: true," & @CRLF
$sHTML &= "    editable: true," & @CRLF
$sHTML &= "  }," & @CRLF
$sHTML &= "  polylineOptions: {" & @CRLF
$sHTML &= "    editable: true" & @CRLF
$sHTML &= "  }," & @CRLF
$sHTML &= "   rectangleOptions: polyOptions," & @CRLF
$sHTML &= "   circleOptions: polyOptions," & @CRLF
$sHTML &= "   polygonOptions: polyOptions," & @CRLF
$sHTML &= "   map: map" & @CRLF
$sHTML &= " });" & @CRLF
$sHTML &= "        google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) {" & @CRLF
$sHTML &= "      var isNotMarker = (e.type != google.maps.drawing.OverlayType.MARKER);" & @CRLF
$sHTML &= "    drawingManager.setDrawingMode(null);" & @CRLF
$sHTML &= "var newShape = e.overlay;" & @CRLF
$sHTML &= "newShape.type = e.type;" & @CRLF
$sHTML &= "   google.maps.event.addListener(newShape, 'click', function() {" & @CRLF
$sHTML &= "    setSelection(newShape, isNotMarker);" & @CRLF
$sHTML &= "   });" & @CRLF
$sHTML &= "   google.maps.event.addListener(newShape, 'drag', function() {" & @CRLF
$sHTML &= "     updateCurSelText(newShape);" & @CRLF
$sHTML &= "   });" & @CRLF
$sHTML &= "   google.maps.event.addListener(newShape, 'dragend', function() {" & @CRLF
$sHTML &= "      updateCurSelText(newShape);" & @CRLF
$sHTML &= "   });" & @CRLF
$sHTML &= "    setSelection(newShape, isNotMarker);" & @CRLF
$sHTML &= "   });" & @CRLF
$sHTML &= "    google.maps.event.addListener(drawingManager, 'drawingmode_changed', clearSelection);" & @CRLF
$sHTML &= "     google.maps.event.addListener(map, 'click', clearSelection);" & @CRLF
$sHTML &= "       google.maps.event.addDomListener(document.getElementById('delete-button'), 'click', deleteSelectedShape);" & @CRLF
$sHTML &= "        buildColorPalette();" & @CRLF
$sHTML &= "     input = /** @type {HTMLInputElement} */( " & @CRLF
$sHTML &= "        document.getElementById('pac-input'));" & @CRLF
$sHTML &= "    map.controls[google.maps.ControlPosition.TOP_RIGHT].push(input);" & @CRLF
$sHTML &= "   var DelPlcButDiv = document.createElement('div');" & @CRLF
$sHTML &= "    DelPlcButDiv.style.backgroundColor = '#fff';" & @CRLF
$sHTML &= "    DelPlcButDiv.style.cursor = 'pointer';" & @CRLF
$sHTML &= "   DelPlcButDiv.innerHTML = 'DEL';" & @CRLF
$sHTML &= "    map.controls[google.maps.ControlPosition.TOP_RIGHT].push(DelPlcButDiv);" & @CRLF
$sHTML &= "     google.maps.event.addDomListener(DelPlcButDiv, 'click', deletePlacesSearchResults);" & @CRLF
$sHTML &= "        searchBox = new google.maps.places.SearchBox(" & @CRLF
$sHTML &= "/** @type {HTMLInputElement} */(input));" & @CRLF
$sHTML &= "    google.maps.event.addListener(searchBox, 'places_changed', function() {" & @CRLF
$sHTML &= "       var places = searchBox.getPlaces();" & @CRLF
$sHTML &= "          if (places.length == 0) {" & @CRLF
$sHTML &= "         return;" & @CRLF
$sHTML &= "      }" & @CRLF
$sHTML &= "       for (var i = 0, marker; marker = placeMarkers[i]; i++) {" & @CRLF
$sHTML &= "         marker.setMap(null);" & @CRLF
$sHTML &= "       }" & @CRLF
$sHTML &= "        placeMarkers = [];" & @CRLF
$sHTML &= "       var bounds = new google.maps.LatLngBounds();" & @CRLF
$sHTML &= "        for (var i = 0, place; place = places[i]; i++) {" & @CRLF
$sHTML &= "         var image = {" & @CRLF
$sHTML &= "           url: place.icon," & @CRLF
$sHTML &= "           size: new google.maps.Size(71, 71)," & @CRLF
$sHTML &= "origin: new google.maps.Point(0, 0)," & @CRLF
$sHTML &= "  anchor: new google.maps.Point(17, 34)," & @CRLF
$sHTML &= "  scaledSize: new google.maps.Size(25, 25)" & @CRLF
$sHTML &= "     };" & @CRLF
$sHTML &= "         var marker = new google.maps.Marker({" & @CRLF
$sHTML &= "           map: map," & @CRLF
$sHTML &= "           icon: image," & @CRLF
$sHTML &= "         title: place.name," & @CRLF
$sHTML &= "       position: place.geometry.location" & @CRLF
$sHTML &= "       });" & @CRLF
$sHTML &= "            placeMarkers.push(marker);" & @CRLF
$sHTML &= "            bounds.extend(place.geometry.location);" & @CRLF
$sHTML &= "}" & @CRLF
$sHTML &= "          map.fitBounds(bounds);" & @CRLF
$sHTML &= " });" & @CRLF
$sHTML &= "      google.maps.event.addListener(map, 'bounds_changed', function() {" & @CRLF
$sHTML &= "        var bounds = map.getBounds();" & @CRLF
$sHTML &= "       searchBox.setBounds(bounds);" & @CRLF
$sHTML &= '      curposdiv.innerHTML = " < b > curpos < /b > Z : " + map.getZoom() + " C : " + map.getCenter().toUrlValue();' & @CRLF
$sHTML &= "      }); " & @CRLF
$sHTML &= "  }" & @CRLF
$sHTML &= "    google.maps.event.addDomListener(window, 'load', initialize);" & @CRLF
$sHTML &= "</script>" & @CRLF
$sHTML &= "</head>" & @CRLF
$sHTML &= "<body>" & @CRLF
$sHTML &= '<div id="panel">' & @CRLF
$sHTML &= '<div id="color - palette"></div>' & @CRLF
$sHTML &= "<div>" & @CRLF
$sHTML &= '<button id="delete - button">Delete Selected Shape</button>' & @CRLF
$sHTML &= "</div>" & @CRLF
$sHTML &= '<div id="curpos"></div>' & @CRLF
$sHTML &= '<div id="cursel"></div>' & @CRLF
$sHTML &= '<div id="note"><small>Note: markers can be selected, but are not graphically indicated; can be deleted, but cannot have their color changed.</small></div>' & @CRLF
$sHTML &= "</div>" & @CRLF
$sHTML &= '<input id="pac - input" type=" text" placeholder=" Search Box">' & @CRLF
$sHTML &= '<div id="map">A</div>' & @CRLF
$sHTML &= "</body>" & @CRLF
$sHTML &= "</html>"


        _IEDocWriteHTML($oIE, $sHTML)
    _IEAction($oIE, "refresh")
    GUISetOnEvent($GUI_EVENT_CLOSE, _close)


EndFunc   ;==>_GUI

Func _page_publish()

    FileReadLine

EndFunc



Func _close()
    Exit
EndFunc   ;==>_close

While 1
    Sleep(100)
WEnd

and  this is a  html page

<!DOCTYPE html>
<!-- http://gmaps-samples-v3.googlecode.com/svn/trunk/drawing/drawing-tools.html -->
<!-- https://developers.google.com/maps/documentation/javascript/examples/places-searchbox -->
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">
    <title>Drawing Tools (B)</title>
    <!-- NOTE: two libraries to load are comma-separated; otherwise last mention of the query string arg overwrites the previous -->
    <script type="text/javascript"
      src="http://maps.google.com/maps/api/js?sensor=false&v=3.21.5a&libraries=drawing&signed_in=true&libraries=places,drawing"></script>
    <style type="text/css">
      #map, html, body {
        padding: 0;
        margin: 0;
        height: 100%;
      }

      #panel {
        width: 200px;
        font-family: Arial, sans-serif;
        font-size: 13px;
        float: right;
        margin: 10px;
      }

      #color-palette {
        clear: both;
      }

      .color-button {
        width: 14px;
        height: 14px;
        font-size: 0;
        margin: 2px;
        float: left;
        cursor: pointer;
      }

      #delete-button {
        margin-top: 5px;
      }
    </style>
    <script type="text/javascript">
      var drawingManager;
      var selectedShape;
      var colors = ['#1E90FF', '#FF1493', '#32CD32', '#FF8C00', '#4B0082'];
      var selectedColor;
      var colorButtons = {};

      function clearSelection() {
        if (selectedShape) {
          if (typeof selectedShape.setEditable == 'function') {
            selectedShape.setEditable(false);
          }
          selectedShape = null;
        }
        curseldiv.innerHTML = "<b>cursel</b>:";
      }

      function updateCurSelText(shape) {
        posstr = "" + selectedShape.position;
        if (typeof selectedShape.position == 'object') {
          posstr = selectedShape.position.toUrlValue();
        }
        pathstr = "" + selectedShape.getPath;
        if (typeof selectedShape.getPath == 'function') {
          pathstr = "[ ";
          for (var i = 0; i < selectedShape.getPath().getLength(); i++) {
            // .toUrlValue(5) limits number of decimals, default is 6 but can do more
            pathstr += selectedShape.getPath().getAt(i).toUrlValue() + " , ";
          }
          pathstr += "]";
        }
        bndstr = "" + selectedShape.getBounds;
        cntstr = "" + selectedShape.getBounds;
        if (typeof selectedShape.getBounds == 'function') {
          var tmpbounds = selectedShape.getBounds();
          cntstr = "" + tmpbounds.getCenter().toUrlValue();
          bndstr = "[NE: " + tmpbounds.getNorthEast().toUrlValue() + " SW: " + tmpbounds.getSouthWest().toUrlValue() + "]";
        }
        cntrstr = "" + selectedShape.getCenter;
        if (typeof selectedShape.getCenter == 'function') {
          cntrstr = "" + selectedShape.getCenter().toUrlValue();
        }
        radstr = "" + selectedShape.getRadius;
        if (typeof selectedShape.getRadius == 'function') {
          radstr = "" + selectedShape.getRadius();
        }
        curseldiv.innerHTML = "<b>cursel</b>: " + selectedShape.type + " " + selectedShape + "; <i>pos</i>: " + posstr + " ; <i>path</i>: " + pathstr + " ; <i>bounds</i>: " + bndstr + " ; <i>Cb</i>: " + cntstr + " ; <i>radius</i>: " + radstr + " ; <i>Cr</i>: " + cntrstr ;
      }

      function setSelection(shape, isNotMarker) {
        clearSelection();
        selectedShape = shape;
        if (isNotMarker)
          shape.setEditable(true);
        selectColor(shape.get('fillColor') || shape.get('strokeColor'));
        updateCurSelText(shape);
      }

      function deleteSelectedShape() {
        if (selectedShape) {
          selectedShape.setMap(null);
        }
      }

      function selectColor(color) {
        selectedColor = color;
        for (var i = 0; i < colors.length; ++i) {
          var currColor = colors[i];
          colorButtons[currColor].style.border = currColor == color ? '2px solid #789' : '2px solid #fff';
        }

        // Retrieves the current options from the drawing manager and replaces the
        // stroke or fill color as appropriate.
        var polylineOptions = drawingManager.get('polylineOptions');
        polylineOptions.strokeColor = color;
        drawingManager.set('polylineOptions', polylineOptions);

        var rectangleOptions = drawingManager.get('rectangleOptions');
        rectangleOptions.fillColor = color;
        drawingManager.set('rectangleOptions', rectangleOptions);

        var circleOptions = drawingManager.get('circleOptions');
        circleOptions.fillColor = color;
        drawingManager.set('circleOptions', circleOptions);

        var polygonOptions = drawingManager.get('polygonOptions');
        polygonOptions.fillColor = color;
        drawingManager.set('polygonOptions', polygonOptions);
      }

      function setSelectedShapeColor(color) {
        if (selectedShape) {
          if (selectedShape.type == google.maps.drawing.OverlayType.POLYLINE) {
            selectedShape.set('strokeColor', color);
          } else {
            selectedShape.set('fillColor', color);
          }
        }
      }

      function makeColorButton(color) {
        var button = document.createElement('span');
        button.className = 'color-button';
        button.style.backgroundColor = color;
        google.maps.event.addDomListener(button, 'click', function() {
          selectColor(color);
          setSelectedShapeColor(color);
        });

        return button;
      }

       function buildColorPalette() {
         var colorPalette = document.getElementById('color-palette');
         for (var i = 0; i < colors.length; ++i) {
           var currColor = colors[i];
           var colorButton = makeColorButton(currColor);
           colorPalette.appendChild(colorButton);
           colorButtons[currColor] = colorButton;
         }
         selectColor(colors[0]);
       }

      /////////////////////////////////////
      var map; //= new google.maps.Map(document.getElementById('map'), {
      // these must have global refs too!:
      var placeMarkers = [];
      var input;
      var searchBox;
      var curposdiv;
      var curseldiv;

      function deletePlacesSearchResults() {
        for (var i = 0, marker; marker = placeMarkers[i]; i++) {
          marker.setMap(null);
        }
        placeMarkers = [];
        input.value = ''; // clear the box too
      }

      /////////////////////////////////////
      function initialize() {
        map = new google.maps.Map(document.getElementById('map'), { //var
          zoom: 12,//10,
          center: new google.maps.LatLng(43.7289,10.8113),//(22.344, 114.048),
          mapTypeId: google.maps.MapTypeId.ROADMAP,
          disableDefaultUI: false,
          zoomControl: true
        });
        curposdiv = document.getElementById('curpos');
        curseldiv = document.getElementById('cursel');

        var polyOptions = {
          strokeWeight: 0,
          fillOpacity: 0.45,
          editable: true
        };
        // Creates a drawing manager attached to the map that allows the user to draw
        // markers, lines, and shapes.
        drawingManager = new google.maps.drawing.DrawingManager({
          drawingMode: google.maps.drawing.OverlayType.POLYGON,
          markerOptions: {
            draggable: true,
            editable: true,
          },
          polylineOptions: {
            editable: true
          },
          rectangleOptions: polyOptions,
          circleOptions: polyOptions,
          polygonOptions: polyOptions,
          map: map
        });

        google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) {
          //~ if (e.type != google.maps.drawing.OverlayType.MARKER) {
            var isNotMarker = (e.type != google.maps.drawing.OverlayType.MARKER);
            // Switch back to non-drawing mode after drawing a shape.
            drawingManager.setDrawingMode(null);

            // Add an event listener that selects the newly-drawn shape when the user
            // mouses down on it.
            var newShape = e.overlay;
            newShape.type = e.type;
            google.maps.event.addListener(newShape, 'click', function() {
              setSelection(newShape, isNotMarker);
            });
            google.maps.event.addListener(newShape, 'drag', function() {
              updateCurSelText(newShape);
            });
            google.maps.event.addListener(newShape, 'dragend', function() {
              updateCurSelText(newShape);
            });
            setSelection(newShape, isNotMarker);
          //~ }// end if
        });

        // Clear the current selection when the drawing mode is changed, or when the
        // map is clicked.
        google.maps.event.addListener(drawingManager, 'drawingmode_changed', clearSelection);
        google.maps.event.addListener(map, 'click', clearSelection);
        google.maps.event.addDomListener(document.getElementById('delete-button'), 'click', deleteSelectedShape);

        buildColorPalette();

        //~ initSearch();
        // Create the search box and link it to the UI element.
         input = /** @type {HTMLInputElement} */( //var
            document.getElementById('pac-input'));
        map.controls[google.maps.ControlPosition.TOP_RIGHT].push(input);
        //
        var DelPlcButDiv = document.createElement('div');
        //~ DelPlcButDiv.style.color = 'rgb(25,25,25)'; // no effect?
        DelPlcButDiv.style.backgroundColor = '#fff';
        DelPlcButDiv.style.cursor = 'pointer';
        DelPlcButDiv.innerHTML = 'DEL';
        map.controls[google.maps.ControlPosition.TOP_RIGHT].push(DelPlcButDiv);
        google.maps.event.addDomListener(DelPlcButDiv, 'click', deletePlacesSearchResults);

        searchBox = new google.maps.places.SearchBox( //var
          /** @type {HTMLInputElement} */(input));

        // Listen for the event fired when the user selects an item from the
        // pick list. Retrieve the matching places for that item.
        google.maps.event.addListener(searchBox, 'places_changed', function() {
          var places = searchBox.getPlaces();

          if (places.length == 0) {
            return;
          }
          for (var i = 0, marker; marker = placeMarkers[i]; i++) {
            marker.setMap(null);
          }

          // For each place, get the icon, place name, and location.
          placeMarkers = [];
          var bounds = new google.maps.LatLngBounds();
          for (var i = 0, place; place = places[i]; i++) {
            var image = {
              url: place.icon,
              size: new google.maps.Size(71, 71),
              origin: new google.maps.Point(0, 0),
              anchor: new google.maps.Point(17, 34),
              scaledSize: new google.maps.Size(25, 25)
            };

            // Create a marker for each place.
            var marker = new google.maps.Marker({
              map: map,
              icon: image,
              title: place.name,
              position: place.geometry.location
            });

            placeMarkers.push(marker);

            bounds.extend(place.geometry.location);
          }

          map.fitBounds(bounds);
        });

        // Bias the SearchBox results towards places that are within the bounds of the
        // current map's viewport.
        google.maps.event.addListener(map, 'bounds_changed', function() {
          var bounds = map.getBounds();
          searchBox.setBounds(bounds);
          curposdiv.innerHTML = "<b>curpos</b> Z: " + map.getZoom() + " C: " + map.getCenter().toUrlValue();
        }); //////////////////////
      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="panel">
      <div id="color-palette"></div>
      <div>
        <button id="delete-button">Delete Selected Shape</button>
      </div>
    <div id="curpos"></div>
    <div id="cursel"></div>
    <div id="note"><small>Note: markers can be selected, but are not graphically indicated; can be deleted, but cannot have their color changed.</small></div>
    </div>
    <input id="pac-input" type="text" placeholder="Search Box">
    <div id="map">A</div>
  </body>
</html>

thnakz at all

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×