-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
[Map] Leaflet vector layers #2445
Comments
Hi, I think yes, see https://symfony.com/bundles/ux-map/current/index.html#interact-with-the-map
|
Hi @Kocal! I tried what you explained with another leaflet plugin ( import {Controller} from "@hotwired/stimulus";
import 'leaflet-editable';
// listen to the event ux:map:connect and pre-connect to set editable: true
_onConnect(event) {
const { map, L } = event.detail;
// L.Editable does not exist
} import {Controller} from "@hotwired/stimulus";
import 'leaflet-editable';
// listen to the event ux:map:connect and pre-connect to set editable: true
_onConnect(event) {
const { map } = event.detail;
const L = window.L;
// L.Editable exists
} Do you see why it's not the same variable ? |
Hi, and sorry for the late reply. It is not the same variable because:
Which can be equivalent, but not identical: _onConnect(event) {
console.log(event.detail.L); // Module
console.log(window.L); // Object
console.log(event.detail.L === window.L);
} If I edit the Leaflet I'm not sure how to fix it correctly, because here both syntax are valid. |
I don't know the implication of this change but reading the Leaflet doc for creating a plugin it says Then I guess most of the plugin creator will follow this. |
Well, yes and no, When you type To me, the |
Also, note that even if we change |
@Kocal about the options : setting a custom options is not easy since the PHP class Thank you very much for this explanations it's now very clear and I hope this issue will helps other devs creating their own Stimulus Controller. |
For the export default class extends Controller {
connect() {
this.element.addEventListener('ux:map:pre-connect', this._onPreConnect);
}
disconnect() {
this.element.removeEventListener('ux:map:pre-connect', this._onPreConnect);
}
_onPreConnect(event) {
event.detail.rawOptions = {
editable: true,
// other custom options if you want
}
}
} About importing Leaflet inside a ESM context, I am unable to see on leaflet documentation what is the "official": Finally, for the plugin API issues, to me a good plugin should not automatically register itself, but explicitly by passing a import {Controller} from "@hotwired/stimulus";
import {install as installLeafletEditable} 'leaflet-editable';
export default class extends Controller {
connect() {
// ...
this.element.addEventListener('ux:map:connect', this._onConnect);
}
disconnect() {
// ...
this.element.removeEventListener('ux:map:connect', this._onConnect);
}
_onConnect(event) {
installLeafletEditable(event.detail.L);
}
} |
Is it possible to use vector layers like https://github.com/Esri/esri-leaflet-vector? What is the best way to implement this?
The text was updated successfully, but these errors were encountered: