0

I need to add graphics to a map with class.

Is it any sample or way to save it to IndexedDB or Local Storage ?

I tried to use offline-editor-js but this library don´t offer possibility to save graphics.

1
require([
        "esri/map", 
        "esri/toolbars/draw",
        "esri/layers/GraphicsLayer", 
        "esri/symbols/SimpleFillSymbol", 
        "esri/graphic", 
        "dojo/domReady!"
      ], function(
        Map, Draw,
        GraphicsLayer, SimpleFillSymbol, 
        Graphic
      ) {
        map = new Map("mapDiv", {
          basemap: "streets",
          center: [-25.312, 34.307],
          zoom: 3
        });

        var tempLayer = new GraphicsLayer();
        map.addLayer(tempLayer)
        if(localStorage.features != undefined){
        JSON.parse(localStorage.features).forEach(function(featureJson){
        tempLayer.add(new Graphic(featureJson));
        })
        }

        var tool = new Draw(map);
        tool.on("draw-end",function(evt){
        var graphic= new Graphic(evt.geometry,new SimpleFillSymbol());
        tempLayer.add(graphic)
        var graphics =[];
        if(localStorage.features != undefined){
        graphics = JSON.parse(localStorage.features)
        }
        graphics.push(graphic.toJson());
        localStorage.features=JSON.stringify(graphics);
        })
        tool.activate(Draw.POLYGON)




      });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.