Skip to content

Commit 681e627

Browse files
committed
Add/Integrate Map in Batch Manager single mode #45
1 parent ac9c824 commit 681e627

2 files changed

Lines changed: 34 additions & 15 deletions

File tree

admin/admin_batchmanager.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,11 @@ function osm_loc_end_element_set_global()
7575
<div class="osm-map1 map1"></div>
7676
<script>
7777
$(document).ready(function() {
78-
console.log( "#permitAction pageshow!" );
7978
$("#permitAction").on("change", function (e) {
80-
console.log( "#permitAction pageshow and change!" );
8179
var optionSelected = $("option:selected", this);
8280
if ("openstreetmap" == optionSelected.val()) {
83-
console.log( "#permitAction pageshow and change and OSM!" );
84-
8581
$(".osm-map1").qleaflet();
86-
87-
} /* End if */
82+
}
8883
});
8984
});
9085
</script>
@@ -218,6 +213,16 @@ function osm_prefilter_batch_manager_unit($content)
218213
<label>{\'Longitude\'|@translate}
219214
<input type="text" size="9" name="osmlon-{$element.id}" value="{$element.longitude}">
220215
</label>
216+
217+
<style type="text/css"> .map1 { height: 200px !important; width:100% !important; margin: 5px; } </style>
218+
<script src="plugins/piwigo-openstreetmap/leaflet/qleaflet.jquery.js"></script>
219+
<div class="osm-map-{$element.id} map1" data-markerpos="{$element.latitude},{$element.longitude}" data-markertext="{$element.name}" data-formid="{$element.id}"></div>
220+
<script>
221+
$(document).ready(function() {
222+
$(".osm-map-{$element.id}").qleaflet();
223+
});
224+
</script>
225+
221226
</td>
222227
</tr>';
223228
$content = substr_replace($content, $add, $pos, 0);

leaflet/qleaflet.jquery.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
scrollWheelZoom : true,
2727
worldCopyJump: true,
2828
contextmenu: false
29-
}
29+
},
30+
formid: false
3031
};
3132

3233
// The actual plugin constructor
@@ -74,15 +75,22 @@
7475
var popup = window.L.popup();
7576

7677
function onMapClick(e) {
77-
console.log(e.latlng.toString());
78-
console.log(document.forms);
78+
//console.log(e.latlng.toString());
79+
//console.log(document.forms);
80+
//console.log(this.options);
7981
popup
8082
.setLatLng(e.latlng)
8183
.setContent("You clicked the map at " + e.latlng.toString())
8284
.openOn(this.map);
83-
var form=document.forms[1]
84-
form.osmlat.value = Math.ceil(e.latlng.lat * 100000) / 100000;
85-
form.osmlon.value = Math.ceil(e.latlng.lng * 100000) / 100000;
85+
86+
if(this.options.formid != false) { // Batch manager single mode
87+
$('[name=osmlat-'+this.options.formid+']').val(Math.ceil(e.latlng.lat * 100000) / 100000);
88+
$('[name=osmlon-'+this.options.formid+']').val(Math.ceil(e.latlng.lng * 100000) / 100000);
89+
} else { // Batch manager global mode
90+
var form=document.forms[1];
91+
form.osmlat.value = Math.ceil(e.latlng.lat * 100000) / 100000;
92+
form.osmlon.value = Math.ceil(e.latlng.lng * 100000) / 100000;
93+
}
8694
}
8795

8896
this.map.on('click', onMapClick, this);
@@ -119,33 +127,39 @@
119127

120128
init : function() {
121129
this.id = this.element.attr('id');
122-
//add id if necessart
130+
//add id if necessary
123131
if(!this.id) {
124132
this.id = 'leafletmap' + Math.floor((Math.random()*100)+1);
125133
this.element.attr('id', this.id);
126134
}
127135
// get data from data attributes in html
128136
// set markers for each map
129137
// other options are shared
130-
if(typeof this.element.data('markerpos') != 'undefined' && this.element.data('markerpos').length != 0) {
138+
if(typeof this.element.data('markerpos') != 'undefined' && this.element.data('markerpos').length > 1) {
131139
this.element.markers = [];
132140
this.element.markers.push({
133141
pos : this.element.data('markerpos').split(','),
134142
text: this.element.data('markertext')
135143
});
144+
this.options.mapOptions.zoom = 15; // If position is set then zoom into it
136145
} else {
137146
this.element.markers = this.options.markers;
138147
}
139148

140149
// set center
141150
if(typeof this.element.data('center') != 'undefined' && this.element.data('center').length != 0) {
142151
this.element.center = this.element.data('center').split(',');
143-
} else if (typeof this.element.data('markerpos') != 'undefined' && this.element.data('markerpos').length != 0) {
152+
} else if (typeof this.element.data('markerpos') != 'undefined' && this.element.data('markerpos').length > 1) {
144153
this.element.center = this.element.data('markerpos').split(',');
145154
} else {
146155
this.element.center = this.options.mapOptions.center;
147156
}
148157

158+
// formid for batch manager single mode
159+
if(typeof this.element.data('formid') != 'undefined' && this.element.data('formid').length != 0) {
160+
this.options.formid = this.element.data('formid');
161+
}
162+
149163
//render
150164
this.loadStylesheet(this.options.leafletCssUri);
151165
$.getScript(this.options.leafletJsUri, this.bind(this.setMap, this));

0 commit comments

Comments
 (0)