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

Usage with Typescript #14

Closed
Ferouk opened this issue Aug 3, 2017 · 10 comments
Closed

Usage with Typescript #14

Ferouk opened this issue Aug 3, 2017 · 10 comments
Labels

Comments

@Ferouk
Copy link

Ferouk commented Aug 3, 2017

I'm currently working on an ionic2 project (Typescript) that use leaflet v1.1.0 as a map. This plugin was very useful for me in previous projects (JavaScript). I'm asking how can I use it with my typescript code? Basically, How to define it in typescript? Thanks

@Ferouk Ferouk changed the title Usage in typescript Usage with Typescript Aug 3, 2017
@bbecquet
Copy link
Owner

bbecquet commented Aug 3, 2017

Hi Ferouk,

Thanks for using this plugin, glad to know it's useful to you :)
I've never used TypeScript first-hand myself. But if I'm not mistaken, TypeScript is only a superset of Javascript which basically adds annotations, so any valid JS code is supposed to be valid TypeScript as well. So I guess it should work as-is. But I've not tested it so I may completely overlook some problems.

Can you describe the problems or incompatibilities you encounter?

@Ferouk
Copy link
Author

Ferouk commented Aug 3, 2017

Hi bbecquet,
Thanks for the quick reply.

In order to resolve leaflet rotateMarker in Typescript, a Typings definition is required otherwise it won't be imported to the project properly. I tried to create a typings definition but I failed mainly because of the L.Marker.include().

The issue is that the class Marker in The "official" Leaflet typings can't be extended, it has to be overriden.

I suggest a modular approach. I mean var L.RotatedMarker= L.Marker.extend().

@bbecquet
Copy link
Owner

bbecquet commented Aug 6, 2017

Ok, this is exactly what was suggested in this previous issue #11.

I personally liked the way Leaflet classes can be dynamically extended without having to create a new class, but maybe it's not suited to big real-life projects. And I understand how it conflicts with the static typing approach.

I guess I'll do the shift to the modular approach when I have some time soon. After that, if you want to add a TypeScript def file to the project, I would be happy to accept a PR :)

@MaddyMastering
Copy link

I am trying to migrate from angular 1 to angular 2 and was successful in creating definitely typed files for other leaflet plugins. But this one seems to be very confusing. It would be very helpful if anyone has any of using this in typescript project.

@Ferouk
Copy link
Author

Ferouk commented Nov 22, 2017

@bbecquet I'll be glad to help

@MaddyMastering A temporary alternative to migrate is by using L.divIcon with inline css
https://stackoverflow.com/a/45506208/2897052

@blueromans
Copy link

same issue on ionic project with leaflet.

@badis
Copy link

badis commented Mar 16, 2018

How about writing a type definition file. this article looks interesting: https://peter.grman.at/how-to-write-typescript-definition-files/

@afeezaziz
Copy link

Hi @Ferouk , have you managed to get a workaround for this? I am using Typescript and Angular too.

@Ferouk
Copy link
Author

Ferouk commented Apr 10, 2018

@afeezaziz I've used L.divIcon instead with style attribute to control the icon rotation. This is an example:

L.divIcon({
  html: '<img class="leaflet-marker-icon leaflet-zoom-animated" src="[icon image URL]" style="width: [icon width]px; height: [icon height]px;transform: rotate([angle]deg);  -webkit-transform: rotate([angle]deg); -moz-transform:rotate([angle]deg);" />'
});

@f-loris
Copy link

f-loris commented Jun 27, 2018

I think this issue is already solved. Type defintions are provided here: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/leaflet-rotatedmarker

See my answer on stackoverflow: https://stackoverflow.com/questions/45479872/leaflet-map-rotated-marker-for-ionic2-typescript/51063718#51063718

@Ferouk Ferouk closed this as completed Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants