Tag Archives: Javascript
New Lens Dijit for the ArcGIS API for JavaScript
Yesterday I added a new dijit to the ArcGIS API for JavaScript Code Gallery: the Lens Dijit. It could also be called an X-Ray dijit. Here’s a screen shot:

Everything you need to get started using it is in the ReadMe.txt included in the download but, if you just want to take it for a spin, you can try it here: lens dijit demo.
Please leave any feedback in the comments here or at the resource center.
Contributed by Derek Swingley.
Custom Objects in dojo.ItemFileReadStore: Using a Type Map
The GeoChalkboard Blog recently published a post about using the dojo.ItemFileReadStore (IFRS). That post does a good job of introducing and discussing basic usage of the ItemFileReadStore, but it leaves out one important aspect, the Type Map.
Natively, an IFRS allows you to store primitive JavaScript types such as strings and numbers. If you want to store custom objects within an IFRS, geometry for instance, then you need to tell dojo a little about the objects and provide some extra info in your JSON file.
You tell dojo about your custom objects through a Type Map. The documentation about Type Map is comprehensive and does a good job of explaining the various options. I recommend sticking with the simplified form. The Type Map itself is a property of an object that is passed into the IFSR constructor. In its simplest form, the value for Type Map is an object that contains custom type names as properties and constructor functions as values. Simple, right? The following example should clear up any confusion.
Here’s some code I used in a dijit I built to zoom to a specific state and/or county:
this.stateStore = new dojo.data.ItemFileReadStore({
url: dojo.moduleUrl(“apl.dijit.ZoomTo”, “data/states_wgs84.json”),
typeMap: { “Extent”: esri.geometry.Extent }
});
The code above is setting up an ItemFileReadStore from which you can retrieve extents. It would be nice if all you had to do was specify the Type Map, but, unfortunately, it’s not that simple. To successfully use custom types in an IFRS, you also need to specify the object type within your JSON. Each custom object needs two specific properties: _type and _value. _type has to match a property name in the Type Map object and _value is passed to the custom type constructor function. Here’s an excerpt from states_wgs84.json file:
{
“identifier”:“name”,
“label”:“name”,
“items”:[{
“name”:“Alabama”,
“abbr”:“AL”,
“fips”:“01″,
“extent”:{
“_type”:“Extent”,
“_value”:{
“xmin”:-88.4729522509999,
“ymin”:30.2336047200001,
“xmax”:-84.8940162469999,
“ymax”:35.0160337240001,
“spatialReference”:{“wkid”:4326}
}
}
}
}
Notice that the value for _type from the JSON file matches a property of the typeMap used in the IFRS constructor. Once you have custom types defined in a Type Map, and set the proper values for _type and _value, you can retrieve and use custom types like any other type coming from an ItemFileReadStore. The code below retrieves a single extent from the store using fetchByIdentity:
this.stateStore.fetchItemByIdentity({
identity: placeName, onItem: this.handleExtent, onError: this.oops
});
To see a complete working example of creating and using custom types in an ItemFileReadStore, see the ZoomTo.js file that is a part of the Zoom To State/County Dijit.
Contributed by Derek Swingley.