adding / moving points works
This commit is contained in:
parent
8401078ab0
commit
5edb287f65
|
@ -147,8 +147,9 @@ class Stop(models.Model):
|
||||||
a.delete()
|
a.delete()
|
||||||
for a in data['alternative_names'].split(","):
|
for a in data['alternative_names'].split(","):
|
||||||
alt_name = AlternativeName()
|
alt_name = AlternativeName()
|
||||||
alt_name.name = a['name']
|
alt_name.name = a
|
||||||
alt_name.typ = 'common'
|
alt_name.typ = 'common'
|
||||||
|
alt_name.content_object = self
|
||||||
alt_name.save()
|
alt_name.save()
|
||||||
self.alt_names.add(alt_name)
|
self.alt_names.add(alt_name)
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ var API_BASE = "/1.0/",
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#formCol').find("#stopForm").remove();
|
$('#formCol').find("#stopForm").remove();
|
||||||
|
$('#formCol').empty();
|
||||||
$('#formCol').append($form);
|
$('#formCol').append($form);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -141,13 +142,15 @@ var API_BASE = "/1.0/",
|
||||||
|
|
||||||
function getStopForm(stop, geom) {
|
function getStopForm(stop, geom) {
|
||||||
// console.log(stop);
|
// console.log(stop);
|
||||||
console.log(geom);
|
// console.log(geom);
|
||||||
var lon = !$.isEmptyObject(geom) ? geom.coordinates[0] : '';
|
var lon = !$.isEmptyObject(geom) ? geom.coordinates[0] : '';
|
||||||
var lat = !$.isEmptyObject(geom) ? geom.coordinates[1] : '';
|
var lat = !$.isEmptyObject(geom) ? geom.coordinates[1] : '';
|
||||||
var $div = $('<div />');
|
var $div = $('<div />');
|
||||||
var $displayName = $('<div />').text(stop.display_name).appendTo($div);
|
var $displayName = $('<div />').text(stop.display_name).appendTo($div);
|
||||||
|
var $slug = $('<div />').addClass("stopSlug").text(stop.slug).appendTo($div);
|
||||||
var $routes = $('<div />').text("Routes: " + stop.routes).appendTo($div);
|
var $routes = $('<div />').text("Routes: " + stop.routes).appendTo($div);
|
||||||
var $form = $('<form />').attr("id", "stopForm").appendTo($div);
|
var $form = $('<form />').attr("id", "stopForm").appendTo($div);
|
||||||
|
|
||||||
var $display_name_input = $('<input />')
|
var $display_name_input = $('<input />')
|
||||||
.val(stop.display_name)
|
.val(stop.display_name)
|
||||||
.attr("id", "displayName")
|
.attr("id", "displayName")
|
||||||
|
@ -189,8 +192,11 @@ var API_BASE = "/1.0/",
|
||||||
//console.log(geojsonString);
|
//console.log(geojsonString);
|
||||||
var url = API_BASE + "stop/" + stop.slug + "?srid=3857";
|
var url = API_BASE + "stop/" + stop.slug + "?srid=3857";
|
||||||
$.post(url, {'geojson': geojsonString}, function(response) {
|
$.post(url, {'geojson': geojsonString}, function(response) {
|
||||||
console.log(response);
|
if (response.errors) {
|
||||||
});
|
alert("error saving");
|
||||||
|
}
|
||||||
|
//console.log(response);
|
||||||
|
}, "json");
|
||||||
});
|
});
|
||||||
return $div;
|
return $div;
|
||||||
}
|
}
|
||||||
|
@ -213,8 +219,43 @@ var API_BASE = "/1.0/",
|
||||||
// map.addLayer(vector_layer);
|
// map.addLayer(vector_layer);
|
||||||
map.addLayers(layers);
|
map.addLayers(layers);
|
||||||
map.setCenter(center, 12);
|
map.setCenter(center, 12);
|
||||||
|
var navigationControl = new OpenLayers.Control.Navigation({
|
||||||
mapControl = new OpenLayers.Control.SelectFeature(layers[1]);
|
defaultDblClick: function(event) {
|
||||||
|
//var xy = event.xy;
|
||||||
|
var lonlat = map.getLonLatFromPixel(event.xy);
|
||||||
|
var $stopForm = $('#stopForm');
|
||||||
|
if ($stopForm.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var slug = $('#formCol').find('.stopSlug').text();
|
||||||
|
//console.log("slug", slug);
|
||||||
|
var stop = $('.selectedStop').data("properties");
|
||||||
|
$('.selectedStop').data("geometry", {
|
||||||
|
'coordinates': [lonlat.x, lonlat.y]
|
||||||
|
});
|
||||||
|
var hasPoint = $('.selectedStop').hasClass('has_point');
|
||||||
|
$('#lon').val(lonlat.lon);
|
||||||
|
$('#lat').val(lonlat.lat);
|
||||||
|
$stopForm.submit();
|
||||||
|
if (hasPoint) {
|
||||||
|
var feature = getStopFromSlug(slug);
|
||||||
|
feature.move(lonlat);
|
||||||
|
} else {
|
||||||
|
var pt = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
|
||||||
|
var feature = new OpenLayers.Feature.Vector(pt, stop);
|
||||||
|
//console.log("trying to add", feature);
|
||||||
|
jsonLayer.addFeatures([feature]);
|
||||||
|
mapControl.select(feature);
|
||||||
|
}
|
||||||
|
// console.log(lonlat);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
map.addControl(navigationControl);
|
||||||
|
mapControl = new OpenLayers.Control.SelectFeature(layers[1], {
|
||||||
|
clickout: false,
|
||||||
|
toggle: true
|
||||||
|
});
|
||||||
zoomControl = new OpenLayers.Control.ZoomToMaxExtent();
|
zoomControl = new OpenLayers.Control.ZoomToMaxExtent();
|
||||||
map.addControl(mapControl);
|
map.addControl(mapControl);
|
||||||
// map.addControl(zoomControl);
|
// map.addControl(zoomControl);
|
||||||
|
@ -229,9 +270,18 @@ var API_BASE = "/1.0/",
|
||||||
function onFeatureSelect(e) {
|
function onFeatureSelect(e) {
|
||||||
//alert(arguments);
|
//alert(arguments);
|
||||||
//console.log(feature);
|
//console.log(feature);
|
||||||
|
// console.log(e.feature);
|
||||||
var slug = e.feature.attributes.slug;
|
var slug = e.feature.attributes.slug;
|
||||||
//alert("selected " + slug);
|
//alert("selected " + slug);
|
||||||
highlightStop(slug);
|
highlightStop(slug);
|
||||||
|
var stop = e.feature.attributes;
|
||||||
|
var geom = {
|
||||||
|
'coordinates': [e.feature.geometry.x, e.feature.geometry.y]
|
||||||
|
};
|
||||||
|
var $form = getStopForm(stop, geom);
|
||||||
|
$('#stopForm').remove();
|
||||||
|
$('#formCol').empty();
|
||||||
|
$('#formCol').append($form);
|
||||||
// var matchedStops = $('.' + slug);
|
// var matchedStops = $('.' + slug);
|
||||||
// matchedStops.click();
|
// matchedStops.click();
|
||||||
// matchedStops.addClass('highlightedStop');
|
// matchedStops.addClass('highlightedStop');
|
||||||
|
@ -242,6 +292,8 @@ var API_BASE = "/1.0/",
|
||||||
var slug = e.feature.attributes.slug;
|
var slug = e.feature.attributes.slug;
|
||||||
//alert("unselected " + slug);
|
//alert("unselected " + slug);
|
||||||
unhighlightStop(slug);
|
unhighlightStop(slug);
|
||||||
|
$('#stopForm').remove();
|
||||||
|
$('#formCol').empty();
|
||||||
// var matchedStops = $('.' + slug);
|
// var matchedStops = $('.' + slug);
|
||||||
// matchedStops.removeClass('selectedStop');
|
// matchedStops.removeClass('selectedStop');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user