[Chameleon] Problem with adding points using CWCJSAPI

Jimmy Lam j.lam at i-real.nl
Thu Apr 20 09:56:43 EDT 2006


I'm working on a Chameleon client with the ability to add points to a 
database. To draw points on the map, I'm using CWCJSAPI since I thought 
it would be easier to add functionality this way than creating a widget 
of my own. For now, I've used a stripped down version of 
sample_enhanced.html as the template and chameleon.map as map file. The 
code below is what I've added to the template. The essentials like the 2 
mandatory tags for CWCJSAPI, onload() and other html tags are omitted 
for clarity's sake. Basicly, there are 2 buttons, 1 adds a layer, 
another registers MOUSE_CLICKED. After pressing the "new layer" button, 
the page refreshes and a layer named "test" is added to the legend. By 
clicking on the "add point" button, I should be able to add a point when 
clicking inside the map. Unfortunately, nothing is drawn.
A few notes:
- Creating a new layer will add it to the MapObject, numlayer gets 
incremented by 1, GetLayerByName("test") will return a LayerObject. 
GetType returns POINT, GetStatus returns ON
- Clicking inside the map will create points. AddPoint returns true.
- I tried turning all layers in the map file off so the newly created 
layer would be the only one on, but it didn't help.
- For every point I create, an error is found in the ErrorReport widget 
saying "ERROR: InitDefaults didn't call base class InitDefaults in 
widget locate". I have not used the Locate widget in my template.
- Calling __CWCMapObject's CreateNewLayer does not update the 
DrawLayerOrder. The array returned by GetDrawLayerOrder has size 11 
while numlayer is 12. I tried to manually add the layer by creating a 
new array with size+1, copying the old array into it and use 
SetLayerDrawingOrder but this didn't fix it.
Am I overseeing something?


Jimmy Lam

    function myMouseClicked() {
        if(MapWinsideMap()) {
            mouseClickedX = goCWCJSAPI.mouseclick[0]; mouseClickedY = 
            po = new CWCPoint();
            aGeoCoord = goCWCJSAPI.oMap.Pix2Geo(mouseClickedX, 
            po.x = aGeoCoord[0];   po.y = aGeoCoord[1];
            po.symbol = 6;  po.symbol_colour ="255,0,0";   
po.symbol_size = 20; po.symbol_outlinecolour = "255,255,255"; 
po.font_size="GIANT"; po.font_colour="255,255,255";
            if(goCWCJSAPI.oMap.AddPoint("test", po)) {
                alert("Point("+po.x+"," +po.y+") added.");
            else {
    function addPoint() {
        goCWCJSAPI.RegisterEvent( MOUSE_CLICKED, "myMouseClicked");
    function newLayer() {
    <INPUT TYPE="BUTTON" OnClick="addPoint()"  value="add point">
    <INPUT TYPE="BUTTON" OnClick="newLayer()"  value="new layer">

More information about the Chameleon mailing list