Skip to content

Commit f670e7a

Browse files
committed
custom mapzen, load before show map
1 parent 29b5575 commit f670e7a

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Developed by [Ilya Ilyankou](https://github.com/ilyankou) and [Jack Dougherty](h
1414
- Leaflet v1.0.3 https://leafletjs.com (BSD-2-Clause)
1515
- jQuery v3.2.0 https://code.jquery.com (MIT)
1616
- leaflet-providers (v1.1.15, manually updated for Carto https) https://github.com/leaflet-extras/leaflet-providers (BSD-2-Clause)
17-
- Mapzen Search geocoding plugin (v1.8.1) https://github.com/mapzen/leaflet-geocoder (MIT)
17+
- Mapzen Search geocoding plugin (v1.8.1, customized to display a blue circle around the search result) https://github.com/mapzen/leaflet-geocoder (MIT)
1818
- leaflet-locatecontrol (v0.60.0) https://github.com/domoritz/leaflet-locatecontrol (MIT)
1919
- Leaflet.markercluster (v1.0.4) https://github.com/Leaflet/Leaflet.markercluster (MIT)
2020
- Leaflet.MarkerCluster.LayerSupport (v.1.0.3) https://github.com/ghybs/Leaflet.MarkerCluster.LayerSupport (MIT)
@@ -28,6 +28,6 @@ Developed by [Ilya Ilyankou](https://github.com/ilyankou) and [Jack Dougherty](h
2828
- jQuery-CSV (v0.71) https://github.com/evanplaice/jquery-csv (MIT)
2929
- DataTables (v1.10.13) by SpryMedia Ltd. https://datatables.net (MIT)
3030

31-
## Please submit any pull requests to our DEV repo
31+
## Please submit any pull requests to our DEV repo
3232
- Leaflet Map FOR DEVELOPMENT https://jackdougherty.github.io/leaflet-maps-with-google-sheets-dev/index.html
3333
- Google Sheet FOR DEVELOPMENT https://docs.google.com/spreadsheets/d/1_xjrH3gSImzRKqIkhRAqpAAMjH387yaBWfGbidkKtqM/

index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/leaflet.markercluster.js"></script>
3535

3636
<!-- Mapzen Search -->
37-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-geocoder-mapzen/1.8.1/leaflet-geocoder-mapzen.css">
38-
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-geocoder-mapzen/1.8.1/leaflet-geocoder-mapzen.js"></script>
37+
<link rel="stylesheet" href="scripts/leaflet-geocoder/leaflet-geocoder-mapzen.css">
38+
<script src="scripts/leaflet-geocoder/leaflet-geocoder-mapzen.js"></script>
3939

4040
<!-- Locate Control -->
4141
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-locatecontrol/0.60.0/L.Control.Locate.min.css" />

scripts/map.js

+35-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
$(window).on('load', function() {
22
var documentSettings = {};
3-
var markerColors = [];
3+
var markerColors = [];
44

55
var polygonSettings = [];
66
var polygonSheets = 1;
77
var currentPolygonSheet = 0;
88
var polygonsLegend;
99

10+
var completePoints = false;
11+
var completePolygons = false;
12+
var completePolylines = false;
13+
1014
/**
1115
* Returns an Awesome marker with specified parameters
1216
*/
@@ -251,10 +255,9 @@ $(window).on('load', function() {
251255
searching: false,
252256
columns: generateColumnsArray(),
253257
});
254-
255-
updateTable();
256258
}
257259

260+
completePoints = true;
258261
return group;
259262
}
260263

@@ -397,6 +400,8 @@ $(window).on('load', function() {
397400
if (legendPos == 'off') {
398401
$('.polygons-legend').hide();
399402
}
403+
404+
completePolygons = true;
400405
}
401406

402407
/**
@@ -565,6 +570,8 @@ $(window).on('load', function() {
565570
if (points.length > 0) {
566571
layers = determineLayers(points);
567572
group = mapPoints(points, layers);
573+
} else {
574+
completePoints = true;
568575
}
569576

570577
centerAndZoomMap(group);
@@ -573,11 +580,15 @@ $(window).on('load', function() {
573580
var polylines = mapData.sheets(constants.polylinesSheetName).elements;
574581
if (polylines.length > 0) {
575582
processPolylines(polylines);
583+
} else {
584+
completePolylines = true;
576585
}
577586

578587
// Add polygons
579588
if (getPolygonSetting(0, '_polygonsGeojsonURL')) {
580589
processPolygons();
590+
} else {
591+
completePolygons = true;
581592
}
582593

583594
// Add Mapzen search control
@@ -615,7 +626,7 @@ $(window).on('load', function() {
615626
// Change Map attribution to include author's info + urls
616627
changeAttribution();
617628

618-
// Generate icons for markers legend
629+
// Append icons to categories in markers legend
619630
$('#points-legend form label span').each(function(i) {
620631
var legendIcon = (markerColors[i].indexOf('.') > 0)
621632
? '<img src="' + markerColors[i] + '" class="markers-legend-icon">'
@@ -625,16 +636,24 @@ $(window).on('load', function() {
625636
$(this).prepend(legendIcon);
626637
});
627638

628-
// All processing has been done, so hide the loader and make the map visible
629-
$('#map').css('visibility', 'visible');
630-
$('.loader').hide();
639+
// When all processing is done, hide the loader and make the map visible
640+
showMap();
631641

632-
// Open intro popup window in the center of the map
633-
if (getSetting('_introPopupText') != '') {
634-
initIntroPopup(getSetting('_introPopupText'), map.getCenter());
635-
};
642+
function showMap() {
643+
if (completePoints && completePolylines && completePolygons) {
644+
$('#map').css('visibility', 'visible');
645+
$('.loader').hide();
636646

637-
togglePolygonLabels();
647+
// Open intro popup window in the center of the map
648+
if (getSetting('_introPopupText') != '') {
649+
initIntroPopup(getSetting('_introPopupText'), map.getCenter());
650+
};
651+
652+
togglePolygonLabels();
653+
} else {
654+
setTimeout(showMap, 50);
655+
}
656+
}
638657
}
639658

640659
/**
@@ -730,6 +749,10 @@ $(window).on('load', function() {
730749
});
731750
}
732751
}
752+
753+
if (p.length == index + 1) {
754+
completePolylines = true;
755+
}
733756
};
734757
}(i));
735758
}

0 commit comments

Comments
 (0)