wboykinm

geocoder.js

Jul 6th, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {% block extrastyle %}
  2. <style type="text/css">
  3.   #{{ id }}_map { width: {{ map_width }}px; height: {{ map_height }}px; }
  4.   #{{ id }}_map .aligned label { float:inherit; }
  5.   #{{ id }}_admin_map { position: relative; vertical-align: top; float: {{ LANGUAGE_BIDI|yesno:"right,left" }}; }
  6.   {% if not display_wkt %}#{{ id }} { display: none; }{% endif %}
  7.   .olControlEditingToolbar .olControlModifyFeatureItemActive {
  8.      background-image: url("{{ ADMIN_MEDIA_PREFIX }}img/gis/move_vertex_on.png");
  9.      background-repeat: no-repeat;
  10.   }
  11.   .olControlEditingToolbar .olControlModifyFeatureItemInactive {
  12.      background-image: url("{{ ADMIN_MEDIA_PREFIX }}img/gis/move_vertex_off.png");
  13.      background-repeat: no-repeat;
  14.   }
  15. </style>
  16. <!--[if IE]>
  17. <style type="text/css">
  18.   /* This fixes the mouse offset issues in IE. */
  19.   #{{ id }}_admin_map { position: static; vertical-align: top; }
  20.   /* `font-size: 0` fixes the 1px border between tiles, but borks LayerSwitcher.
  21.       Thus, this is disabled until a better fix is found.
  22.   #{{ id }}_map { width: {{ map_width }}px; height: {{ map_height }}px; font-size: 0; } */
  23. </style>
  24. <![endif]-->
  25. {% endblock %}
  26.  
  27. <span id="{{ id }}_admin_map">
  28. <script type="text/javascript">
  29. //<![CDATA[
  30. {% block openlayers %}{% include "gis/admin/openlayers.js" %}{% endblock %}
  31. //]]>
  32. var geoCodeURL = "http://nominatim.openstreetmap.org/search";
  33. var zoomToPlace = function() {
  34.    var address = document.getElementsByName("geocoder")[0].value;
  35.    if (!address)
  36.       alert("Please type an address or location!");
  37.    else {
  38.  
  39. //begin geocoder (https://gist.github.com/836127)
  40.    // Pass user input to nominatim
  41.    $("#address").autocomplete({
  42.        source: function ( request, response ) {
  43.            $.ajax({
  44.                   url: geoCodeURL,
  45.                   data: {
  46.                       format: "json",
  47.                       q: request.term
  48.                   },
  49.                   //Receive result including lat, lon
  50.                   success: function ( data ) {
  51.                       response ( $.map( data, function( item ) {
  52.                           return  {
  53.                               label: item.display_name,
  54.                               value: item.display_name,
  55.                               lat: item.lat,
  56.                               lon: item.lon
  57.                           }}));
  58.  
  59.                       }
  60.                   })
  61.         },
  62.         minLength: 2,
  63.         delay: 200,
  64.         select: function ( event, ui ) {
  65.                 //transform results and reset map center
  66.             map.setCenter(
  67.                new OpenLayers.LonLat( ui.item.lon, ui.item.lat).transform(
  68.                   new OpenLayers.Projection("EPSG:4326"),
  69.                   // or new OpenLayers.Projection("EPSG:900913")
  70.                   map.getProjectionObject()
  71.                ), 13);
  72.  
  73.         },
  74.        // open: function () {
  75.        //     $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top");
  76.        // },
  77.        // close: function () {
  78.        //     $( this ).removeClass( "ui-corner-top").addClass("ui-corner-all");
  79.        // }
  80.      });
  81.     });
  82. //end inserted code (https://gist.github.com/836127)
  83.   }  
  84. }
  85. </script>
  86. <p>Zoom to Address:
  87. <input id="{{ id }}_geocoder" name="geocoder" value="" onchange="zoomToPlace()">
  88. <button type="button" onclick="zoomToPlace()" >Go!</button>
  89. </p>
  90. <div id="{{ id }}_map"{% if LANGUAGE_BIDI %} dir="ltr"{% endif %}></div>
  91. <a href="javascript:{{ module }}.clearFeatures()">Delete all Features</a>
  92. {% if display_wkt %}<p> WKT debugging window:</p>{% endif %}
  93. <textarea id="{{ id }}" class="vWKTField required" cols="150" rows="10" name="{{ name }}">{{ wkt }}</textarea>
  94. <script type="text/javascript">{% block init_function %}{{ module }}.init();{% endblock %}</script>
  95. </span>
Advertisement
Add Comment
Please, Sign In to add comment