Closed Nicd closed 9 years ago
I decided to work around the problem by changing the way I move the map. I now zoom the map one level less than the intended zoom level and then zoom it in by calling the map's zoomIn(). This seems to fix the input issue.
function setCoords(longitude, latitude, zoom) {
// Create point to transform it to correct map coordinates
var point = new OpenLayers.LonLat(longitude, latitude);
// Coordinate system is WGS 84
var proj = new OpenLayers.Projection("EPSG:4326");
{% for map in maps %}
var map = map_{{ map }}.map;
point.transform(proj, map.getProjectionObject());
map.setCenter(point, zoom - 1, true, true);
// Fix map input breaking due to setCenter()
map.zoomIn();
{% endfor %}
}
I'm writing a site as a project for a university course. The site should have a possibility for users to locate one or more points on a map, which would then be stored in a GeoDjango PointField or MultiPointField. I've set up a floppyforms PointWidget which works, but I've been trying to add HTML5 geolocation into the mix using a setCenter() call on the widget's map object.
My demo is live at http://loytotavarat.nytsoi.net/find/create/ If you disallow geolocation, the widget seems to work ok and you can input a point just fine. If you do allow geolocation, however, the map zooms to the correct location, but inserting a point no longer works (I'm testing on the latest stable Chrome on OS X). I assume the widget loses track of what the map is pointing at due to the geolocation moving the map. When this happens, the blue circle no longer tracks the cursor or disappears altogether and it's not possible to insert points on the map anymore. If the user zooms in or out manually, functionality is restored.
I change the map's location based on geolocation data with the following function (the list 'maps' contains the ids of all maps in the form):
Is there another way to incorporate geolocation or move the map that doesn't upset the widget or is this a real issue?