Infrastructure Map Server Forum
Welcome to Autodesk’s Infrastructure Map Server Forums. Share your knowledge, ask questions, and explore popular Infrastructure Map Server topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can you create an MGSelection object?

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
334 Views, 7 Replies

Can you create an MGSelection object?

When there are no selected map features, the getSelection method and the
Selection property point to a null object so I can't use either of these to
add objects to the current selection.

Is it possible to create an MGSelection object? I thought createObject might
do it but it appears that it won't create these objects. Any ideas?

--
There are 10 kinds of people:
Those who understand binary and those who don't
http://www.acadx.com
http://vbxtender.sourceforge.net
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

"Frank Oquendo wrote"> When there are no selected map features, the
getSelection method and the
> Selection property point to a null object so I can't use either of these
to
> add objects to the current selection.
>
> Is it possible to create an MGSelection object? I thought createObject
might
> do it but it appears that it won't create these objects. Any ideas?
>

Frank,

createObject will only create an MGCollection, MGExtenex, or MGPoint. If
you want an MGSelection, getSelection will return an empty MGSelection but
you can still add objects to it - or create an MGCollection object, add
objects to it, then add the MGCollection to the MGSelection.

down & dirty..

Private Sub Command1_Click()
Dim sel As MGSelection
Dim col As MGCollection
Dim L As MGMapLayer

Set L = MGMap1.getMapLayer("General")
Set col = MGMap1.CreateObject("MGCollection")

col.Add L.getMapObject("02-021-A-B1-0007-00") 'object Key

Set sel = MGMap1.getSelection 'get current selection - even if empty

MsgBox sel.NumObjects '=0

sel.addObjectsEx col, True

MsgBox sel.NumObjects '=1

End Sub

HTH,

Scott
Message 3 of 8
Anonymous
in reply to: Anonymous

Scott Friedrich had this to say:

> If you want an MGSelection, getSelection will return an empty
> MGSelection but you can still add objects to it

That's what I understood as well but it isn't working. In my JavaScript, I
call map.getSelection().addObject() and I get an error telling me that
map.getSelection is null or not an object. This happens without fail
whenever there are no objects selected.

--
There are 10 kinds of people:
Those who understand binary and those who don't
http://www.acadx.com
http://vbxtender.sourceforge.net
Message 4 of 8
Anonymous
in reply to: Anonymous

"Frank Oquendo wrote "
> That's what I understood as well but it isn't working. In my JavaScript, I
> call map.getSelection().addObject() and I get an error telling me that
> map.getSelection is null or not an object. This happens without fail
> whenever there are no objects selected.

Frank,

I have duplicated your problem - try these two approaches - they work.

function addObj1()
{
var map = getMap();
var l = map.getMapLayer("General");
var sel = map.getSelection();
sel.addObject(l.getMapObject("02-021-A-B1-0007-00"),true);
}

Or,

function addObj2()
{
var map = getMap();
var l = map.getMapLayer("General");
var obj = l.getMapObject("02-021-A-B1-0007-00");
var sel = map.getSelection();
sel.addObject(obj,true);
}

Good Luck,

Scott
Message 5 of 8
Anonymous
in reply to: Anonymous

Scott Friedrich had this to say:

> I have duplicated your problem - try these two approaches - they work.

Scott,

Thanks for the help. Unfortunately, nothing seems to help. Below is the code
I'm using. I finally wrapped the selection code in an if statement just to
avoid the error. Needless to say, the code inside the if block never
executes.

function zoomParcel(pin) {
var map = getMap();
if (!map.isBusy()) {
var sel = map.getSelection();
map.zoomGoToLocation("Parcel Search", pin, 10000);
if (sel != null) {
var layer = map.getMapLayer("Parcels");
var obj = layer.getMapObject(pin);
sel.addObject(obj, true);
}
}
}

--
There are 10 kinds of people:
Those who understand binary and those who don't
http://www.acadx.com
http://vbxtender.sourceforge.net
Message 6 of 8
Anonymous
in reply to: Anonymous

Frank,

I tested your code and got irregular results - sometime it worked, other
times it did not. It ignored the IF.. statement randomly, I think this may
be the result of zoomGoToLocation putting map into a busy state -
setAutoRefresh is ignored by it so that won't work. It looks like this
function is to obviously zoom to the object, but then add it to the
selection set so the user can see it as selected. If that's the case, add
the object to the selection before calling zoomGoToLocation - this always
works.

function zoomParcel(pin)
{
var map = getMap();

if (!map.isBusy())
{
var sel = map.getSelection();
sel.clear();//this is optional - use only if you want the current pin in
the selection
var layer = map.getMapLayer("Parcels");
var obj = layer.getMapObject(pin);
sel.addObject(obj, true);

map.zoomGoToLocation("Parcel Search", pin, 10000);

}

Scott





"Frank Oquendo" wrote in message
news:DB118E81DAEDF5C67F3B249A20CACFB2@in.WebX.maYIadrTaRb...
> Scott Friedrich had this to say:
>
> > I have duplicated your problem - try these two approaches - they work.
>
> Scott,
>
> Thanks for the help. Unfortunately, nothing seems to help. Below is the
code
> I'm using. I finally wrapped the selection code in an if statement just to
> avoid the error. Needless to say, the code inside the if block never
> executes.
>
> function zoomParcel(pin) {
> var map = getMap();
> if (!map.isBusy()) {
> var sel = map.getSelection();
> map.zoomGoToLocation("Parcel Search", pin, 10000);
> if (sel != null) {
> var layer = map.getMapLayer("Parcels");
> var obj = layer.getMapObject(pin);
> sel.addObject(obj, true);
> }
> }
> }
>
> --
> There are 10 kinds of people:
> Those who understand binary and those who don't
> http://www.acadx.com
> http://vbxtender.sourceforge.net
>
>
Message 7 of 8
Anonymous
in reply to: Anonymous

Scott Friedrich had this to say:

> If
> that's the case, add the object to the selection before calling
> zoomGoToLocation - this always works.

*Sigh*. Still no joy. Although your mention of the map busy state did cause
me to remember a detail which might be important in solving this puzzle: the
code is called in response to the onViewChanged event.

The idea is to allow the client to launch the map with a parcel pre-selected
and centered on the screen. The centering works, the selection does not.

--
There are 10 kinds of people:
Those who understand binary and those who don't
http://www.acadx.com
http://vbxtender.sourceforge.net
Message 8 of 8
Anonymous
in reply to: Anonymous

"Frank Oquendo wrote" > *Sigh*. Still no joy. Although your mention of the
map busy state did cause
> me to remember a detail which might be important in solving this puzzle:
the
> code is called in response to the onViewChanged event.

One way to accomplish is to add additional code to the onViewChanged event
to make the selection after the zoomGoToLocation centers the map for you. I
use global variables to track the initial MapLoading (the onMapLoaded
doesn't work! , and zoomGoToLocation wouldn't work in this event anyways),
and a global variable to go ahead and add the object to the selection set.
Oh, and a var for the pin.

Something like this..

function onViewChanged(map)
//global Init = "y"
//global addToSel = '"n"
//global pin = object key

{
if (Init == "y")//fired after map initially loaded
{
map.zoomGoToLocation("Parcels", pin, 10000);
Init = "n" //this will keep the zoom from firing any longer
addToSel = "Y"
}
else//fired after the above zoom is done
{
if (addToSel == "Y")
{
var map = getMap();
var l = map.getMapLayer("Parcels");
var obj = l.getMapObject(pin);
var sel = map.getSelection();
sel.clear();
sel.addObject(obj,true);
addToSel = "n"//won't fire any longer
}
else
{
return;
}
}
}

...ain't this fun? There may be other ways to do this, but I have been
using this method for a while with good results.

Scott

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report