Adding custom markers dynamically to map using OpenLayers

后端 未结 2 2028
天涯浪人
天涯浪人 2021-02-04 10:03

I would like to let users add custom markers on a map with a description for each marker. Any tips, links to any tutorials would be really useful.

2条回答
  •  佛祖请我去吃肉
    2021-02-04 10:36

    i tried @Fran 's solution but it didnt work for me. so i adapted this example from openlayers so that i could accomplish 2 things:

    1. save latitude and longitude of marker position
    2. place a marker by clicking on the openlayers map

      
      
        
          
          
          
          MousePosition Control
          
          
          
          
          
      
        
          

      MousePosition Control

      coordinate

      Click on map and create marker


      see how, even though we did NOT transform [lonlat],
      it was nevertheless transformed

    there is something that you need to be aware of regarding the TRANSFORM method for LonLat as used in this simple example: when you apply [ .transform(projection1, projection2) ] to any LonLat, ALL LonLat objects are transformed.

    play around with the order of certain commands and you will see what i mean.

    for draggable markers, this example has it all

提交回复
热议问题