[Users] Get Position from Vectorlayer
Andreas Hocevar
ahocevar at opengeo.org
Tue Nov 22 12:54:03 CET 2011
Hi,
your problem is that there is no e.xy for the featureselected handler.
So instead of
map.getLonLatFromPixel(e.xy);
you will need a reference to your SelectFeature control (e.g.
selectFeature), and do
map.getLonLatFromPixel(selectFeature.handlers.feature.evt.xy);
Andreas.
On Tue, Nov 22, 2011 at 12:40 PM, Kai Volland <kaivolland at web.de> wrote:
> Hi,
>
> hmm it don't work for me.
>
> layer.map.getLonLatFromPixel(...); // --------> layer is not defined
> calpal.map.getLonLatFromPixel(...); // --------> is Null
> e.feature.layer.map.getLonLatFromPixel(...); // --------> is Null
> e.feature.getBounds().getCenterLonLat(); //-----------> e.feature.getBounds
> is not a function
>
> Here is my code. Maybe there is a problem i don't see.
>
> calpal.events.on({
> featureselected: function(e) {
> if(e.feature.attributes.count>1) {
> //map.zoomIn();
> if(map.getZoom()<8){
>
> map.moveTo(e.feature.getBounds().getCenterLonLat().transform(WGS84,
> mercator), map.zoom + 1);
> /*var pixel =
> calpal.map.getLonLatFromPixel(e.xy);
> pixel.transform(WGS84, mercator);
> map.moveTo(pixel, map.zoom + 1);*/
> }
> }
> else{
> calpalPopup(e.feature);
> }
> }
> })
>
>
> Kai
>
>
> PS: got an error with the geoext-list so the mail goes to you only.
>
> Am 21.11.2011 14:26, schrieb Andreas Hocevar:
>>
>> Hi,
>>
>> layer.map.getLonLatFromPixel(...);
>>
>> or
>>
>> feature.layer.map.getLonLatFromPixel(...);
>>
>> And instead of feature.lonlat try
>>
>> feature.getBounds().getCenterLonLat();
>>
>> Andreas.
>>
>> On Mon, Nov 21, 2011 at 1:46 PM, Kai Volland<kaivolland at web.de> wrote:
>>>
>>> And, how can i call it on the map and not on the vector layer?
>>> I also tried feature.lonlat but this is "null" too.
>>>
>>>
>>> Am 21.11.2011 12:34, schrieb Andreas Hocevar:
>>>>
>>>> Hi,
>>>>
>>>> you should be using the getLonLatFromPixel API method, although this
>>>> won't fix your issue. To fix your issue, make sure to really call it
>>>> on the map, not on the vector layer. And finally, it won't return
>>>> anything before the extent/center of the map has been set initially.
>>>>
>>>> Andreas.
>>>>
>>>> On Mon, Nov 21, 2011 at 11:58 AM, Kai Volland<kaivolland at web.de>
>>>> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> i get the error map.getLonLatFromViewPortPx is null when using it with
>>>>> a
>>>>> vectorlayer. Isn't it possible to use it it with a vectorlayer? And if
>>>>> it's not possible how to get the position of an vector item?
>>>>>
>>>>> (The idea is to zoom in when clicking on clustered vectoritems.)
>>>>>
>>>>> Kind regards
>>>>>
>>>>> Kai
>>>>> _______________________________________________
>>>>> Users mailing list
>>>>> Users at geoext.org
>>>>> http://www.geoext.org/cgi-bin/mailman/listinfo/users
>>>>>
>>>>
>>>
>>
>>
>
>
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list