Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cut topology leaflet plugin #22

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 27 additions & 32 deletions georiviere/river/static/river/js/cut-topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ L.Control.PointTopology = L.Control.extend({
}
});


L.Handler.PointTopology = L.Draw.Marker.extend({
initialize: function (map, guidesLayer, options) {
L.Draw.Marker.prototype.initialize.call(this, map, options);
this._helpText = gettext('Click map to place marker, then move it to snap with the topology.');
this._topoMarker = null;
this._partTopo = null;
this._guidesLayer = guidesLayer;
map.addGuideLayer(guidesLayer);
map.togglePin();
map.on('draw:created', this._onDrawn, this);
},

Expand All @@ -131,9 +132,6 @@ L.Handler.PointTopology = L.Draw.Marker.extend({
restoreTopology: function (topo) {
this._topoMarker = L.marker([topo.lat, topo.lng]);
this._splitTopology(this._topoMarker);
if (topo.snap) {
this._topoMarker.fire('move'); // snap to closest
}
},

_onDrawn: function (e) {
Expand All @@ -150,36 +148,33 @@ L.Handler.PointTopology = L.Draw.Marker.extend({

_splitTopology: function (marker) {
marker.addTo(this._map);
L.DomUtil.addClass(marker._icon, 'marker-point');
marker.editing = new L.Handler.MarkerSnap(this._map, marker);
marker.editing.addGuideLayer(this._guidesLayer);
marker.editing.enable();
marker.on('snap', function (e) {
var content = $('#form_topology');
$('#lat').val(e.latlng.lat);
$('#lng').val(e.latlng.lng);
if (this._partTopo === null){
var partTopo = new L.Polyline(L.GeometryUtil.extract(
this._map,
this._guidesLayer,
L.GeometryUtil.locateOnLine(this._map, this._guidesLayer, e.latlng),
0),
L.DomUtil.addClass(marker._icon, 'scissor-point');

var content = $('#form_topology');
$('#lat').val(marker._latlng.lat);
$('#lng').val(marker._latlng.lng);
if (this._partTopo === null) {
var partTopo = new L.Polyline(L.GeometryUtil.extract(
this._map,
this._guidesLayer,
L.GeometryUtil.locateOnLine(this._map, this._guidesLayer, marker._latlng), 0),
{color: 'red', weight: 5, opacity: 0.5});
this._partTopo = partTopo;
partTopo.addTo(this._map);
this._map.on('layeradd', function (e) {
partTopo.bringToFront();
});
}
this._partTopo.setLatLngs(
L.GeometryUtil.extract(this._map,
this._guidesLayer,
L.GeometryUtil.locateOnLine(this._map, this._guidesLayer, e.latlng), 0));
marker.bindPopup(content.html()).openPopup();
this._partTopo = partTopo;
partTopo.addTo(this._map);
this._map.on('layeradd', function (e) {
partTopo.bringToFront();
});
}
this._partTopo.setLatLngs(L.GeometryUtil.extract(
this._map,
this._guidesLayer,
L.GeometryUtil.locateOnLine(this._map, this._guidesLayer, marker._latlng), 0));
marker.bindPopup(content.html()).openPopup();

this._map.on('click', function (e) {
marker.closePopup();
this.reset()
}, this);
marker.on('unsnap', function (e) {
marker.closePopup();
}, this);
},
});

4 changes: 4 additions & 0 deletions georiviere/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@
'topofields': {'js': ['river/js/georiviere.forms.snap.js',
'river/js/cut-topology.js'],
'css': ['river/css/cut-topology.css']}
'leaflet.pin': {
'css': ['vendors/Leaflet.Pin/leaflet.pin.min.css'],
'js': ['vendors/Leaflet.Pin/leaflet.pin.min.js'],
}
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added georiviere/static/vendors/Leaflet.Pin/images/pin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions georiviere/static/vendors/Leaflet.Pin/leaflet.pin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.leaflet-pin-marker {
margin-left: -4px !important;
margin-top: -4px !important;
width: 8px !important;
height: 8px !important;
}

.leaflet-control-pin {
width: 26px;
height: 26px;
}

.leaflet-control-pin a {
background: url("images/pin-disabled.png");
background-position: -2px -2px;
}

.leaflet-control-pin-enabled a {
background: url("images/pin.png");
}
Loading