Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have markers on pressing to which popup has to be brought. how to make it? (coordinates of markers undertake from a DB)

var map;
var markers;


function ejecutar() {
    init(3);
    //loadMarkers();
}
function init(b,kor_1,kor_2) {
    if (b == 3) {
        map = new OpenLayers.Map("basicMap", {
            controls: [
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar(),
                new OpenLayers.Control.LayerSwitcher(),
                new OpenLayers.Control.Attribution()],
            maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
            maxResolution: 156543.0399,
            numZoomLevels: 2,
            units: 'm',
            projection: new OpenLayers.Projection("EPSG:900913"),
            displayProjection: new OpenLayers.Projection("EPSG:4326")
        });
    }

    layerMapnik = new OpenLayers.Layer.OSM.Mapnik("MapaCiudad");
    map.addLayer(layerMapnik);
    var lonLat = new OpenLayers.LonLat(50.5206298828125, 55.15881723298661).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
    //map.setCenter(new OpenLayers.LonLat(-3.862788677215576, 43.4669443349282) // Center of the map
    map.zoomTo(9);
    map.setCenter(lonLat, 19);


    //создаем дорогу

    var lineLayer = new OpenLayers.Layer.Vector("Линии"); 
    map.addLayer(lineLayer);                    
    map.addControl(new OpenLayers.Control.DrawFeature(lineLayer, OpenLayers.Handler.Path));

    var points = new Array(
       new OpenLayers.Geometry.Point(37.61556, 55.75222),
       new OpenLayers.Geometry.Point(45, 33),
       new OpenLayers.Geometry.Point(49, 35),
       new OpenLayers.Geometry.Point(45, 56),
       new OpenLayers.Geometry.Point(49, 87)
    );

    var line = new OpenLayers.Geometry.LineString(points);
    line.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));

    var style = { 
        strokeColor: '#0000ff', 
        strokeOpacity: 0.5,
        strokeWidth: 5
    };

    var lineFeature = new OpenLayers.Feature.Vector(line, null, style);
    lineLayer.addFeatures([lineFeature]);


    var popup = new OpenLayers.Popup.FramedCloud(
             "popup",
             OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
             null,
             '<div style="color:#FF0000">'+feature.data.Name + '</br><a href="http://test.url">test.url</a>' + '</div>',
             null,
             true
         );

    //добавление на карту 
    map.addPopup(popup, true);



    //создаем маркер
    markers = new OpenLayers.Layer.Markers("Marcadores");
    map.addLayer(markers);

    if (b == 2) 
    {           

            //=================  =========стили для маркеров и тут хранятся координаты
            var size = new OpenLayers.Size(30, 30);
            var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);

            var location = new OpenLayers.LonLat(kor_1, kor_2).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
            var icon = new OpenLayers.Icon('http://icons.iconarchive.com/icons/icons-land/vista-map-markers/256/Map-Marker-Ball-Pink-icon.png', size, offset);
            markers.addMarker(new OpenLayers.Marker(location, icon.clone()));





    }


}

    function add_metka()
    {
        function dobavit(koor1, koor2)
        {

            init(2,koor1,koor2);
        }


    @foreach (Дорожное_строительство.Models.koordinats_piket picket  in ViewBag.Data)
    {
    <text>
        dobavit(@picket.Dolgota,@picket.Shirota);       
    </text>
    }

    }

    setTimeout('add_metka()', 6000)
</script>

share|improve this question
    
I didn't understand what you need, en espanhol mejor? =) –  Gery May 17 '13 at 7:50
    
from russia)by pressing a marker to make the popup.how to make it? –  user2390000 May 17 '13 at 9:38
add comment

1 Answer 1

I thought it was spanish because you have "Marcadores". Anyway check this, basically you need:

var popup = new OpenLayers.Popup.FramedCloud(
                "popup",
                OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
                null,
                '<div style="color:#FF0000">'+feature.data.Name + '</br><a href="http://test.url">test.url</a>' + '</div>',
                null,
                true
            );
share|improve this answer
    
i add this code.....no work..((((Maybe to this code still it is necessary to add something? –  user2390000 May 17 '13 at 9:56
    
post your whole code, in that way is easier to see what is your problem –  Gery May 17 '13 at 10:02
    
I edited the code. (I added the whole code) –  user2390000 May 17 '13 at 10:19
    
you need to modify the popup according to your code, the example above is just an example, I think your problem is feature.geometry.toShortString(), for more examples check this –  Gery May 17 '13 at 10:27
    
markers.events.register("click", markers, function(e){ popup = new OpenLayers.Popup("chicken", map.getLonLatFromPixel(e.x), new OpenLayers.Size(200,200), "example popup", true); map.addPopup(popup); }); –  user2390000 May 17 '13 at 12:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.