Skip to content

Commit

Permalink
feat: Added separate debugger class so we can keep debugging statemen…
Browse files Browse the repository at this point in the history
…t but not increase the plug-in size too much.
  • Loading branch information
toepoke committed Mar 3, 2024
1 parent a67a4a9 commit 02103c7
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Local-Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ Google now charges for API use. To avoid charges no [working] API keys are prov
- Ensure you add _credentials_ to ensure you aren't charged from unscrupulous actors reusing your key for their own projects
- Perform a search on your mapsed repo for **[YOUR-API-KEY]** and add your own key

### Debugging

To enable debug helper class, include the **mapsed.debug.js** file on the page.


2 changes: 2 additions & 0 deletions examples/06-full-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ function fullWindowExample(e) {
e.preventDefault();

$.fn.mapsed({
debugger: new MapsedDebug(),

// Map initialisation options to pass onto Google Maps
mapOptions: {
zoom: 15,
Expand Down
1 change: 1 addition & 0 deletions full-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

<!-- Mapsed JavaScript -->
<script src="mapsed.js"></script>
<script src="mapsed.debug.js"></script>

<!-- Examples JavaScript -->
<script src="examples/mapsed-storage.js"></script>
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ <h3>Issues and Assistance</h3>

<!-- Mapsed JavaScript -->
<script src="mapsed.js"></script>
<script src="mapsed.debug.js"></script>

<!-- Examples JavaScript -->
<script src="examples/mapsed-storage.js"></script>
Expand Down
52 changes: 52 additions & 0 deletions mapsed.debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Class to aid debugging without increasing the size of the core
* library too much. Including this file on the web page enables
* the improved debugging experience.
*/
class MapsedDebug {
#polygon = null;

logMarker(mLatName, mLat, x1Name, x1, x2Name, x2) {
console.log(mLatName, mLat, x1Name, x1, x2Name, x2);
}

logger(...args) {
console.log(args);
}

clearLog() {
console.clear();
}

drawNearbyPolygon(onMap, boundaryDef) {
const markerCoords = [
{ lat: boundaryDef.x1, lng: boundaryDef.y1 },
{ lat: boundaryDef.x2, lng: boundaryDef.y1 },
{ lat: boundaryDef.x2, lng: boundaryDef.y2 },
{ lat: boundaryDef.x1, lng: boundaryDef.y2 },

{ lat: boundaryDef.x1, lng: boundaryDef.y1 },
];

// Construct the polygon.
this.#polygon = new google.maps.Polygon({
paths: markerCoords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35,
});

this.#polygon.setMap(onMap);
}

clearPolygon() {
if (this.#polygon != null) {
this.#polygon.setMap(null);
this.#polygon = null;
}

}

}
8 changes: 7 additions & 1 deletion mapsed.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@
// When adding custom places, mapsed will expand the map to show all places
// Usually this is what you'd want, but sometimes you may want to focus on a particular area
// "forceCenter" will override the default behaviour and centre where specified in the options
forceCenter: false
forceCenter: false,

// Helper to aid debugging mapsed itself (you must include mapsed.dev.js to use this)
// ... (mainly to aid mapsed development)
debugger: null

}, options || {});

Expand Down Expand Up @@ -511,6 +515,7 @@
var currMarker = this;
closeTooltips();

settings?.debugger?.logger("_pagedMarkers", _pagedMarkers, "_currMarkerPage", _currMarkerPage);
if (currMarker.details.markerType == "new") {
canEdit = true;
if (settings.onAdd) {
Expand Down Expand Up @@ -801,6 +806,7 @@
* for places in their back-end which fall onto the map at the current boundary and zoom level.
*/
function gmIdle() {
settings?.debugger?.clearPolygon();
var bounds = _gMap.getBounds();

if (bounds) {
Expand Down

0 comments on commit 02103c7

Please sign in to comment.