Monday, November 2, 2015

kmeans + Openstreet /үргэлжлэл/

Өмнөх постонд оруулсан Pokemon уудын байршил болон тоглогчдын байршлыг openstreet дээр байршуулав


    map = new OpenLayers.Map("mapdiv");
    map.addLayer(new OpenLayers.Layer.OSM());

    var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
    var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
    var size = new OpenLayers.Size(21,25);
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
    var zoom=9;
 
    var markers = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markers);
<?php
//clusteriin tseguuded marker zooh
$mar = 1; //icon uud solihod ashiglav
foreach ($clusterdata as $key => $value) {
  foreach ($value as $key => $v) {
    echo 'markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat('.$v[1].','.$v[0].').transform(fromProjection,toProjection), new OpenLayers.Icon("img/marker'.$mar.'.png", size, offset)));';
  }
  $mar++;
}
$centerlat=0;
$centerlng = 0;
//centroiduudiig haruulah
foreach ($centroids as $key => $value) {
  echo 'markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat('.$value[1].','.$value[0].').transform(fromProjection,toProjection), new OpenLayers.Icon("img/star.png", size, offset)));';
  $centerlat += $value[0];
  $centerlng += $value[1];
}

//map centert haruulah
echo 'var lonLat = new OpenLayers.LonLat( '.$centerlng/$k.','.$centerlat/$k.' )
          .transform(new OpenLayers.Projection("EPSG:4326"), 
            map.getProjectionObject()
          );
  map.setCenter (lonLat, zoom);';
?>  


Гаралт нь


Од гарсан хэсэгт покемонууд гарч ирэх харгалзах тоглогчдод байршлыг нь явуулна.

No comments:

Post a Comment