简体   繁体   中英

Add markers to mapbox map via JS API then “save”

what I'm trying to do is simple (i think):

I can add markers to my mapbox map via the JS api, and on a different device, I want to be able to view those new markers i've added. I cant for the life of me figure out how to get the added markers to "save" to my map so that they are always there. Does anyone have any ideas? Here's what i've got now

var map = L.mapbox.map('map', 'myuser.mymapid')
        .setView([35.673343,139.710388], 6);

  L.mapbox.featureLayer({
      type: 'Feature',
      geometry: {
          type: 'Point',
          coordinates: [35, 77]
      },
      properties: {
          title: 'mytitle',
          description: 'desc',
          'marker-size': 'large',
          'marker-color': '#f0a'
      }
  }).addTo(map);

Inferring from the plans page , MapBox does not provide write-back storage of any kind for editing maps. They do provide storage for TileMill tiles , which - in my layman's understanding - allows you to overlay completely custom map tiles onto existing cartography.

Some additional hints that MapBox doesn't provide any write-back functionality (besides the glaring lack of any mention of it on the website) , would be things like this example document which uses Firebase to keep the map in sync between users. Granted, the example is marked as API v1.0.0, but since they're still on version 1.xx, I think you can infer that there's currently no write-back functionality.

Your best bet is probably to use your own back-end database to store new pins / layers, or use something like Firebase to keep the new data in sync for you. For what it's worth, I've used Firebase and it's extremely easy and extremely fast.

Looking at your center coords, you may have your coordinates in the featureLayer reversed. Try flipping those to have your marker land closer to your center.

  coordinates: [77, 35]

The order for GeoJSON coordinates is easting, northing, altitude.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM