Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up and isolate js code in files select.html and listeners.html #1291

Merged
merged 12 commits into from
Dec 10, 2022
18 changes: 18 additions & 0 deletions examples/js/listeners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let map;

(function(){
map = L.map('map').setView([51.505, -0.09], 13);
map.addGoogleMutant();

map.whenReady(function() {
img = L.distortableImageOverlay('example.jpg', {
selected: true,
}).addTo(map);

// Wait until image is loaded before setting up DOM element listeners
L.DomEvent.on(img.getElement(), 'load', function() {
L.DomEvent.on(img, 'edit', function() { alert('edited'); });
L.DomEvent.on(img.getElement(), 'mouseup touchend', function() { alert('edited'); });
});
});
})();
59 changes: 59 additions & 0 deletions examples/js/select.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
let map;

(function(){
map = L.map('map').setView([51.505, -0.09], 13);
map.addGoogleMutant();

map.whenReady(function() {
img = L.distortableImageOverlay('example.jpg', {
corners: [
L.latLng(51.52, -0.14),
L.latLng(51.52,-0.10),
L.latLng(51.50, -0.14),
L.latLng(51.50,-0.10),
],
mode: 'lock',
});

// create a second image
img2 = L.distortableImageOverlay('example.jpg', {
corners: [
L.latLng(51.51, -0.20),
L.latLng(51.51,-0.16),
L.latLng(51.49, -0.21),
L.latLng(51.49,-0.17),
],
mode: 'freeRotate',
suppressToolbar: true,
});

img3 = L.distortableImageOverlay('example.jpg', {
corners: [
L.latLng(51.50, -0.13),
L.latLng(51.50,-0.09),
L.latLng(51.48, -0.14),
L.latLng(51.48,-0.10),
],
actions: [L.DistortAction, L.FreeRotateAction, L.LockAction, L.OpacityAction, L.DeleteAction, L.StackAction],
});

img4 = L.distortableImageOverlay('example.jpg', {
actions: [L.ScaleAction, L.DistortAction, L.RotateAction, L.FreeRotateAction, L.LockAction, L.OpacityAction, L.DeleteAction, L.StackAction],
corners: [
L.latLng(51.51, -0.07),
L.latLng(51.51,-0.03),
L.latLng(51.49, -0.08),
L.latLng(51.49,-0.04),
]
});

imgGroup = L.distortableCollection().addTo(map);

/* TODO: make an addLayers func */
imgGroup.addLayer(img);
imgGroup.addLayer(img4);
imgGroup.addLayer(img2);
imgGroup.addLayer(img3);
});
})();
=======
segun-codes marked this conversation as resolved.
Show resolved Hide resolved
let map;

(function(){
Expand Down
22 changes: 2 additions & 20 deletions examples/listeners.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script src="../node_modules/leaflet/dist/leaflet.js" type="text/javascript" charset="utf-8"></script>
<script src="../dist/vendor.js"></script>
<script src="../dist/leaflet.distortableimage.js"></script>
<script src="./js/listeners.js" defer></script>
</head>
<body style="margin:0;">

Expand All @@ -21,25 +22,6 @@
</form>

<div id="map" style="width:100%; height:100%; position:absolute; top:0;"></div>

</body>
<script>
let map;

(function(){
map = L.map('map').setView([51.505, -0.09], 13);
map.addGoogleMutant();

map.whenReady(function() {
img = L.distortableImageOverlay('example.jpg', {
selected: true,
}).addTo(map);

// Wait until image is loaded before setting up DOM element listeners
L.DomEvent.on(img.getElement(), 'load', function() {
L.DomEvent.on(img, 'edit', function() { alert('edited'); });
L.DomEvent.on(img.getElement(), 'mouseup touchend', function() { alert('edited'); });
});
});
})();
</script>
</html>
17 changes: 17 additions & 0 deletions src/edit/iconsets/IconSet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* this is the baseclass other IconSets inherit from,
* we don't use it directly */
L.IconSet = L.Class.extend({

_svg: '<svg xmlns="http://www.w3.org/2000/svg">',

_symbols: '',

render() {
this.addSymbols(this._symbols);
return this._svg;
},

addSymbols(symbols) {
this._svg += symbols;
},
});
7 changes: 7 additions & 0 deletions src/edit/iconsets/KeymapperIconSet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
L.KeymapperIconSet = L.IconSet.extend({

_symbols:
// eslint-disable-next-line max-len
segun-codes marked this conversation as resolved.
Show resolved Hide resolved
'<symbol viewBox="0 0 25 25" id="keyboard_open"><path d="M12 23l4-4H8l4 4zm7-15h-2V6h2v2zm0 3h-2V9h2v2zm-3-3h-2V6h2v2zm0 3h-2V9h2v2zm0 4H8v-2h8v2zM7 8H5V6h2v2zm0 3H5V9h2v2zm1-2h2v2H8V9zm0-3h2v2H8V6zm3 3h2v2h-2V9zm0-3h2v2h-2V6zm9-3H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"/></symbol>',

});
23 changes: 23 additions & 0 deletions src/edit/iconsets/ToolbarIconSet.js

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