Created
February 20, 2011 17:28
-
-
Save jacobandresen/836127 to your computer and use it in GitHub Desktop.
nonimatim openlayers jquery example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var geoCodeURL = "http://nominatim.openstreetmap.org/search"; | |
var map = new OpenLayers.Map({ div: "map" }); | |
var osm = new OpenLayers.Layer.OSM(); | |
map.addLayers([osm]); | |
map.addControl(new OpenLayers.Control.LayerSwitcher()); | |
map.setCenter( | |
new OpenLayers.LonLat( 9.2134, 55.3028).transform( | |
new OpenLayers.Projection("EPSG:4326"), | |
map.getProjectionObject() | |
), 10); | |
$("#address").autocomplete({ | |
source: function ( request, response ) { | |
$.ajax({ | |
url: geoCodeURL, | |
data: { | |
format: "json", | |
q: request.term | |
}, | |
success: function ( data ) { | |
response ( $.map( data, function( item ) { | |
return { | |
label: item.display_name, | |
value: item.display_name, | |
lat: item.lat, | |
lon: item.lon | |
}})); | |
} | |
}) | |
}, | |
minLength: 2, | |
delay: 200, | |
select: function ( event, ui ) { | |
map.setCenter( | |
new OpenLayers.LonLat( ui.item.lon, ui.item.lat).transform( | |
new OpenLayers.Projection("EPSG:4326"), | |
map.getProjectionObject() | |
), 13); | |
}, | |
open: function () { | |
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top"); | |
}, | |
close: function () { | |
$( this ).removeClass( "ui-corner-top").addClass("ui-corner-all"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment