refs #2 add option to change marker style and tooltip visibility

merge-requests/1/head
Julien Veyssier 2016-12-06 16:23:14 +01:00
parent bf6c42b3f7
commit bfe39ad302
4 changed files with 111 additions and 15 deletions

View File

@ -11,7 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- ability to load jpg files as markers, conversion with gpsbabel like kml and csv - ability to load jpg files as markers, conversion with gpsbabel like kml and csv
[#3](https://gitlab.com/eneiluj/gpxedit-oc/issues/3) @eneiluj [#3](https://gitlab.com/eneiluj/gpxedit-oc/issues/3) @eneiluj
- custom tile server management - custom tile server management
[#4](https://gitlab.com/eneiluj/gpxedit-oc/issues/3) @eneiluj [#4](https://gitlab.com/eneiluj/gpxedit-oc/issues/4) @eneiluj
- option to change marker style and tooltip visibility
[#2](https://gitlab.com/eneiluj/gpxedit-oc/issues/2) @eneiluj
### Fixed ### Fixed
- remove $.parseXML, apparently useless and producing errors - remove $.parseXML, apparently useless and producing errors

View File

@ -463,6 +463,13 @@ input[type=checkbox]
height: 30px !important; height: 30px !important;
} }
.leaflet-marker-blue
{
background-image: url('images/marker-icon.png') !important;
width: 25px !important;
height: 41px !important;
}
.leaflet-marker-red .leaflet-marker-red
{ {
background-image: url('images/marker-icon-red.png'); background-image: url('images/marker-icon-red.png');

View File

@ -4,6 +4,7 @@
var gpxedit = { var gpxedit = {
map: {}, map: {},
baseLayers: null, baseLayers: null,
drawControl: null,
id: 0, id: 0,
// indexed by gpxedit_id // indexed by gpxedit_id
layersData: {} layersData: {}
@ -183,10 +184,6 @@ function load_map() {
).addTo(gpxedit.map); ).addTo(gpxedit.map);
gpxedit.minimapControl._toggleDisplayButtonClicked(); gpxedit.minimapControl._toggleDisplayButtonClicked();
//gpxedit.map.on('moveend',updateTrackListFromBounds);
//gpxedit.map.on('zoomend',updateTrackListFromBounds);
//gpxedit.map.on('baselayerchange',updateTrackListFromBounds);
gpxedit.editableLayers = new L.FeatureGroup(); gpxedit.editableLayers = new L.FeatureGroup();
gpxedit.map.addLayer(gpxedit.editableLayers); gpxedit.map.addLayer(gpxedit.editableLayers);
@ -215,6 +212,7 @@ function load_map() {
}; };
var drawControl = new L.Control.Draw(options); var drawControl = new L.Control.Draw(options);
gpxedit.drawControl = drawControl;
gpxedit.map.addControl(drawControl); gpxedit.map.addControl(drawControl);
// when something is created, we generate popup content // when something is created, we generate popup content
@ -374,15 +372,35 @@ function generateGpx(){
// adds a marker and initialize its data // adds a marker and initialize its data
function drawMarker(latlng, name, desc, cmt){ function drawMarker(latlng, name, desc, cmt){
// to add a marker var wst = $('#markerstyleselect').val();
var m = L.marker(latlng, { if (wst === 'tp' || wst === 'p'){
icon: L.divIcon({ var m = L.marker(latlng, {
className: 'leaflet-div-icon2', icon: L.divIcon({
iconAnchor: [5, 30] className: 'leaflet-div-icon2',
}) iconAnchor: [5, 30]
}); })
});
}
else if (wst === 'ts' || wst === 's'){
var m = L.marker(latlng, {
icon: L.divIcon({
iconSize:L.point(6,6),
html:'<div></div>'
})
});
}
else if (wst === 'tm' || wst === 'm'){
var m = L.marker(latlng);
}
var layer = onCreated('marker', m); var layer = onCreated('marker', m);
m.bindTooltip(name, {sticky:true}); if (name !== ''){
if (wst === 'tm' || wst === 'tp' || wst === 'ts'){
m.bindTooltip(name, {permanent:true});
}
else{
m.bindTooltip(name, {sticky:true});
}
}
gpxedit.layersData[layer.gpxedit_id].name = name; gpxedit.layersData[layer.gpxedit_id].name = name;
gpxedit.layersData[layer.gpxedit_id].comment = cmt; gpxedit.layersData[layer.gpxedit_id].comment = cmt;
gpxedit.layersData[layer.gpxedit_id].description = desc; gpxedit.layersData[layer.gpxedit_id].description = desc;
@ -390,12 +408,20 @@ function drawMarker(latlng, name, desc, cmt){
// adds a polyline and initialize its data // adds a polyline and initialize its data
function drawLine(latlngs, name, desc, cmt){ function drawLine(latlngs, name, desc, cmt){
var wst = $('#markerstyleselect').val();
var p = L.polyline(latlngs, { var p = L.polyline(latlngs, {
color: '#f357a1', color: '#f357a1',
weight: 7 weight: 7
}); });
var layer = onCreated('polyline', p); var layer = onCreated('polyline', p);
p.bindTooltip(name, {sticky:true}); if (name !== ''){
if (wst === 'tm' || wst === 'tp' || wst === 'ts'){
p.bindTooltip(name, {permanent:true});
}
else{
p.bindTooltip(name, {sticky:true});
}
}
gpxedit.layersData[layer.gpxedit_id].name = name; gpxedit.layersData[layer.gpxedit_id].name = name;
gpxedit.layersData[layer.gpxedit_id].comment = cmt; gpxedit.layersData[layer.gpxedit_id].comment = cmt;
gpxedit.layersData[layer.gpxedit_id].description = desc; gpxedit.layersData[layer.gpxedit_id].description = desc;
@ -445,6 +471,7 @@ function parseGpx(xml){
function clear(){ function clear(){
var layersToRemove = []; var layersToRemove = [];
gpxedit.editableLayers.eachLayer(function (layer) { gpxedit.editableLayers.eachLayer(function (layer) {
layer.unbindTooltip();
delete gpxedit.layersData[layer.gpxedit_id]; delete gpxedit.layersData[layer.gpxedit_id];
layersToRemove.push(layer); layersToRemove.push(layer);
}); });
@ -584,21 +611,68 @@ function addTileServer(){
}); });
} }
function updateLeafletDrawMarkerStyle(){
var wst = $('#markerstyleselect').val();
if (wst === 'tp' || wst === 'p'){
gpxedit.drawControl.setDrawingOptions({
marker: {
icon: L.divIcon({
className: 'leaflet-div-icon2',
iconAnchor: [5, 30]
})
}
});
}
else if (wst === 'ts' || wst === 's'){
gpxedit.drawControl.setDrawingOptions({
marker: {
icon: L.divIcon({
iconSize:L.point(6,6),
html:'<div></div>'
})
}
});
}
else if (wst === 'tm' || wst === 'm'){
gpxedit.drawControl.setDrawingOptions({
marker: {
icon: L.divIcon({
className: 'leaflet-marker-blue',
iconAnchor: [12, 41]
})
}
});
}
}
$(document).ready(function(){ $(document).ready(function(){
gpxedit.username = $('p#username').html(); gpxedit.username = $('p#username').html();
load_map(); load_map();
document.onkeydown = checkKey; document.onkeydown = checkKey;
$('select#markerstyleselect').change(function(e){
updateLeafletDrawMarkerStyle();
});
updateLeafletDrawMarkerStyle();
$('body').on('click','button.popupOkButton', function(e) { $('body').on('click','button.popupOkButton', function(e) {
var id = parseInt($(this).attr('layerid')); var id = parseInt($(this).attr('layerid'));
var name = $(this).parent().find('.layerName').val(); var name = $(this).parent().find('.layerName').val();
var description = $(this).parent().find('.layerDesc').val(); var description = $(this).parent().find('.layerDesc').val();
var comment = $(this).parent().find('.layerCmt').val(); var comment = $(this).parent().find('.layerCmt').val();
var wst = $('#markerstyleselect').val();
gpxedit.layersData[id].name = name; gpxedit.layersData[id].name = name;
gpxedit.layersData[id].description = description; gpxedit.layersData[id].description = description;
gpxedit.layersData[id].comment = comment; gpxedit.layersData[id].comment = comment;
gpxedit.layersData[id].layer.bindTooltip(name, {sticky:true}); gpxedit.layersData[id].layer.unbindTooltip();
if (name !== ''){
if (wst === 'tm' || wst === 'tp' || wst === 'ts'){
gpxedit.layersData[id].layer.bindTooltip(name, {permanent:true});
}
else{
gpxedit.layersData[id].layer.bindTooltip(name, {sticky:true});
}
}
gpxedit.map.closePopup(); gpxedit.map.closePopup();
}); });

View File

@ -64,6 +64,19 @@ echo '</p>'."\n";
<div class="sidebar-pane" id="settings"> <div class="sidebar-pane" id="settings">
<h1 class="sectiontitle"><?php p($l->t('Settings and extra actions')); ?></h1> <h1 class="sectiontitle"><?php p($l->t('Settings and extra actions')); ?></h1>
<hr/> <hr/>
<br/>
<label>Waypoint style:</label>
<select id="markerstyleselect">
<option value="ts"><?php p($l->t('text+point')); ?></option>
<option value="s"><?php p($l->t('point')); ?></option>
<option value="tp"><?php p($l->t('text+pin')); ?></option>
<option value="p"><?php p($l->t('pin')); ?></option>
<option value="tm"><?php p($l->t('text+marker')); ?></option>
<option value="m"><?php p($l->t('marker')); ?></option>
</select>
<br/>
<br/>
<hr/>
<br/> <br/>
<h3 class="sectiontitle"><?php p($l->t('Custom tile servers')); ?></h3> <h3 class="sectiontitle"><?php p($l->t('Custom tile servers')); ?></h3>
<br/> <br/>