Add custom Control
If I see correctly the .js main file I declare custom controls like that:
...,
customControls : [
L.mapbox.geocoderControl('foursquare.map-ikj05elx'),
L.control.locate({
setView: true,
locateOptions: {maxZoom: 10}
})
],...
Which I would traditionally declare like:
map.addControl( L.mapbox.geocoderControl('foursquare.map-ikj05elx') )
.addControl( L.control.locate({
setView: true,
locateOptions: {maxZoom: 10} })
)
However it doesn't work. Do I do something wrong?
have a look at pull request https://github.com/tombatossals/angular-leaflet-directive/pull/114
controller
$scope.controls = {
custom: []
};
var MyControl = L.control();
MyControl.setPosition('bottomleft');
MyControl.onAdd = function () {
var className = 'leaflet-control-my-location',
container = L.DomUtil.create('div', className + ' leaflet-bar');
return container;
}
map.controls.custom.push(MyControl);
html
<leaflet controls="controls"></leaflet>
For anyone who's interested, a 3rd-party control such as leaflet-locatecontrol can be added like so:
Controller
$scope.controls = {
custom: [
L.control.locate({ follow: true })
]
};
HTML
<leaflet controls="controls"></leaflet>
Hey @porjo I'm trying to add leaflet-locatecontrol as you suggested but I get this error:
TypeError: Cannot read property 'custom' of undefined
Any idea what I'm doing wrong?
HTML
<leaflet defaults="map.defaults"
controls="controls"
center="map.center"
markers="markers">
</leaflet>
Controller
$scope.map = {
defaults: {
maxZoom: 18,
minZoom: 11
},
center: {
lat: 40.055048,
lng: 17.976894,
zoom: 15
}
};
$scope.markers = {};
$scope.controls = {
custom: []
};
leafletData.getMap().then(function(map) {
map.controls.custom.push(L.control.locate({
follow: true
}));
});
My solution to get the sidebar control working was to change the angular-leaflet-directive code itself: see #362 and https://github.com/tombatossals/angular-leaflet-directive/blob/master/src/directives/controls.js#L18
@tonyrh sorry my code was wrong. I've updated the post.
@BergWerkGIS Would you please elaborate a little on your solution? Although adapting the controls directive I can't get the sidebar to work properly. Thanks in advance
Old issue, code has changed a lot since this, closing. Please reply if you think this should be reopened. Thanks.
This should be reopened https://github.com/tombatossals/angular-leaflet-directive/issues/929
I worked this out by commenting the following lines. if (!isValidControlType(controlType)) { $log.error(errorHeader + ' Invalid control type: ' + controlType + '.'); return; }
OR may be just add "custom" in controlTypes array around line 284.