Skip to content

Commit

Permalink
FIX Incorrect download content bug (fixes #3)
Browse files Browse the repository at this point in the history
The Export feature did not download the correct Map content when displaying multiple Maps using the Shortcode.
  • Loading branch information
Joseph Hawes committed Jul 27, 2021
1 parent 387c868 commit 26117a7
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 26 deletions.
17 changes: 15 additions & 2 deletions assets/dist/waymark-js/js/waymark-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -7104,6 +7104,9 @@ function Waymark_Map() {
});
Waymark_L.control.attribution({prefix: '<a href="https://wordpress.org/plugins/waymark" title="Share your way">Waymark</a> | <a href="https://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>'}).addTo(Waymark.map);

//Add reference
map_container.data('Waymark', Waymark);

//View
if(Waymark.config.map_init_latlng !== undefined) {
Waymark.map.setView(Waymark.config.map_init_latlng);
Expand Down Expand Up @@ -9171,12 +9174,22 @@ function Waymark_Map_Editor() {
*/

function Waymark_Map_Factory() {
this.instances = [];

this.viewer = function() {
return Object.assign(new Waymark_Map, new Waymark_Map_Viewer);
var instance = Object.assign(new Waymark_Map, new Waymark_Map_Viewer);

this.instances.push(instance);

return instance;
}

this.editor = function() {
return Object.assign(new Waymark_Map, new Waymark_Map_Editor);
var instance = Object.assign(new Waymark_Map, new Waymark_Map_Editor);

this.instances.push(instance);

return instance;
}
}

Expand Down
2 changes: 1 addition & 1 deletion assets/dist/waymark-js/js/waymark-js.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/front.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 32 additions & 13 deletions assets/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ function waymark_setup_map_export() {
//Each Export field
jQuery('.waymark-map-export').each(function() {
var export_container = jQuery(this);

if(export_container) {
//Shortcode
var shortcode_container = export_container.parents('.waymark-shortcode');
if(shortcode_container.length) {
var map_container = jQuery('.waymark-map', shortcode_container);
//Map Details & Admin
} else {
var map_container = jQuery('.waymark-map');
}

//Container
var export_parent = export_container.parents('.waymark-meta-export_data');
if(! export_parent.length) {
Expand All @@ -27,16 +36,14 @@ function waymark_setup_map_export() {

var input_map_data = jQuery('input[name="map_data"]', export_container);

var export_link = jQuery('a', export_container);
var export_select = jQuery('select', export_container);

//Hide Export row if no data to export
if(typeof Waymark !== 'undefined') {
Waymark.map.on('layerremove layeradd', function() {
var Waymark_Instance = map_container.data('Waymark');
if(typeof Waymark_Instance !== 'undefined') {
Waymark_Instance.map.on('layerremove layeradd', function() {
var active_layer_count = 0;
Waymark.map_data.eachLayer(function(layer) {
Waymark_Instance.map_data.eachLayer(function(layer) {
//If visible
if(Waymark.map.hasLayer(layer)) {
if(Waymark_Instance.map.hasLayer(layer)) {
active_layer_count++;
}
});
Expand All @@ -51,16 +58,28 @@ function waymark_setup_map_export() {

//When clicked
export_container.on('submit', function(e) {

// var count = 1;
// for(key in window.Waymark_Map_Factory.instances) {
// if(window.Waymark_Map_Factory.instances[key] === Waymark_Instance) {
// console.log('Export Map #' + count);
//
// return false;
// }
//
// count++;
// }

var export_select = jQuery('select', export_container);
var export_format = export_select.val() ? export_select.val() : 'geojson';

//Get data layer from Leaflet
var map_export_layers = Waymark_L.layerGroup();

console.log(map_export_layers);

Waymark.map_data.eachLayer(function(layer) {

Waymark_Instance = map_container.data('Waymark');
Waymark_Instance.map_data.eachLayer(function(layer) {
//If visible
if(Waymark.map.hasLayer(layer)) {
if(Waymark_Instance.map.hasLayer(layer)) {
for(key in layer.feature.properties) {
//If we have something
if(typeof layer.feature.properties[key] != 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion inc/Admin/Waymark_Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function get_map_form() {
}

//Map Div
echo '<div id="waymark-map"></div>' . "\n";
echo '<div id="waymark-map" class="waymark-map"></div>' . "\n";

//Output Config
Waymark_JS::add_call('var waymark_user_config = ' . json_encode(Waymark_Config::get_map_config()) . ';');
Expand Down
4 changes: 2 additions & 2 deletions inc/Front/Waymark_Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function handle_shortcode($shortcode_data, $content = null) {

//Output HTML container
$out = '<!-- START Waymark Shortcode #' . $shortcode_hash . ' -->' . "\n";
$out .= '<div id="waymark-shortcode-' . $shortcode_hash . '" class="waymark-shortcode waymark-container">' . "\n";
$out .= '<div id="waymark-shortcode-' . $shortcode_hash . '" data-shortcode_hash="' . $shortcode_hash . '" class="waymark-shortcode waymark-container">' . "\n";


//Header ?
Expand Down Expand Up @@ -166,7 +166,7 @@ function handle_shortcode($shortcode_data, $content = null) {

//Map HTML Container
$out .= ' <!-- Map -->' . "\n";
$out .= ' <div id="waymark-map-' . $shortcode_hash . '" class="' . $map_class . '" style="height:' . $map_height . 'px"></div>' . "\n";
$out .= ' <div id="waymark-map-' . $shortcode_hash . '" class="' . $map_class . '" data-shortcode_hash="' . $shortcode_hash . '" style="height:' . $map_height . 'px"></div>' . "\n";

//Elevation?
if(array_key_exists('show_elevation', $shortcode_data)) {
Expand Down
17 changes: 15 additions & 2 deletions waymark-js/dist/js/waymark-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -7104,6 +7104,9 @@ function Waymark_Map() {
});
Waymark_L.control.attribution({prefix: '<a href="https://wordpress.org/plugins/waymark" title="Share your way">Waymark</a> | <a href="https://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>'}).addTo(Waymark.map);

//Add reference
map_container.data('Waymark', Waymark);

//View
if(Waymark.config.map_init_latlng !== undefined) {
Waymark.map.setView(Waymark.config.map_init_latlng);
Expand Down Expand Up @@ -9171,12 +9174,22 @@ function Waymark_Map_Editor() {
*/

function Waymark_Map_Factory() {
this.instances = [];

this.viewer = function() {
return Object.assign(new Waymark_Map, new Waymark_Map_Viewer);
var instance = Object.assign(new Waymark_Map, new Waymark_Map_Viewer);

this.instances.push(instance);

return instance;
}

this.editor = function() {
return Object.assign(new Waymark_Map, new Waymark_Map_Editor);
var instance = Object.assign(new Waymark_Map, new Waymark_Map_Editor);

this.instances.push(instance);

return instance;
}
}

Expand Down
2 changes: 1 addition & 1 deletion waymark-js/dist/js/waymark-js.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions waymark-js/src/js/Waymark_Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ function Waymark_Map() {
});
Waymark_L.control.attribution({prefix: '<a href="https://wordpress.org/plugins/waymark" title="Share your way">Waymark</a> | <a href="https://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>'}).addTo(Waymark.map);

//Add reference
map_container.data('Waymark', Waymark);

//View
if(Waymark.config.map_init_latlng !== undefined) {
Waymark.map.setView(Waymark.config.map_init_latlng);
Expand Down
14 changes: 12 additions & 2 deletions waymark-js/src/js/Waymark_Map_Factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
*/

function Waymark_Map_Factory() {
this.instances = [];

this.viewer = function() {
return Object.assign(new Waymark_Map, new Waymark_Map_Viewer);
var instance = Object.assign(new Waymark_Map, new Waymark_Map_Viewer);

this.instances.push(instance);

return instance;
}

this.editor = function() {
return Object.assign(new Waymark_Map, new Waymark_Map_Editor);
var instance = Object.assign(new Waymark_Map, new Waymark_Map_Editor);

this.instances.push(instance);

return instance;
}
}

Expand Down

0 comments on commit 26117a7

Please sign in to comment.