Mabox-gl-js Marker translated position












0















I'm trying to use https://www.mapbox.com/mapbox-gl-js/api/#marker



const el = document.createElement('div');
el.className = 'marker';

const marker = new mapboxgl.Marker(el, {
color: '#FFFFFF',
draggable: true,
offset: [0, 0],
})
.setLngLat([0, 0])
.addTo(this.map);


Which is connected to map:



this.map = new mapboxgl.Map({
container: this.mapEl,
center: [this.props.longitude, this.props.latitude],
zoom: this.props.zoom,
maxZoom: 17,
pitch: this.props.pitch || 0,
bearing: this.props.bearing || 0,
style: getStyleByTheme(this.props.theme),
preserveDrawingBuffer: true,
attributionControl: false,
});


The problem is that the marker position is being 'translated' with huge values: transform: translate(-50%, -50%) translate(225173px, 75290px);



By debugging this calculation I found out that the problem is occuring at this line: https://github.com/mapbox/mapbox-gl-js/blob/e0c4d4679d06be7c0f51970b26a184f8d9ed6d5b/src/ui/marker.js#L338



So I went further:



this.map.project(marker.getLngLat())._add(marker.getOffset())


returns {x: 225173.2033574923, y: 75289.74831606582}



And by removing function _add call and outputting the value of this.map.project(marker.getLngLat()) I get the same value.



So, this actually happens here: https://github.com/mapbox/mapbox-gl-js/blob/e0c4d4679d06be7c0f51970b26a184f8d9ed6d5b/src/ui/map.js#L616



Which leads me to https://github.com/mapbox/mapbox-gl-js/blob/7b4be8d247c7351df83316eed0f8d20d3a184722/src/geo/transform.js#L314



Ohh my, I'm lost now



What could be the issue here? Is it the Mapbox-gl-js, my map setup or event html structure?



Please help. :)










share|improve this question





























    0















    I'm trying to use https://www.mapbox.com/mapbox-gl-js/api/#marker



    const el = document.createElement('div');
    el.className = 'marker';

    const marker = new mapboxgl.Marker(el, {
    color: '#FFFFFF',
    draggable: true,
    offset: [0, 0],
    })
    .setLngLat([0, 0])
    .addTo(this.map);


    Which is connected to map:



    this.map = new mapboxgl.Map({
    container: this.mapEl,
    center: [this.props.longitude, this.props.latitude],
    zoom: this.props.zoom,
    maxZoom: 17,
    pitch: this.props.pitch || 0,
    bearing: this.props.bearing || 0,
    style: getStyleByTheme(this.props.theme),
    preserveDrawingBuffer: true,
    attributionControl: false,
    });


    The problem is that the marker position is being 'translated' with huge values: transform: translate(-50%, -50%) translate(225173px, 75290px);



    By debugging this calculation I found out that the problem is occuring at this line: https://github.com/mapbox/mapbox-gl-js/blob/e0c4d4679d06be7c0f51970b26a184f8d9ed6d5b/src/ui/marker.js#L338



    So I went further:



    this.map.project(marker.getLngLat())._add(marker.getOffset())


    returns {x: 225173.2033574923, y: 75289.74831606582}



    And by removing function _add call and outputting the value of this.map.project(marker.getLngLat()) I get the same value.



    So, this actually happens here: https://github.com/mapbox/mapbox-gl-js/blob/e0c4d4679d06be7c0f51970b26a184f8d9ed6d5b/src/ui/map.js#L616



    Which leads me to https://github.com/mapbox/mapbox-gl-js/blob/7b4be8d247c7351df83316eed0f8d20d3a184722/src/geo/transform.js#L314



    Ohh my, I'm lost now



    What could be the issue here? Is it the Mapbox-gl-js, my map setup or event html structure?



    Please help. :)










    share|improve this question



























      0












      0








      0








      I'm trying to use https://www.mapbox.com/mapbox-gl-js/api/#marker



      const el = document.createElement('div');
      el.className = 'marker';

      const marker = new mapboxgl.Marker(el, {
      color: '#FFFFFF',
      draggable: true,
      offset: [0, 0],
      })
      .setLngLat([0, 0])
      .addTo(this.map);


      Which is connected to map:



      this.map = new mapboxgl.Map({
      container: this.mapEl,
      center: [this.props.longitude, this.props.latitude],
      zoom: this.props.zoom,
      maxZoom: 17,
      pitch: this.props.pitch || 0,
      bearing: this.props.bearing || 0,
      style: getStyleByTheme(this.props.theme),
      preserveDrawingBuffer: true,
      attributionControl: false,
      });


      The problem is that the marker position is being 'translated' with huge values: transform: translate(-50%, -50%) translate(225173px, 75290px);



      By debugging this calculation I found out that the problem is occuring at this line: https://github.com/mapbox/mapbox-gl-js/blob/e0c4d4679d06be7c0f51970b26a184f8d9ed6d5b/src/ui/marker.js#L338



      So I went further:



      this.map.project(marker.getLngLat())._add(marker.getOffset())


      returns {x: 225173.2033574923, y: 75289.74831606582}



      And by removing function _add call and outputting the value of this.map.project(marker.getLngLat()) I get the same value.



      So, this actually happens here: https://github.com/mapbox/mapbox-gl-js/blob/e0c4d4679d06be7c0f51970b26a184f8d9ed6d5b/src/ui/map.js#L616



      Which leads me to https://github.com/mapbox/mapbox-gl-js/blob/7b4be8d247c7351df83316eed0f8d20d3a184722/src/geo/transform.js#L314



      Ohh my, I'm lost now



      What could be the issue here? Is it the Mapbox-gl-js, my map setup or event html structure?



      Please help. :)










      share|improve this question
















      I'm trying to use https://www.mapbox.com/mapbox-gl-js/api/#marker



      const el = document.createElement('div');
      el.className = 'marker';

      const marker = new mapboxgl.Marker(el, {
      color: '#FFFFFF',
      draggable: true,
      offset: [0, 0],
      })
      .setLngLat([0, 0])
      .addTo(this.map);


      Which is connected to map:



      this.map = new mapboxgl.Map({
      container: this.mapEl,
      center: [this.props.longitude, this.props.latitude],
      zoom: this.props.zoom,
      maxZoom: 17,
      pitch: this.props.pitch || 0,
      bearing: this.props.bearing || 0,
      style: getStyleByTheme(this.props.theme),
      preserveDrawingBuffer: true,
      attributionControl: false,
      });


      The problem is that the marker position is being 'translated' with huge values: transform: translate(-50%, -50%) translate(225173px, 75290px);



      By debugging this calculation I found out that the problem is occuring at this line: https://github.com/mapbox/mapbox-gl-js/blob/e0c4d4679d06be7c0f51970b26a184f8d9ed6d5b/src/ui/marker.js#L338



      So I went further:



      this.map.project(marker.getLngLat())._add(marker.getOffset())


      returns {x: 225173.2033574923, y: 75289.74831606582}



      And by removing function _add call and outputting the value of this.map.project(marker.getLngLat()) I get the same value.



      So, this actually happens here: https://github.com/mapbox/mapbox-gl-js/blob/e0c4d4679d06be7c0f51970b26a184f8d9ed6d5b/src/ui/map.js#L616



      Which leads me to https://github.com/mapbox/mapbox-gl-js/blob/7b4be8d247c7351df83316eed0f8d20d3a184722/src/geo/transform.js#L314



      Ohh my, I'm lost now



      What could be the issue here? Is it the Mapbox-gl-js, my map setup or event html structure?



      Please help. :)







      javascript mapbox-gl-js mapbox-marker






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 8:37







      R-J

















      asked Nov 15 '18 at 8:16









      R-JR-J

      665515




      665515
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Ok, i figured it out - It was totally my fault!



          As documentation says here - https://www.mapbox.com/mapbox-gl-js/api/#map#project
          "Returns a Point representing pixel coordinates, relative to the map's container, that correspond to the specified geographical location."



          I was using .setLngLat([0, 0]) but the map actually pointed to different location.



          By using, the same LngLat as the map is centered with, I fixed the issue. :)






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315013%2fmabox-gl-js-marker-translated-position%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Ok, i figured it out - It was totally my fault!



            As documentation says here - https://www.mapbox.com/mapbox-gl-js/api/#map#project
            "Returns a Point representing pixel coordinates, relative to the map's container, that correspond to the specified geographical location."



            I was using .setLngLat([0, 0]) but the map actually pointed to different location.



            By using, the same LngLat as the map is centered with, I fixed the issue. :)






            share|improve this answer




























              0














              Ok, i figured it out - It was totally my fault!



              As documentation says here - https://www.mapbox.com/mapbox-gl-js/api/#map#project
              "Returns a Point representing pixel coordinates, relative to the map's container, that correspond to the specified geographical location."



              I was using .setLngLat([0, 0]) but the map actually pointed to different location.



              By using, the same LngLat as the map is centered with, I fixed the issue. :)






              share|improve this answer


























                0












                0








                0







                Ok, i figured it out - It was totally my fault!



                As documentation says here - https://www.mapbox.com/mapbox-gl-js/api/#map#project
                "Returns a Point representing pixel coordinates, relative to the map's container, that correspond to the specified geographical location."



                I was using .setLngLat([0, 0]) but the map actually pointed to different location.



                By using, the same LngLat as the map is centered with, I fixed the issue. :)






                share|improve this answer













                Ok, i figured it out - It was totally my fault!



                As documentation says here - https://www.mapbox.com/mapbox-gl-js/api/#map#project
                "Returns a Point representing pixel coordinates, relative to the map's container, that correspond to the specified geographical location."



                I was using .setLngLat([0, 0]) but the map actually pointed to different location.



                By using, the same LngLat as the map is centered with, I fixed the issue. :)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 8:30









                R-JR-J

                665515




                665515
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315013%2fmabox-gl-js-marker-translated-position%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Error while running script in elastic search , gateway timeout

                    Adding quotations to stringified JSON object values