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

Add event to get reference on drawcontrol #49

Merged
merged 2 commits into from
Dec 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion leaflet/static/leaflet/leaflet.forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ L.GeometryField = L.Class.extend({
map.addLayer(this.drawnItems);

// Initialize the draw control and pass it the FeatureGroup of editable layers
var drawControl = new L.Control.Draw(this._controlDrawOptions());
var drawControl = map.drawControl = new L.Control.Draw(this._controlDrawOptions());

if (this.options.modifiable) {
map.addControl(drawControl);
Expand All @@ -114,6 +114,8 @@ L.GeometryField = L.Class.extend({
}

this.load();

map.fire('map:loadfield', {field: this, fieldid: this.options.fieldid});
},

load: function () {
Expand Down
2 changes: 2 additions & 0 deletions leaflet/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<script src="../../node_modules/django-leaflet-tests/node_modules/leaflet/build/deps.js"></script>
<script src="../../node_modules/django-leaflet-tests/node_modules/leaflet/debug/leaflet-include.js"></script>

<script src="../../leaflet/static/leaflet/draw/leaflet.draw.js"></script>

<script src="../../leaflet/static/leaflet/leaflet.extras.js"></script>
<script src="../../leaflet/static/leaflet/leaflet.forms.js"></script>

Expand Down
3 changes: 2 additions & 1 deletion leaflet/tests/test.extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ describe('Test Leaflet Extras', function() {
describe('L.Map.DjangoMap', function() {

it("should not fail with minimal options", function(done) {
new L.Map.DjangoMap('map', {djoptions: {layers: []}});
var map = new L.Map.DjangoMap('map', {djoptions: {layers: []}});
map.remove();
done();
});

Expand Down
25 changes: 25 additions & 0 deletions leaflet/tests/test.forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,30 @@ describe('Test Leaflet Forms', function() {
assert.isTrue(field.options.is_point);
done();
});

describe('Events', function () {

var map;

beforeEach(function () {
map = L.map('map').fitWorld();
});

afterEach(function () {
map.remove();
});

it("should emit event when field is loaded", function (done) {
var field = new L.GeometryField({geom_type: 'GEOMETRY', fieldid: 'formfield'});
map.on('map:loadfield', function (e) {
assert.equal(e.target, map);
assert.equal(e.field, field);
assert.equal(e.fieldid, 'formfield');
assert.isDefined(map.drawControl);
done();
});
field.addTo(map);
});
});
});
});