?
Solved

Openlayers - zooming to show multiple co-ordinates

Posted on 2014-11-10
1
Medium Priority
?
259 Views
Last Modified: 2014-11-16
I have a bunch of co-ordinates, and i was the map to show them all on screen
Currently, its just zooming on one asset

I've, found some code, but it just seems to zoom into the sea (near gulf of guinea), i'm not sure if this is due to a map type?

Here is my code that i've been using to try and get it working


var selectedAsset_Coordinates = {};
var markers = new OpenLayers.Layer.Markers("Markers");

selectedAsset_Coordinates.d = [];

for (var kd = 0; kd < currentlySelectedCheckboxes.length; kd++) {
            
            k = currentlySelectedCheckboxes[kd];

            selectedAsset_Coordinates.d[k] = {};
            selectedAsset_Coordinates.d[k].vLongitude = obj.d[k].vLongitude;
            selectedAsset_Coordinates.d[k].vLatitude = obj.d[k].vLatitude;

            var _CurrentRowId = $("#chk" + k)[0].id.substring(3, $("#chk" + k)[0].id.length);
            if ($.inArray(parseInt(_CurrentRowId), currentlySelectedCheckboxes) > -1) {
                var point = new OpenLayers.Geometry.Point(obj.d[k].vLongitude, obj.d[k].vLatitude);
                point = point.transform(WGS84, map.getProjectionObject());

                var pointFeature = new OpenLayers.Feature.Vector(point, null, null);

                var _str = ShortAssetName(obj.d[k].vDeviceName);

                pointFeature.attributes = {
                    label: _str,
                    favColor: 'blue', //favorite color
                    align: "cm",
                    labelAlign: "cm",
                    AssetID: obj.d[k].vpkDeviceID
                };


                flagLayer.addFeatures([pointFeature]);  // this code for showing tooltip


                //map.setCenter(new OpenLayers.LonLat(obj.d[k].vLongitude, obj.d[k].vLatitude).transform(WGS84, map.getProjectionObject()), map.getZoom());


            var ipoint = new OpenLayers.Geometry.Point(obj.d[k].vLongitude, obj.d[k].vLatitude);
            ipoint = ipoint.transform(WGS84, map.getProjectionObject());

           var ipointFeature = new OpenLayers.Feature.Vector(ipoint, null, null);

            ipointFeature.attributes = {
                icon: maparrow + obj.d[k].vImage,
                label: obj.d[k].vDeviceName,
                radius: 1,
                date: recevedtime,
                Ignition: obj.d[k].bIsIgnitionOn,
                Latitude: obj.d[k].vLatitude,
                Longitude: obj.d[k].vLongitude,
                AssetName: obj.d[k].vDeviceName,
                DriverId: obj.d[k].DriverId,
                AssetPhotoName: obj.d[k].AssetPhotoName,
                iTrackerType: obj.d[k].iTrackerType,
                FuelVoltage: obj.d[k].FuelVoltage,
                Drivername: obj.d[k].Drivername,
                DriverPhoto: obj.d[k].DriverPhoto,
                Speed: obj.d[k].vVehicleSpeed,
                AssetID: obj.d[k].vpkDeviceID,
                ipkAssetID: parseInt(obj.d[k].ipkDeviceID, "10")
            };

            markerLayer.addFeatures([ipointFeature]);


            markerLayer.addFeatures([ipointFeature]);
            MselectControl.select(this.markerLayer.features[kd]); }
            map.addLayer(markers);
           var size = new OpenLayers.Size(25, 25);
            var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
            var icon = new OpenLayers.Icon('http://www.openlayers.org/api/img/zoom-world-mini.png', size, offset);
            markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(selectedAsset_Coordinates.d[k].vLongitude,            
selectedAsset_Coordinates.d[k].vLatitude), icon));

}

    //zoom to multiple co-ordinates
    map.zoomToExtent(markers.getDataExtent());
  

Open in new window



as i said above, it zooms to the sea and not the co-ordinates
is there a better way/ other way/ error above?

HELP!
0
Comment
Question by:websss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40445982
I can't really test this but it looks like, on line 72 you forgot to transform the marker positions like you did on the other points, should probably be:
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(selectedAsset_Coordinates.d[k].vLongitude, selectedAsset_Coordinates.d[k].vLatitude).transform(WGS84, map.getProjectionObject()), icon));
//                                                                                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Open in new window

When I say I can't really test, I did test with some standard code, taking out a lot of your code and using mock-up data that hopefully comes close to what you're trying to do and got it to work with that extra transform, see: http://schutt.nl/ee/Q_28554813
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Starting up a Project

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question