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

Local Geojson Layer doesn't show #193

Open
airbreizh opened this issue Jul 3, 2020 · 3 comments
Open

Local Geojson Layer doesn't show #193

airbreizh opened this issue Jul 3, 2020 · 3 comments

Comments

@airbreizh
Copy link

airbreizh commented Jul 3, 2020

Hello, I'm trying to show a local Geojson Layer in my map but it doesn't work.
I'm using Vue.js 2.x and the geojson file is in an "asset" folder inside the Vue project.
I tried the code below:

`<template>
          <MglMap
              :accessToken="accessToken"
              :mapStyle.sync="mapStyle"
              :zoom=9
              :center= [x,y]
              @load="onMapLoaded"
              :maxBounds="bounds"
              >
              <MglGeojsonLayer
              sourceId="myLayerSource"
              :source="myLayerSource"
              layerId="myLayer"
              :layer="myLayer"
              />
          </MglMap>
</template>
 
<script>
myLayerSource: {
      id: 'myLayerSource',
      type: 'geojson',
      data: '../assets/path_to_my_layer/myLayer.geojson'
    },
    myLayer: {
      id: 'myLayer',
      type: 'line',
      minzoom: 1,
      source: 'myLayerSource'
      paint: {
      'line-color': 'red',
       }
    }
</script>`

Does anybody has the same issue ?

@elC0mpa
Copy link

elC0mpa commented Jul 9, 2020

Are you sure the source is correctly added? If not, use the map.getSource(sourceId) method to verify this. This is the first thing I would check in tha case

@airbreizh
Copy link
Author

Thanks for your answer !
I listened to your tip and used the getSource method: the source seems to be corretly added.
I just have this warning message:

message: "Not Found"
name: "e"
stack: ""
status: 404
url: "http://localhost:8080/assets/path_to_my_layer/myLayer.geojson"
<prototype>: Object { … }

As I explained in my fist post, it's a geojson stored into the Vue project files so it should be showing ?

@elC0mpa
Copy link

elC0mpa commented Jul 16, 2020

Well, that warning message reflects some kind of error, but I am not sure about what to do. Do something, replace the path data of myLayerSource and just initialize the data object directly with the content of ../assets/path_to_my_layer/myLayer.geojson file. Take a look it the warning keep showing, I hope this could help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants