Map JS API
See how to update the same item position in real-time
This sample introduces an approach to update the position of items already on the map. No needs to remove and re-add the item to refresh the location.
<html> <head> <script src="https://rasters.io/maps/v0.8.0/rasters.map.min.js"></script> </head> <body> <script> var map; var MapToken = "Enter your MapToken here"; Rasters.Map.OnReady = function () { map = new Rasters.Map({ container: 'Map', // container id url: 'https://api.rasters.io/', mapKey: "", authenticationMode: Rasters.AuthenticationMode.MapToken, token: MapToken }); map.OnReady = OnConnectHander; } function OnConnectHander() { map.SetPosition(-71.2170425, 46.810457, 6); addGeoJSON(); window.setInterval(SetLivePosition, 500); } function SetLivePosition() { var item = map.GetItemById("Point1"); item.geometry.coordinates[0] += 0.01; //map.SetItemPosition(item.id, item.geometry.coordinates); // OR map.AddMapItems(item); } function addGeoJSON() { var geoJson = { "type": "Feature", "id": "Point1", "properties": { "name": "Point1", "style.icon": "star" }, "geometry": { "type": "Point", "coordinates": [-71.217042, 46.810457] } }; // Set the last parameter to false (is Not Locked) map.AddMapItems(geoJson, "", false, false); } </script> <div id="Map" style='width: 100%; height: 100%;'></div> </body> </html>
Help Guide Powered by Documentor