javascript - Updating map attributes -


i´m trying "ease" mapbox map. pretty sure not specific mapbox.js

basically take map via id , call properties on it, these won´t update map.

i can recreate problem in dom console on taking example.

a busy cat

on app have function updates map, , use same logic: map via identifier , call properties move it.

what missing?

thanks!!

in code have yui autocomplete field, , neither of "on" or "after" work:

function addmeasureinput() { yui().use("autocomplete", "autocomplete-filters", "autocomplete-highlighters", function(y) {     //skin     y.one('body').addclass('yui3-skin-sam');     //array source     var locs = getlocationslist();     y.one('#ac-input').plug(y.plugin.autocomplete, {         resultfilters: 'phrasematch',         resulthighlighter: 'phrasematch',         source: locs,         on: {             select: function() {              console.log("location selected!");                              var map = mapbox.map('map');              map.ease.location({ lat: 0, lon: 0 }).zoom(5).optimal();             }         },         after: {             select: function(o) {                 var map = mapbox.map('map');                 map.ease.location({ lat: 0, lon: 0 }).zoom(5).optimal();                 showloc(o.result.raw);             }         }     }); }); 

};

mapbox.map('map') must create map: http://mapbox.com/mapbox.js/api/v0.6.7/#mapbox.map:

create map on current page.  

when map dom element document.getelementbyid('map') don't found links mapbox map instance. can't exist map instance dom. it's bad idea save own javascript objects in dom elements.

better save map instance javascript object. mapbox exaple http://mapbox.com/mapbox.js/example/optimal-easing/ map instance stored in window object. can write:

map.ease.location({ lat: 38.9, lon: -77 }).zoom(10).optimal(); 

or

map.zoomin(); 

and etc. it's work.

upd: understood better use lazy initialization:

var map = null;  function ease (lat, lon, zoom) {     if (!map) {         map = mapbox.map('map');     }     map.ease.location({ lat: lat, lon: lon }).zoom(zoom).optimal(); }  function addmeasureinput() {     yui().use("autocomplete", "autocomplete-filters",               "autocomplete-highlighters", function(y) {         //skin         y.one('body').addclass('yui3-skin-sam');         //array source         var locs = getlocationslist();         y.one('#ac-input').plug(y.plugin.autocomplete, {             resultfilters: 'phrasematch',             resulthighlighter: 'phrasematch',             source: locs,             on: {                 select: function() {                     console.log("location selected!");                     ease(0, 0, 5);                 }             },             after: {                 select: function(o) {                     ease(0, 0, 5);                     showloc(o.result.raw);                 }             }         }     }); }); 

but map initialization it's slow operation (create dom, load tiles), better initialize map once , not on demand.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -