-
-
Notifications
You must be signed in to change notification settings - Fork 364
[Map] Leaflet vector layers #2445
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
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);
}
} |
@Kocal The rawOptions on pre-connect is very useful. This is not working right now right? |
We tried to implement esri vector layers with the code below. This works but there are some drawbacks. We must remove the default layer to activate the vector layer. This now loads some tilelayers till the request is cancelled. Is there some other option possible hat we don't add the default tile layer? import { Controller } from "@hotwired/stimulus";
/* stimulusFetch: 'lazy' */
export default class extends Controller {
connect() {
this.element.addEventListener('ux:map:connect', this._onConnect);
}
disconnect() {
this.element.removeEventListener('ux:map:connect', this._onConnect);
}
async _onConnect(event) {
const { map } = event.detail;
// use async because else we miss the connect event. Also set esri vars
window.L.esri = await import("esri-leaflet/dist/esri-leaflet");
window.L.esri.Vector = await import("esri-leaflet-vector/dist/esri-leaflet-vector");
map.removeLayer(Object.values(map._layers)[0]); // Remove default layer else vector map is not working
L.esri.Vector.vectorBasemapLayer('ArcGIS:Streets', {
apikey: "<key>",
}).addTo(map);
}
} |
If I understand correctly, that's because the current and default behavior is that a Then, I think the best we can do is to make $map = new Map();
$map->options(new LeafletOptions(tileLayer: null));
// or:
$map->options(new LeafletOptions(tileLayer: false)); It will requires some updates in following files:
Up for a PR? |
@Kocal Yes, will try to create a PR. |
This PR was merged into the 2.x branch. Discussion ---------- [Map] Optional leaflet tilelayer | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Comment from #2445 (comment) Commits ------- 90d40b3 [Map] Optional leaflet tilelayer
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: