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

flutter-mapbox-gl doesnt work on the web #514

Closed
maliknajjar opened this issue Jan 29, 2021 · 29 comments · Fixed by #551
Closed

flutter-mapbox-gl doesnt work on the web #514

maliknajjar opened this issue Jan 29, 2021 · 29 comments · Fixed by #551
Labels
help wanted Extra attention is needed

Comments

@maliknajjar
Copy link

in pub.dev android, ios and web is considered supported, but when i use my app in the web the mapbox map doesn't work.
is it me or its just not supported for the web?

@Shailevy
Copy link

It works fine on the web, you just need to add a few lines to your index.html, it's described in the js integration guide

@maliknajjar
Copy link
Author

It works fine on the web, you just need to add a few lines to your index.html, it's described in the js integration guide

thank you so much Shailevy for responding .. can you please send me the link of the js integration guide?
I didn't find it

@maliknajjar
Copy link
Author

maliknajjar commented Jan 29, 2021

Is this what you are talking about Mr. Shailevy ?
https://docs.mapbox.com/mapbox-gl-js/api/
image

@Shailevy
Copy link

Yes.. That's it

@maliknajjar
Copy link
Author

maliknajjar commented Jan 29, 2021

I included the JavaScript and CSS files in the head but still doesn't work.
in this path -> {appName}/web/index.html
that's weird
image

@Shailevy
Copy link

What's the errors you see in the browser console? Does the same code work on iOS/Android?

@maliknajjar
Copy link
Author

maliknajjar commented Jan 29, 2021

there is nothing in the browser console and yes the map works fine on android

@maliknajjar
Copy link
Author

maliknajjar commented Jan 29, 2021

when I included js integration code part which is inside the body tag .. it worked fine
but its not working from the flutter-mapbox-gl side

@maliknajjar
Copy link
Author

do I have to make some type of cleaning or refreshing .. could that be the problem ?

@iampato
Copy link

iampato commented Jan 29, 2021

If you updated your flutter version to 1.26.0-12.0pre or higher flutter web removed the shadowRoot 'thing' which this plugin still refers to in order to append the html platform view in:
mapbox_gl_web/lib/src/mapbox_map_controller.dart

 HtmlElement e = document.getElementsByTagName('flt-platform-view')[index]
        as HtmlElement;

    LinkElement link = LinkElement();
    link.href =
        'https://api.tiles.mapbox.com/mapbox-gl-js/v1.6.1/mapbox-gl.css';
    link.rel = 'stylesheet';
    e.shadowRoot.append(link);

@maliknajjar
Copy link
Author

what's the solution ?

@iampato
Copy link

iampato commented Jan 31, 2021

Downgrade to a lower version in the beta version

@alparslana
Copy link

alparslana commented Feb 9, 2021

I encounter the same problem. Running Flutter 1.26.0-17.3.pre • channel beta. It was working fine before one of my flutter upgrades, and now it is broken.

Downgrading to a previous version of flutter is neither an elegant solution nor sustainable. Are there any plans to bring a structural fix to mapbox package to be in compliance with newer versions of flutter SDK?

@tobrun tobrun added the help wanted Extra attention is needed label Feb 12, 2021
@tobrun tobrun pinned this issue Feb 12, 2021
@tobrun
Copy link
Collaborator

tobrun commented Feb 12, 2021

appreciate any help we can get on this issue! I'm personally not very familiar with flutter web and web in general.

@iampato
Copy link

iampato commented Feb 13, 2021

Great I will take a look 👍

@maliknajjar
Copy link
Author

was this probleme fixed guys?

@joranmulderij
Copy link

Still waiting.

@qcasey
Copy link

qcasey commented Feb 26, 2021

I still have the issue even with the PR build above, does that fix it for anyone else?

@shroff
Copy link
Collaborator

shroff commented Feb 28, 2021

@qcasey could you please comment on #551 describing what you observed?

@alparslana
Copy link

Hi all,

I have tried out the update of @shroff and it seems to fix the problem on web version. I will not be able to comment on performance/effectivity however the functionality is back with this update. I have manually updated my local mapbox_map_controller.dart file and now I see the map in my browser. Kudos @shroff

@maliknajjar
Copy link
Author

so when this fix pull request will be merged to the master ?

@joranmulderij
Copy link

I found that (in Flutter 2) it gets stuck in the loop

Future<void> _addStylesheetToShadowRoot() async {
  int index = -1;
  // Keeps running forever!
  while (index == -1) {
    index = document.getElementsByTagName('flt-platform-view').length - 1;
    await Future.delayed(Duration(milliseconds: 10));
  }
  HtmlElement e = document.getElementsByTagName('flt-platform-view')[index]
      as HtmlElement;

  LinkElement link = LinkElement();
  link.href =
      'https://api.tiles.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css';
  link.rel = 'stylesheet';
  e.shadowRoot.append(link);

  await link.onLoad.first;
}

Removing all the contents from the function results in the map showing, but with the wrong size.

I hope someone can solve this issue.

@alparslana
Copy link

@joranmulderij can you try out the update @shroff has done?

Here: https://github.com/tobrun/flutter-mapbox-gl/pull/551/files

Let us know if it works for you. In his implementation the loop is removed with updated _addStylesheetToShadowRoot method contents.

@joranmulderij
Copy link

Yes. @shoff's solution works. Just tried it.
I hope it will be merged soon.

@qcasey
Copy link

qcasey commented Mar 5, 2021

I'm not sure what issue I was having before, but I can also confirm the webcss branch fixes this issue beautifully on Flutter 2.0.1

@joranmulderij
Copy link

#551 is just trying to merge the webcss branch into main.
You can indeed also just use the webcss branch.

@maliknajjar
Copy link
Author

maliknajjar commented Mar 6, 2021

I tried to change the file but it gave me this error
image

@joranmulderij
Copy link

joranmulderij commented Mar 6, 2021

Put this in your pubspec.yaml. No file editing needed.

dependencies:
  mapbox_gl:
    git:
      url: https://github.com/tobrun/flutter-mapbox-gl.git
      ref: webcss
  # Other dependencies...

@maliknajjar
Copy link
Author

maliknajjar commented Mar 6, 2021

nice it's working .. it didn't work for me in the first time but then I changed the --web-renderer to html and it's working now
this is the command for people who had the same issue -> "flutter run -d chrome --web-renderer html"

shroff added a commit that referenced this issue Mar 14, 2021
@m0nac0 m0nac0 unpinned this issue Mar 15, 2021
m0nac0 referenced this issue in maplibre/flutter-maplibre-gl Oct 5, 2021
* Change iOS dependencies to Maplibre

* Update MapLibre dependency

* Set iOS deployment target to 9.0

* fix Podfile syntax

* Podfile: comment out platform key

* set MinimumOSVersion: 9.0; uncomment Podfile:platform key

* CI: verbose iOS build

* Update IPHONEOS_DEPLOYMENT_TARGET to 9.0

* [web] Fix Mapbox GL JS CSS embedding (#551)

Fixes #514

* iOS: update Podfile to fix CI (#565)

* Update deprecated patterns to fix CI static analysis  (#568)

* [offline][android] Add setOffline method (#537)

* Add batch mode of screen location (#554)

* Change SDK version of example

* Add toScreenLocationBatch

* Add custom marker example

* Define which annotations consume tap events (Multiple annotations on click area management) (#575)

* AnnotationClickOrder working (not order but activation/desactivation)

* Switch to annotationConsumeTapEvents method

* Remove failed offline pack downloads (#583)

When a download error occurs, the app is informed through the channel so
that it can display an appropriate error. However, on subsequent calls
to list the available downloaded packs it is surprising to see that the
failed region download is present as if it had been downloaded.

There is no way for the app to repair this incomplete pack. Therefore,
it seems much better to clean up the failed download as soon as it's
detected. If any tiles were downloaded they will be at least temporarily
in the cache and available to a future re-download attempt. This follows
the same logic as failures caused by hitting the tile limit.

* [docs] update changelog for v0.11.0 release (#584)

* [release] update pubspec for v0.11.0 (#585)

* add annotationOrder to web (#588)

* emits onTap only for the feature above the others (#589)

* [web] update image dependency to ^3.0.2 (#598)

* [android] bumpn release to v9.6.0 and use SDK registry distribution mechanism (#489)

* [iOS][Android] Batch creation/removal for circles, fills and lines (#576)

* added batch mode

* added circle support

* added remove features

* removed test code

* inital android implementation

* added documentation

* removed unused code

* add batch example

* fix feature mamager on release build (#593)

* Improve description to enable location features (#596)

* Update to Mapbox-iOS-SDK 6.3.0 (#513)

* Update to Mapbox-iOS-SDK 6.3.0

The 6.0.0 upgrade had no breaking changes:

> This major release does not include any breaking changes to public
> APIs. We are treating this release as a SEMVER major change because
> our installation instructions have changed.
https://github.com/mapbox/mapbox-gl-native-ios/releases/tag/ios-v6.0.0

I did however need to cast the `accessToken` as a `String` to satisfy
the compiler after this upgrade.

Prior to the upgrade I was seeing crashes from this bug, which was fixed
in 6.2: mapbox/mapbox-gl-native-ios#485

So far I don't see any issues at all after the upgrade.

Developers will need to configure their access token in order to fetch
the mapbox sdk for this an future versions, described here:
https://docs.mapbox.com/ios/maps/guides/install/

* Setup .netrc for iOS mapbox sdk download

Writes a `~/.netrc` file containing the credentials needed to download
the iOS mapbox sdk. I'm not experienced with github workflow so I'm just
hoping that I can write to the home directory of whatever container it
runs in. This should allow curl to find and use the given credentials.

Co-authored-by: tobrun <tobrun.van.nuland@gmail.com>

* [docs] update changeog for v0.12.0 (#602)

* [release] v0.12.0 (#603)

* fix: update MapLibre dependencies and imports.

* fix: update String cast

* Fix maplibre dependency (org.maplibre.gl has migrated to maven central)

* Update iOS MapLibre to 5.12.0

* Bump MapLibreAnnotationExtension to 0.0.1-beta.3

* Update maplibre_gl.podspec

* [iOS] - Fix compilation issue with maplibre 5.12.0

* Update CHANGELOG.md

Co-authored-by: m0nac0 <58807793+m0nac0@users.noreply.github.com>
Co-authored-by: shroff <ashroff6@gmail.com>
Co-authored-by: Yoshikage Ochi <yoshikage.ochi@mapbox.com>
Co-authored-by: Stephane Trepier <stephane.trepier@gmail.com>
Co-authored-by: Nathan <nathan@transit.app>
Co-authored-by: Tobrun <tobrun.van.nuland@gmail.com>
Co-authored-by: Andrea Valenzano <andr3a689@gmail.com>
Co-authored-by: Ahmed <ahm322@hotmail.com>
Co-authored-by: Felix Horvat <felix.horvat@ocell.aero>
Co-authored-by: Ettore Atalan <atalanttore@googlemail.com>
Co-authored-by: Konrad Koeppe <konrad.koeppe@bareways.com>
Co-authored-by: Vincent Berthet <vincent@web-74.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants