Wednesday, May 19, 2010

Dojo generate colors

The one that I want is in

dojox.color.Generator.monochromatic ({ base:myColor, num:6 })
http://bugs.dojotoolkit.org/browser/dojox/trunk/color/Generator.js?rev=14628

This monochromatic function does NOT do what I want
dojo.require("dojox.color.Palette");
var colors = dojox.color.Palette.generators.monochromatic ({ base:myColor, num:6 });




Tuesday, May 18, 2010

Dojo How to ColorPalette + TooltipDialog + DropDownButton

function changeColor(selectColor) {
console.log("color: " + selectColor);
}

dojo.addOnLoad( function() {
var censusContainer = new dijit.layout.BorderContainer({
style: "width: 30%; height: 30%",
gutters: false,
design: "headline"
},"censusContainerId");


var paramsContent = new dijit.layout.ContentPane();
var colorPalette = new dijit.ColorPalette({onChange:changeColor});
var colorPalette2 = new dijit.ColorPalette({onChange:changeColor});
censusContainer.addChild(colorPalette);
var dropDownButton = new dijit.form.DropDownButton({label: "drop", dropDown: colorPalette2});
censusContainer.addChild(dropDownButton);
censusContainer.startup();
}

HTML:

<body class="tundra">
<div id="censusContainerId" region="top" >Region top</div>
<div dojoType="dijit.ColorPalette" onChange="changeColor"></div>
</body>

Thursday, May 13, 2010

Erlang parse file

Trying to parse csv file with the following contents

INTC,07-May-2010 16:51,21.31,21.31,21.31,21.31,200\n
INTC,07-May-2010 16:47,21.31,21.31,21.31,21.31,100\n
INTC,07-May-2010 16:42,21.31,21.31,21.31,21.31,300\n

The erlang code


getCompanyEff(Filename,Company) ->
{ok,Device} = file:open(Filename,read),
getLinesCompany(Device,[],Company).

getLinesCompany(Device,Accum,Company) ->
case io:get_line(Device,"") of
eof -> Accum;
Line ->
case regexp:first_match(Line, Company ++ ",*") of
{match,_,_} -> getLinesCompany(Device, [Line|Accum], Company);
nomatch -> getLinesCompany(Device, Accum, Company)
end
end.

and to execute:
erl> module:getCompanyEff("/path/to/file", "CompanyName").

Monday, May 10, 2010

HTML 5 postMessage (Cross-Domain Message) on Firefox 3.6.3

This only works in Firefox because IE uses attachEvent(). You can always use dojo.connect( window, 'message', func() ) so it works in Firefox and IE.

A (http://localhost/cross.htm) has an iframe containing B (http://otherdomain/cross.htm)

After the iframe is loaded in A, then a message is sent to it (containing string 'Hello'). The origin is checked in B, and if it matches an alert is displayed.

on A (http://localhost/cross.htm)
<script type="text/javascript">
function iframeload() {
var o = document.getElementById('crossid').contentWindow;
o.postMessage('Hello', "http://otherdomain/cross.htm");
}
</script>

<iframe id="crossid" onload="iframeload();" src="http://otherdomain/cross.htm" width="700px" height="700px">
</iframe>


on B (http://otherdomain/cross.htm)
window.addEventListener('message',function(e) {
if (e.origin == 'http://localhost') {
if (e.data == 'Hello') {
alert(e.data);
e.source.postMessage('Hello');
} else {
alert(e.data);
}
}
}, false);

Friday, May 7, 2010

Javascript for loop + closure

This for loop uses closure to get the value of i for every iteration.
Without closure, every element in divvar will get the last value of x(length-1) from iteration.

for( var i=0;i<divvar.length;i++ ) {
(
function(x) { // -> capture looping variable
divvar[x].onclick = function() {
console.debug("clicked:", x);
}
}
)(i); // -> pass in looping variable
}

Compare this to the standar loop without closure

for( var i=0;i<divvar.length;i++ ) {
divvar[i].onclick = function() {
console.debug("clicked:", i);
};
}

Or we can use dojo.forEach to fix this

Thursday, May 6, 2010

ESRI ArcXML get service info

HTTP POST to http://xxx/IMS/servlet/com.esri.esrimap.Esrimap?ServiceName=six_combo&CustomService=query

ARCXML service info:

<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<REQUEST>
<GET_SERVICE_INFO fields="false" envelope="false" renderer="false" extensions="true" acetateinfo="false" />
</REQUEST>
</ARCXML>

The response:
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<RESPONSE>
<SERVICEINFO>
<ENVIRONMENT>
<LOCALE language="en" country="AU" />
<UIFONT name="Arial" color="0,0,0" size="12" style="regular" />
<SEPARATORS cs=" " ts=";"/>
<CAPABILITIES forbidden="" disabledtypes="" returngeometry="xmlmode"/>
<SCREEN dpi="74"/>
</ENVIRONMENT>
<PROPERTIES>
<FEATURECOORDSYS string="GEOGCS["GCS_GDA_1994",DATUM["D_GDA_1994",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]" id="4283" />
<FILTERCOORDSYS string="GEOGCS["GCS_GDA_1994",DATUM["D_GDA_1994",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]" id="4283" />
<ENVELOPE minx="140.05983881892" miny="-37.740334035" maxx="154.575951211079" maxy="-27.924909045" name="Initial_Extent" />
<ENVELOPE minx="140.05983881892" miny="-37.740334035" maxx="154.575951211079" maxy="-27.924909045" name="Extent_Limit" />
<MAPUNITS units="decimal_degrees" />
<LEGEND/>
</PROPERTIES>
<LAYERINFO type="featureclass" visible="true" name="Suburb Labels" id="Suburb_Label_1" minscale="0.0000308686210057027" maxscale="0.000308686210057027">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.Suburb.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.suburbname" type="12" size="40" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.postcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.state" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Local Government Area Labels" id="LocalGovernmentArea_Label_1" minscale="0.000246948968045622" maxscale="0.000926058630171081">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.LocalGovernmentArea.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.lganame" type="12" size="60" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.councilname" type="12" size="80" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.abscode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.ltocode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.vgcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.wbcode" type="4" size="10" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="false" name="Locality Labels" id="Locality_Label_1" maxscale="0.0000000308686210057027">
<FCLASS type="point">
<FIELD name="delivsdm:geodb.placepoint.topoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.objectmoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.featuremoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.classsubtype" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.featurereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.attributereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.capturesourcecode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.capturemethodcode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.planimetricaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.placepoint.verticalaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.placepoint.operationalstatus" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.generalnameoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.generalname" type="12" size="50" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.alternativelabel" type="12" size="50" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.placetype" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.population" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.popsourcedate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.placesignificance" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
<EXTENSION type="StoredQuery">
<STOREDQUERIES>
<STOREDQUERY name="generalname">
<QUERY subfields="" where="generalname LIKE '[%var%]%'" >
</QUERY>
<SQVAR name="[%var%]" position="0">
<FIELD name="delivsdm:geodb.placepoint.generalname" type="12" />
</SQVAR>
</STOREDQUERY>
</STOREDQUERIES>
</EXTENSION>

</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Road Labels" id="RoadSegment_Label_1">
<FCLASS type="line">
<FIELD name="delivsdm:geodb.RoadSegment.topoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.objectmoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.featuremoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.classsubtype" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.featurereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.attributereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.capturesourcecode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.capturemethodcode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.planimetricaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.RoadSegment.verticalaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.RoadSegment.operationalstatus" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnameoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnamebase" type="12" size="50" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnametype" type="12" size="20" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnamesuffix" type="12" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.functionhierarchy" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadontype" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.surface" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.lanecount" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Town Labels" id="Town_Label_1" minscale="0.000246948968045622">
<FCLASS type="point">
<FIELD name="OBJECTID" type="8" size="10" precision="0" />
<FIELD name="NAME" type="12" size="32" precision="0" />
<FIELD name="POSTCODE" type="8" size="10" precision="0" />
<FIELD name="POP_1996" type="8" size="10" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="#ID#" type="-99" size="16" precision="0" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Local Government Area" id="LocalGovernmentArea_1" minscale="0.000246948968045622" maxscale="0.000926058630171081">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.LocalGovernmentArea.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.lganame" type="12" size="60" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.councilname" type="12" size="80" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.abscode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.ltocode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.vgcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.wbcode" type="4" size="10" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Suburbs" id="Suburb_1" minscale="0.0000308686210057027" maxscale="0.000308686210057027">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.Suburb.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.suburbname" type="12" size="40" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.postcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.state" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Topographic Map Index" id="Topographic_Map_Index_1" maxscale="0.000617372420114054">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.topomapindex.mapnumber" type="12" size="10" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.maptitle" type="12" size="32" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.nominalpresentationscale" type="4" size="8" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.mgazone" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.hundredkmapnumber" type="4" size="5" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.presentationformat" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="NSW Border" id="Border_1" minscale="0.00617372420114054">
<FCLASS type="line">
<FIELD name="IGDS_CLASS" type="4" size="5" precision="0" />
<FIELD name="IGDS_COLOR" type="4" size="5" precision="0" />
<FIELD name="GROUP" type="4" size="5" precision="0" />
<FIELD name="IGDS_STYLE" type="4" size="5" precision="0" />
<FIELD name="WEIGHT" type="4" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="#ID#" type="-99" size="16" precision="0" />
</FCLASS>
</LAYERINFO>

</SERVICEINFO>
</RESPONSE>
</ARCXML>